tracepoint: Remove TRACEPOINT_LIB declaration
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 Aug 2011 15:34:46 +0000 (11:34 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 26 Aug 2011 15:34:46 +0000 (11:34 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/ust/tracepoint-internal.h
include/ust/tracepoint.h
libust/tracepoint.c
libustjava/UST.c
tests/fork/fork.c
tests/fork/fork2.c
tests/hello/hello.c

index 6ed789032f85a925633d83447d76dfbae2d2ea3f..93d89257fb559d2b0058283841e9fbdfb71c4a11 100644 (file)
 #include <urcu/list.h>
 #include <ust/tracepoint.h>
 
+struct tracepoint_lib {
+       struct tracepoint * const *tracepoints_start;
+       int tracepoints_count;
+       struct cds_list_head list;
+};
+
 extern int tracepoint_probe_register_noupdate(const char *name, void *probe,
                                              void *data);
 extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe,
index 158d9b8a4cc1d3d28fdf4546f058dc8f83868152..76645dd6a1d1fce7181022f88151aa033f508a46 100644 (file)
@@ -46,26 +46,35 @@ struct tracepoint {
 #define tracepoint(name, args...)      __trace_##name(args)
 
 /*
- * Library should be made known to libust by declaring TRACEPOINT_LIB in
- * the source file. (Usually at the end of the file, in the outermost
- * scope).
+ * These weak symbols, the constructor, and destructor take care of
+ * registering only _one_ instance of the tracepoints per shared-ojbect
+ * (or for the whole main program).
+ * The dummy tracepoint entry ensures that the start/stop pointers get
+ * initialized by the linker when no tracepoints are present in a
+ * shared-object (or main program).
  */
-#define TRACEPOINT_LIB                                                 \
-       extern struct tracepoint * const __start___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
-       extern struct tracepoint * const __stop___tracepoints_ptrs[] __attribute__((weak, visibility("hidden"))); \
-       static struct tracepoint * __tracepoint_ptr_dummy               \
-       __attribute__((used, section("__tracepoints_ptrs")));           \
-       static void __attribute__((constructor)) __tracepoints__init(void) \
-       {                                                               \
-               tracepoint_register_lib(__start___tracepoints_ptrs,     \
-                                       __stop___tracepoints_ptrs -     \
-                                       __start___tracepoints_ptrs);    \
-       }                                                               \
-                                                                       \
-       static void __attribute__((destructor)) __tracepoints__destroy(void) \
-       {                                                               \
-               tracepoint_unregister_lib(__start___tracepoints_ptrs);  \
-       }
+extern struct tracepoint * const __start___tracepoints_ptrs[]
+       __attribute__((weak, visibility("hidden")));
+extern struct tracepoint * const __stop___tracepoints_ptrs[]
+       __attribute__((weak, visibility("hidden")));
+int __tracepoint_registered
+       __attribute__((weak, visibility("hidden")));
+
+static void __attribute__((constructor)) __tracepoints__init(void)
+{
+       if (__tracepoint_registered++)
+               return;
+       tracepoint_register_lib(__start___tracepoints_ptrs,
+                               __stop___tracepoints_ptrs -
+                               __start___tracepoints_ptrs);
+}
+
+static void __attribute__((destructor)) __tracepoints__destroy(void)
+{
+       if (--__tracepoint_registered)
+               return;
+       tracepoint_unregister_lib(__start___tracepoints_ptrs);
+}
 
 /*
  * it_func[0] is never NULL because there is at least one element in the array
@@ -182,12 +191,6 @@ int __tracepoint_probe_register(const char *name, void *probe, void *data);
 extern
 int __tracepoint_probe_unregister(const char *name, void *probe, void *data);
 
-struct tracepoint_lib {
-       struct tracepoint * const *tracepoints_start;
-       int tracepoints_count;
-       struct cds_list_head list;
-};
-
 extern
 int tracepoint_register_lib(struct tracepoint * const *tracepoints_start,
                            int tracepoints_count);
index 2b45a88cd85c81f49c9e837e4676c22e0c65815d..a006f700cc18af292d3061e622b6fb1a9ba46f3b 100644 (file)
 
 #include <ust/usterr-signal-safe.h>
 
-extern struct tracepoint * const __start___tracepoints_ptrs[]
-       __attribute__((visibility("hidden")));
-extern struct tracepoint * const __stop___tracepoints_ptrs[]
-       __attribute__((visibility("hidden")));
-
-static struct tracepoint * __tracepoint_ptr_dummy
-       __attribute__((used, section("__tracepoints_ptrs")));
-
 /* Set to 1 to enable tracepoint debug output */
 static const int tracepoint_debug;
 static int initialized;
@@ -667,8 +659,8 @@ lib_added:
        /* TODO: update just the loaded lib */
        lib_update_tracepoints();
 
-       /* tracepoints_count - 1: skip dummy */
-       DBG("just registered a tracepoints section from %p and having %d tracepoints (minus dummy tracepoints)", tracepoints_start, tracepoints_count);
+       DBG("just registered a tracepoints section from %p and having %d tracepoints",
+               tracepoints_start, tracepoints_count);
 
        return 0;
 }
@@ -696,12 +688,8 @@ void init_tracepoint(void)
        if (uatomic_xchg(&initialized, 1) == 1)
                return;
        init_usterr();
-       tracepoint_register_lib(__start___tracepoints_ptrs,
-               __stop___tracepoints_ptrs
-               - __start___tracepoints_ptrs);
 }
 
 void exit_tracepoint(void)
 {
-       tracepoint_unregister_lib(__start___tracepoints_ptrs);
 }
index 84b7393abb7c36727091049f4cc99b9b478118c2..7ad1c717317079306ed57c0b02d6ddd3bc5ba154 100644 (file)
@@ -13,5 +13,3 @@ JNIEXPORT void JNICALL Java_UST_ust_1java_1event (JNIEnv *env, jobject jobj,
 
        tracepoint(ust_java_event, ev_name_cstr, args_cstr);
 }
-
-TRACEPOINT_LIB
index be96d817d8df9fa8172f8090187069b37b8f6ca8..17162574195a9f89853ea35f7138cc61b5df0536 100644 (file)
@@ -24,7 +24,6 @@
 
 #define TRACEPOINT_CREATE_PROBES
 #include "ust_tests_fork.h"
-TRACEPOINT_LIB
 
 int main(int argc, char **argv, char *env[])
 {
index 42e2facafb37c70b8ae161c78597d25fe843fd5b..187b7a1cecd50f66c56d7f450dc6c8ae2a377834 100644 (file)
@@ -20,7 +20,6 @@
 
 #define TRACEPOINT_CREATE_PROBES
 #include "ust_tests_fork.h"
-TRACEPOINT_LIB
 
 int main()
 {
index b265b348f2d0fa8615b194893b15065ecfdc6165..72a30d0996c9c51751492875e3061fd213921baa 100644 (file)
@@ -28,7 +28,6 @@
 #include <string.h>
 
 #include "ust_tests_hello.h"
-TRACEPOINT_LIB
 
 void inthandler(int sig)
 {
This page took 0.028446 seconds and 4 git commands to generate.