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.7.0-rc1~19 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c082d14bd6b59a5c08a5732693cd31229151fbdd;p=lttng-ust.git 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 1734c1b7..4bc4fc9e 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 */ @@ -45,7 +46,7 @@ extern "C" { #endif #define tracepoint_enabled(provider, name) \ - caa_unlikely(__tracepoint_##provider##___##name.state) + caa_unlikely(CMM_LOAD_SHARED(__tracepoint_##provider##___##name.state)) #define do_tracepoint(provider, name, ...) \ __tracepoint_cb_##provider##___##name(__VA_ARGS__) 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); }