Use urcu tls-compat.h
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 21 Feb 2013 15:55:52 +0000 (10:55 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 21 Feb 2013 15:55:52 +0000 (10:55 -0500)
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 <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-context-procname.c
liblttng-ust/lttng-context-vtid.c
liblttng-ust/lttng-ust-comm.c
libringbuffer/frontend_api.h
libringbuffer/frontend_internal.h
libringbuffer/ring_buffer_frontend.c

index 0d42be9191958fc0042a74840cc97931cf1fb9f5..0e7bf1ce6080ed264be4335dfc8f9de6334273a0 100644 (file)
@@ -23,6 +23,7 @@
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
 #include <lttng/ringbuffer-config.h>
+#include <urcu/tls-compat.h>
 #include <assert.h>
 #include "compat.h"
 
  * 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]));
 }
index dd443774d4c9ef35386cda1d1c4f3e067682a381..4b1da4f8e9b78541473f3e838352e04ac4461679 100644 (file)
 #include <lttng/ust-tracer.h>
 #include <lttng/ringbuffer-config.h>
 #include <lttng/ust-tid.h>
+#include <urcu/tls-compat.h>
 #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)));
 }
index bfc9bc5a87f8fc6e02bd5cb3d999f575af1c98dc..a1ebcbe6fc83564a5fc4d9c0c0642403938da35f 100644 (file)
@@ -43,6 +43,7 @@
 #include <lttng/ust.h>
 #include <lttng/ust-error.h>
 #include <lttng/ust-ctl.h>
+#include <urcu/tls-compat.h>
 #include <ust-comm.h>
 #include <usterr-signal-safe.h>
 #include <helper.h>
@@ -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 */
index 6a06bba2c2393ba139bc506a8f88bb4027b59ea9..a2a9af39aea777998c5d96cdde5f632f500c8cf7 100644 (file)
@@ -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();
 }
 
index de705d5b1226d4caaddaeed57b4a2f6f2103e064..a96746dcc53533910e76baaa15ab28e0133fd566 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <urcu/compiler.h>
+#include <urcu/tls-compat.h>
 #include <signal.h>
 #include <pthread.h>
 
@@ -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 */
index 6f94040e9b186ca9a2788c3875d9d453bddde8c6..7762da7291ae5d1f215ee0c47039bd8c84f78d28 100644 (file)
@@ -58,6 +58,7 @@
 #include <fcntl.h>
 #include <urcu/compiler.h>
 #include <urcu/ref.h>
+#include <urcu/tls-compat.h>
 #include <helper.h>
 
 #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)));
 }
This page took 0.031988 seconds and 4 git commands to generate.