Fix: procname context semantic
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Oct 2012 13:04:14 +0000 (09:04 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 24 Oct 2012 13:04:14 +0000 (09:04 -0400)
Cache the procname per-thread rather than per-process to take into
account that prctl() can be used to set thread names.

prctl() should be issued before tracing each thread's first event if we
care about the thread name.

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

index 2ea4eadfdd72a942182b350bffeda7b0bfe9fe76..34c5557adeef7786244437ee5d4abfa5332ce5ad 100644 (file)
@@ -39,5 +39,6 @@ void ust_unlock(void);
 
 void lttng_fixup_event_tls(void);
 void lttng_fixup_vtid_tls(void);
+void lttng_fixup_procname_tls(void);
 
 #endif /* _LTT_TRACER_CORE_H */
index d165be88277daada8bbb616c2db60572050f9aa2..96cd1ee2c8f4979f7c7fbaf7c9367c2d9b59061b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * LTTng UST procname context.
  *
- * Copyright (C) 2009-2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * each event.
  * Upon exec, procname changes, but exec takes care of throwing away
  * this cached version.
+ * The procname can also change by calling prctl(). The procname should
+ * be set for a thread before the first event is logged within this
+ * thread.
  */
-static char cached_procname[17];
+static __thread char cached_procname[17];
 
 static inline
 char *wrapper_getprocname(void)
@@ -94,3 +97,11 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
        field->record = procname_record;
        return 0;
 }
+
+/*
+ * Force a read (imply TLS fixup for dlopen) of TLS variables.
+ */
+void lttng_fixup_procname_tls(void)
+{
+       asm volatile ("" : : "m" (cached_procname[0]));
+}
index efc6724f1b6510538e3a2d7063c1dc8093e02c6c..31955bb56d82b94a94a0d99886244353036a8f0a 100644 (file)
@@ -952,6 +952,7 @@ void __attribute__((constructor)) lttng_ust_init(void)
        lttng_fixup_ringbuffer_tls();
        lttng_fixup_vtid_tls();
        lttng_fixup_nest_count_tls();
+       lttng_fixup_procname_tls();
 
        /*
         * We want precise control over the order in which we construct
This page took 0.026945 seconds and 4 git commands to generate.