[sheepdog] [PATCH v4 2/5] logger: use LWP for worker idx
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Mar 4 01:08:03 CET 2013
We cannot use a sequence number for the thread index any more. This
patch uses LWP for it instead.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
include/logger.h | 2 +-
include/util.h | 1 +
lib/logger.c | 5 +++--
lib/util.c | 6 ++++++
sheep/work.c | 2 +-
5 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/include/logger.h b/include/logger.h
index 6721a58..88af7d5 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -35,7 +35,7 @@ void log_close(void);
void dump_logmsg(void *);
void log_write(int prio, const char *func, int line, const char *fmt, ...)
__printf(4, 5);
-void set_thread_name(const char *name, int idx);
+void set_thread_name(const char *name, bool show_idx);
void get_thread_name(char *name);
#define sd_dump_variable(var) ({ \
diff --git a/include/util.h b/include/util.h
index 0530a2c..23d5678 100644
--- a/include/util.h
+++ b/include/util.h
@@ -87,6 +87,7 @@ int rmdir_r(char *dir_path);
bool is_numeric(const char *p);
int install_sighandler(int signum, void (*handler)(int), bool once);
int install_crash_handler(void (*handler)(int));
+pid_t gettid(void);
void trim_zero_sectors(void *buf, uint64_t *offset, uint32_t *len);
void untrim_zero_sectors(void *buf, uint64_t offset, uint32_t len,
diff --git a/lib/logger.c b/lib/logger.c
index 659ae2d..e48471d 100644
--- a/lib/logger.c
+++ b/lib/logger.c
@@ -609,10 +609,11 @@ notrace void log_close(void)
}
}
-notrace void set_thread_name(const char *name, int idx)
+notrace void set_thread_name(const char *name, bool show_idx)
{
worker_name = name;
- worker_idx = idx;
+ if (show_idx)
+ worker_idx = gettid();
}
notrace void get_thread_name(char *name)
diff --git a/lib/util.c b/lib/util.c
index 3ac89c0..6908bb0 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
+#include <sys/syscall.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
@@ -375,3 +376,8 @@ int install_crash_handler(void (*handler)(int))
install_sighandler(SIGILL, handler, true) ||
install_sighandler(SIGFPE, handler, true);
}
+
+pid_t gettid(void)
+{
+ return syscall(SYS_gettid);
+}
diff --git a/sheep/work.c b/sheep/work.c
index 81e7e54..bc5c7c9 100644
--- a/sheep/work.c
+++ b/sheep/work.c
@@ -84,7 +84,7 @@ static void *worker_routine(void *arg)
struct work *work;
eventfd_t value = 1;
- set_thread_name(wi->name, 0);
+ set_thread_name(wi->name, false);
pthread_mutex_lock(&wi->startup_lock);
/* started this thread */
--
1.8.1.3.566.gaa39828
More information about the sheepdog
mailing list