From: Mathieu Desnoyers Date: Mon, 22 Jun 2015 14:30:02 +0000 (-0400) Subject: Fix: perform volatile load of tracepoint state X-Git-Tag: v2.6.3~15 X-Git-Url: http://git.liburcu.org/?p=lttng-ust.git;a=commitdiff_plain;h=05523fbf3fa3af6247a048c32d219b07bd65fd1a Fix: perform volatile load of tracepoint state 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 --- diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index 63759a20..39539911 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -28,6 +28,7 @@ #include #include #include +#include #include /* for dlopen */ #include /* for memset */ #include /* 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) diff --git a/liblttng-ust/tracepoint.c b/liblttng-ust/tracepoint.c index a4a79ba5..5fd1126a 100644 --- a/liblttng-ust/tracepoint.c +++ b/liblttng-ust/tracepoint.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include /* 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); }