Fix: perform volatile load of tracepoint state
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 22 Jun 2015 14:30:02 +0000 (10:30 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 22 Jun 2015 14:37:50 +0000 (10:37 -0400)
Because tracepoint state is updated by lttng-ust threads, and read by
application threads, we need to perform a volatile load of that state.

Not having the volatile load can cause the compiler to optimize away the
reload of that state, keeping a local copy instead. For instance, a main
program consisting of a loop could keep the tracepoint state on its
stack or in registers without ever reloading it from memory.

Perform a volatile load (CMM_LOAD_SHARED()) of the tracepoint state.
Add the matching volatile store (CMM_STORE_SHARED()) in tracepoint.c for
the state update.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/tracepoint.h
liblttng-ust/tracepoint.c

index 63759a20ee3da5f7a7e0beb6f08219c8567abe55..39539911d3b6a12e5a55849013e324958ec4b797 100644 (file)
@@ -28,6 +28,7 @@
 #include <lttng/tracepoint-types.h>
 #include <lttng/tracepoint-rcu.h>
 #include <urcu/compiler.h>
+#include <urcu/system.h>
 #include <dlfcn.h>     /* for dlopen */
 #include <string.h>    /* for memset */
 #include <lttng/ust-config.h>  /* for sdt */
@@ -47,7 +48,7 @@ extern "C" {
 #define tracepoint(provider, name, ...)                                            \
        do {                                                                \
                STAP_PROBEV(provider, name, ## __VA_ARGS__);                \
-               if (caa_unlikely(__tracepoint_##provider##___##name.state)) \
+               if (caa_unlikely(CMM_LOAD_SHARED(__tracepoint_##provider##___##name.state))) \
                        __tracepoint_cb_##provider##___##name(__VA_ARGS__); \
        } while (0)
 
index a4a79ba59b3f8298b30a2889bf6e7e30ef04aad2..5fd1126aa42d3b03c5709994aaad61c4ddaa11ae 100644 (file)
@@ -30,6 +30,7 @@
 #include <urcu/hlist.h>
 #include <urcu/uatomic.h>
 #include <urcu/compiler.h>
+#include <urcu/system.h>
 
 #include <lttng/tracepoint.h>
 #include <lttng/ust-abi.h>     /* for LTTNG_UST_SYM_NAME_LEN */
@@ -347,7 +348,7 @@ static void set_tracepoint(struct tracepoint_entry **entry,
         * is used.
         */
        rcu_assign_pointer(elem->probes, (*entry)->probes);
-       elem->state = active;
+       CMM_STORE_SHARED(elem->state, active);
 }
 
 /*
@@ -358,7 +359,7 @@ static void set_tracepoint(struct tracepoint_entry **entry,
  */
 static void disable_tracepoint(struct lttng_ust_tracepoint *elem)
 {
-       elem->state = 0;
+       CMM_STORE_SHARED(elem->state, 0);
        rcu_assign_pointer(elem->probes, NULL);
 }
 
This page took 0.025689 seconds and 4 git commands to generate.