Fix: additional compiler barriers for procname context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 14 Feb 2019 21:39:57 +0000 (16:39 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 14 Feb 2019 21:39:57 +0000 (16:39 -0500)
Use additional volatile load/stores and compiler barriers to make
sure the compiler do not reorder the nesting counter wrt procname cache
content load/stores.

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

index 95d5f28dbe20b9a2e21decd18e7b2db04ccb0efa..8c1520ad51f221b467dd38815cd66868a75b137d 100644 (file)
@@ -49,24 +49,29 @@ static DEFINE_URCU_TLS(int, procname_nesting);
 static inline
 char *wrapper_getprocname(void)
 {
-       int nesting = URCU_TLS(procname_nesting);
+       int nesting = CMM_LOAD_SHARED(URCU_TLS(procname_nesting));
 
        if (caa_unlikely(nesting >= PROCNAME_NESTING_MAX))
                return "<unknown>";
        if (caa_unlikely(!URCU_TLS(cached_procname)[nesting][0])) {
                CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting + 1);
+               /* Increment nesting before updating cache. */
+               cmm_barrier();
                lttng_ust_getprocname(URCU_TLS(cached_procname)[nesting]);
                URCU_TLS(cached_procname)[nesting][LTTNG_UST_PROCNAME_LEN - 1] = '\0';
+               /* Decrement nesting after updating cache. */
+               cmm_barrier();
                CMM_STORE_SHARED(URCU_TLS(procname_nesting), nesting);
        }
        return URCU_TLS(cached_procname)[nesting];
 }
 
+/* Reset should not be called from a signal handler. */
 void lttng_context_procname_reset(void)
 {
-       URCU_TLS(cached_procname)[1][0] = '\0';
+       CMM_STORE_SHARED(URCU_TLS(cached_procname)[1][0], '\0');
        CMM_STORE_SHARED(URCU_TLS(procname_nesting), 1);
-       URCU_TLS(cached_procname)[0][0] = '\0';
+       CMM_STORE_SHARED(URCU_TLS(cached_procname)[0][0], '\0');
        CMM_STORE_SHARED(URCU_TLS(procname_nesting), 0);
 }
 
This page took 0.025459 seconds and 4 git commands to generate.