From: Mathieu Desnoyers Date: Thu, 21 Feb 2013 15:55:52 +0000 (-0500) Subject: Use urcu tls-compat.h X-Git-Tag: v2.2.0-rc1~78 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8c90a710949a214d87084ff67fc85f284bc93ef2;p=lttng-ust.git Use urcu tls-compat.h We can use the URCU_TLS() compatibility layer from userspace RCU to support some BSD flavors that do not support __thread. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index 0d42be91..0e7bf1ce 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "compat.h" @@ -35,21 +36,22 @@ * be set for a thread before the first event is logged within this * thread. */ -static __thread char cached_procname[17]; +typedef char procname_array[17]; +static DEFINE_URCU_TLS(procname_array, cached_procname); static inline char *wrapper_getprocname(void) { - if (caa_unlikely(!cached_procname[0])) { - lttng_ust_getprocname(cached_procname); - cached_procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + if (caa_unlikely(!URCU_TLS(cached_procname)[0])) { + lttng_ust_getprocname(URCU_TLS(cached_procname)); + URCU_TLS(cached_procname)[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; } - return cached_procname; + return URCU_TLS(cached_procname); } void lttng_context_procname_reset(void) { - cached_procname[0] = '\0'; + URCU_TLS(cached_procname)[0] = '\0'; } static @@ -103,5 +105,5 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) */ void lttng_fixup_procname_tls(void) { - asm volatile ("" : : "m" (cached_procname[0])); + asm volatile ("" : : "m" (URCU_TLS(cached_procname)[0])); } diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index dd443774..4b1da4f8 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -26,13 +26,14 @@ #include #include #include +#include #include "lttng-tracer-core.h" /* * We cache the result to ensure we don't trigger a system call for * each event. */ -static __thread pid_t cached_vtid; +static DEFINE_URCU_TLS(pid_t, cached_vtid); /* * Upon fork or clone, the TID assigned to our thread is not the same as @@ -41,7 +42,7 @@ static __thread pid_t cached_vtid; */ void lttng_context_vtid_reset(void) { - cached_vtid = 0; + URCU_TLS(cached_vtid) = 0; } static @@ -59,10 +60,11 @@ void vtid_record(struct lttng_ctx_field *field, struct lttng_ust_lib_ring_buffer_ctx *ctx, struct lttng_channel *chan) { - if (caa_unlikely(!cached_vtid)) - cached_vtid = gettid(); - lib_ring_buffer_align_ctx(ctx, lttng_alignof(cached_vtid)); - chan->ops->event_write(ctx, &cached_vtid, sizeof(cached_vtid)); + if (caa_unlikely(!URCU_TLS(cached_vtid))) + URCU_TLS(cached_vtid) = gettid(); + lib_ring_buffer_align_ctx(ctx, lttng_alignof(URCU_TLS(cached_vtid))); + chan->ops->event_write(ctx, &URCU_TLS(cached_vtid), + sizeof(URCU_TLS(cached_vtid))); } int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) @@ -94,5 +96,5 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx) */ void lttng_fixup_vtid_tls(void) { - asm volatile ("" : : "m" (cached_vtid)); + asm volatile ("" : : "m" (URCU_TLS(cached_vtid))); } diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index bfc9bc5a..a1ebcbe6 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -85,7 +86,7 @@ static int sem_count = { 2 }; * Counting nesting within lttng-ust. Used to ensure that calling fork() * from liblttng-ust does not execute the pre/post fork handlers. */ -static int __thread lttng_ust_nest_count; +static DEFINE_URCU_TLS(int, lttng_ust_nest_count); /* * Info about socket and associated listener thread. @@ -183,7 +184,7 @@ extern void lttng_ring_buffer_metadata_client_exit(void); static void lttng_fixup_nest_count_tls(void) { - asm volatile ("" : : "m" (lttng_ust_nest_count)); + asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count))); } static @@ -621,9 +622,9 @@ int get_wait_shm(struct sock_info *sock_info, size_t mmap_size) * If the open failed because the file did not exist, try * creating it ourself. */ - lttng_ust_nest_count++; + URCU_TLS(lttng_ust_nest_count)++; pid = fork(); - lttng_ust_nest_count--; + URCU_TLS(lttng_ust_nest_count)--; if (pid > 0) { int status; @@ -1213,7 +1214,7 @@ void ust_before_fork(sigset_t *save_sigset) sigset_t all_sigs; int ret; - if (lttng_ust_nest_count) + if (URCU_TLS(lttng_ust_nest_count)) return; /* Disable signals */ sigfillset(&all_sigs); @@ -1240,7 +1241,7 @@ static void ust_after_fork_common(sigset_t *restore_sigset) void ust_after_fork_parent(sigset_t *restore_sigset) { - if (lttng_ust_nest_count) + if (URCU_TLS(lttng_ust_nest_count)) return; DBG("process %d", getpid()); rcu_bp_after_fork_parent(); @@ -1259,7 +1260,7 @@ void ust_after_fork_parent(sigset_t *restore_sigset) */ void ust_after_fork_child(sigset_t *restore_sigset) { - if (lttng_ust_nest_count) + if (URCU_TLS(lttng_ust_nest_count)) return; DBG("process %d", getpid()); /* Release urcu mutexes */ diff --git a/libringbuffer/frontend_api.h b/libringbuffer/frontend_api.h index 6a06bba2..a2a9af39 100644 --- a/libringbuffer/frontend_api.h +++ b/libringbuffer/frontend_api.h @@ -55,12 +55,12 @@ int lib_ring_buffer_get_cpu(const struct lttng_ust_lib_ring_buffer_config *confi rcu_read_lock(); cpu = lttng_ust_get_cpu(); - nesting = ++lib_ring_buffer_nesting; /* TLS */ + nesting = ++URCU_TLS(lib_ring_buffer_nesting); cmm_barrier(); if (caa_unlikely(nesting > 4)) { WARN_ON_ONCE(1); - lib_ring_buffer_nesting--; /* TLS */ + URCU_TLS(lib_ring_buffer_nesting)--; rcu_read_unlock(); return -EPERM; } else @@ -74,7 +74,7 @@ static inline void lib_ring_buffer_put_cpu(const struct lttng_ust_lib_ring_buffer_config *config) { cmm_barrier(); - lib_ring_buffer_nesting--; /* TLS */ + URCU_TLS(lib_ring_buffer_nesting)--; /* TLS */ rcu_read_unlock(); } diff --git a/libringbuffer/frontend_internal.h b/libringbuffer/frontend_internal.h index de705d5b..a96746dc 100644 --- a/libringbuffer/frontend_internal.h +++ b/libringbuffer/frontend_internal.h @@ -32,6 +32,7 @@ */ #include +#include #include #include @@ -520,6 +521,6 @@ extern void lib_ring_buffer_free(struct lttng_ust_lib_ring_buffer *buf, struct lttng_ust_shm_handle *handle); /* Keep track of trap nesting inside ring buffer code */ -extern __thread unsigned int lib_ring_buffer_nesting; +extern DECLARE_URCU_TLS(unsigned int, lib_ring_buffer_nesting); #endif /* _LTTNG_RING_BUFFER_FRONTEND_INTERNAL_H */ diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 6f94040e..7762da72 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include "smp.h" @@ -102,7 +103,7 @@ struct switch_offsets { switch_old_end:1; }; -__thread unsigned int lib_ring_buffer_nesting; +DEFINE_URCU_TLS(unsigned int, lib_ring_buffer_nesting); /* * TODO: this is unused. Errors are saved within the ring buffer. @@ -1558,5 +1559,5 @@ int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx) */ void lttng_fixup_ringbuffer_tls(void) { - asm volatile ("" : : "m" (lib_ring_buffer_nesting)); + asm volatile ("" : : "m" (URCU_TLS(lib_ring_buffer_nesting))); }