lttng_ust_init_thread: initialise cached context values
authorNorbert Lange <nolange79@gmail.com>
Mon, 1 Aug 2022 14:36:59 +0000 (16:36 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 1 Aug 2022 15:10:42 +0000 (11:10 -0400)
Modify all relevant *_alloc_tls functions so that they take
flags for 'init'. Rename them to init_thread for consistency.

So far define one flag LTTNG_UST_INIT_THREAD_CONTEXT_CACHE,
this will warm up cached values so less is done during
the first tracepoint.

The function 'lttng_ust_init_thread' will use all available
flags, software can opt-in to do work early instead
of lazily during tracepoints.

Signed-off-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 files changed:
src/lib/lttng-ust/lttng-context-cgroup-ns.c
src/lib/lttng-ust/lttng-context-ipc-ns.c
src/lib/lttng-ust/lttng-context-net-ns.c
src/lib/lttng-ust/lttng-context-perf-counters.c
src/lib/lttng-ust/lttng-context-procname.c
src/lib/lttng-ust/lttng-context-provider.c
src/lib/lttng-ust/lttng-context-time-ns.c
src/lib/lttng-ust/lttng-context-uts-ns.c
src/lib/lttng-ust/lttng-context-vtid.c
src/lib/lttng-ust/lttng-probes.c
src/lib/lttng-ust/lttng-tracer-core.h
src/lib/lttng-ust/lttng-ust-comm.c
src/lib/lttng-ust/lttng-ust-statedump.c

index 34523ea1ad96b33f2bacdb48860597309283392c..5accd2df47e44367d95935895bf3374e43525bc2 100644 (file)
@@ -155,7 +155,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_cgroup_ns_alloc_tls(void)
+void lttng_ust_cgroup_ns_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_cgroup_ns)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)get_cgroup_ns();
 }
index 63401e8d5889a6ce7f8fabb6b45c17684b1340d5..078e646106b576bc8deee1778b0e291c6389f6e4 100644 (file)
@@ -153,7 +153,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_ipc_ns_alloc_tls(void)
+void lttng_ust_ipc_ns_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_ipc_ns)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)get_ipc_ns();
 }
index 960591c2586e41c0543d2aa975d6c9da5e7a13ff..66fcb045ee776bd2a21b03a12e0bea456f51048a 100644 (file)
@@ -153,7 +153,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_net_ns_alloc_tls(void)
+void lttng_ust_net_ns_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_net_ns)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)get_net_ns();
 }
index 2db11436a9ad8fa320f7092d9420e21972dc2ad6..52371a0dc6eb13cb600055cf85eba36077748cf5 100644 (file)
@@ -87,9 +87,10 @@ static DEFINE_URCU_TLS(int, ust_perf_mutex_nest);
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_ust_perf_counter_alloc_tls(void)
+void lttng_ust_perf_counter_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(ust_perf_mutex_nest)));
+       (void)flags;
 }
 
 void lttng_perf_lock(void)
index b5bf77be611b28ee3d6d87ac5415da0470acafc6..16f34c4652e865bc14324f80e2cb1e119f776c1b 100644 (file)
@@ -122,7 +122,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_procname_alloc_tls(void)
+void lttng_ust_procname_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_procname)[0]));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)wrapper_getprocname();
 }
index 4e7e429fcc6ee662c744cd94a818eca68d01eb5f..5000657de636e79b20e84bb8526843616250e8bc 100644 (file)
@@ -67,7 +67,7 @@ struct lttng_ust_registered_context_provider *lttng_ust_context_provider_registe
        size_t name_len = strlen(provider->name);
        uint32_t hash;
 
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        /* Provider name starts with "$app.". */
        if (strncmp("$app.", provider->name, strlen("$app.")) != 0)
@@ -101,7 +101,7 @@ end:
 
 void lttng_ust_context_provider_unregister(struct lttng_ust_registered_context_provider *reg_provider)
 {
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        if (ust_lock())
                goto end;
index ec32a1deea2881793af572f95753f49fa02fd201..e84b7048fae9cb37d0fc5b67eeaa7cfff081ea8f 100644 (file)
@@ -152,7 +152,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_time_ns_alloc_tls(void)
+void lttng_ust_time_ns_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_time_ns)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)get_time_ns();
 }
index 06a978fd4184d561c9ff437a760bbd3ea7203bda..51d6092e53158fb197269b25f8f79cf827df53cc 100644 (file)
@@ -154,7 +154,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_uts_ns_alloc_tls(void)
+void lttng_ust_uts_ns_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_uts_ns)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)get_uts_ns();
 }
index 880e34b90a1dae8aa9b95eec305ceaa08d0b5176..e9bbbf85bd8eb1c3d98612aa63018d9c7214c369 100644 (file)
@@ -112,7 +112,9 @@ error_find_context:
 /*
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
-void lttng_vtid_alloc_tls(void)
+void lttng_ust_vtid_init_thread(int flags)
 {
        asm volatile ("" : : "m" (URCU_TLS(cached_vtid)));
+       if (flags & LTTNG_UST_INIT_THREAD_CONTEXT_CACHE)
+               (void)wrapper_getvtid();
 }
index e8e08ff176ce6d5e2b4bccf556bf2053fcb51762..2d47bf19c050e475ca0a506e5dff1d5e17adf5bf 100644 (file)
@@ -231,7 +231,7 @@ struct lttng_ust_registered_probe *lttng_ust_probe_register(const struct lttng_u
 {
        struct lttng_ust_registered_probe *reg_probe = NULL;
 
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        /*
         * If version mismatch, don't register, but don't trigger assert
@@ -269,7 +269,7 @@ end:
 
 void lttng_ust_probe_unregister(struct lttng_ust_registered_probe *reg_probe)
 {
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        if (!reg_probe)
                return;
index eadc43edb38df401e460a7dfad8051e20d28e264..61cd740cfd3578d56f51df789c33cf81ae199c98 100644 (file)
 #include <lttng/ust-ringbuffer-context.h>
 #include "common/logging.h"
 
+enum lttng_ust_init_thread_flags {
+       LTTNG_UST_INIT_THREAD_CONTEXT_CACHE = (1 << 0),
+       LTTNG_UST_INIT_THREAD_MASK = (LTTNG_UST_INIT_THREAD_CONTEXT_CACHE << 1) - 1,
+};
+
 struct lttng_ust_session;
 struct lttng_ust_channel_buffer;
 struct lttng_ust_ctx_field;
@@ -34,28 +39,28 @@ void ust_lock_nocheck(void)
 void ust_unlock(void)
        __attribute__((visibility("hidden")));
 
-void lttng_ust_alloc_tls(void)
+void lttng_ust_common_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_vtid_alloc_tls(void)
+void lttng_ust_vtid_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_procname_alloc_tls(void)
+void lttng_ust_procname_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_cgroup_ns_alloc_tls(void)
+void lttng_ust_cgroup_ns_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_ipc_ns_alloc_tls(void)
+void lttng_ust_ipc_ns_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_net_ns_alloc_tls(void)
+void lttng_ust_net_ns_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_time_ns_alloc_tls(void)
+void lttng_ust_time_ns_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
-void lttng_uts_ns_alloc_tls(void)
+void lttng_ust_uts_ns_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
 const char *lttng_ust_obj_get_name(int id)
@@ -78,7 +83,7 @@ void lttng_event_notifier_notification_send(
        __attribute__((visibility("hidden")));
 
 #ifdef HAVE_LINUX_PERF_EVENT_H
-void lttng_ust_perf_counter_alloc_tls(void)
+void lttng_ust_perf_counter_init_thread(int flags)
        __attribute__((visibility("hidden")));
 
 void lttng_perf_lock(void)
@@ -88,7 +93,7 @@ void lttng_perf_unlock(void)
        __attribute__((visibility("hidden")));
 #else /* #ifdef HAVE_LINUX_PERF_EVENT_H */
 static inline
-void lttng_ust_perf_counter_alloc_tls(void)
+void lttng_ust_perf_counter_init_thread(int flags __attribute__((unused)))
 {
 }
 static inline
index 7f34efe7a2f95ec9e934c0005d163bd71cd0ffcd..0a039feffdb7f8d64085da19118b0fea3a886e42 100644 (file)
@@ -387,7 +387,7 @@ const char *get_lttng_home_dir(void)
  * Force a read (imply TLS allocation for dlopen) of TLS variables.
  */
 static
-void lttng_nest_count_alloc_tls(void)
+void lttng_ust_nest_count_alloc_tls(void)
 {
        asm volatile ("" : : "m" (URCU_TLS(lttng_ust_nest_count)));
 }
@@ -402,26 +402,26 @@ void lttng_ust_mutex_nest_alloc_tls(void)
  * Allocate lttng-ust urcu TLS.
  */
 static
-void lttng_lttng_ust_urcu_alloc_tls(void)
+void lttng_ust_urcu_alloc_tls(void)
 {
        (void) lttng_ust_urcu_read_ongoing();
 }
 
-void lttng_ust_alloc_tls(void)
+void lttng_ust_common_init_thread(int flags)
 {
-       lttng_lttng_ust_urcu_alloc_tls();
+       lttng_ust_urcu_alloc_tls();
        lttng_ringbuffer_alloc_tls();
-       lttng_vtid_alloc_tls();
-       lttng_nest_count_alloc_tls();
-       lttng_procname_alloc_tls();
+       lttng_ust_vtid_init_thread(flags);
+       lttng_ust_nest_count_alloc_tls();
+       lttng_ust_procname_init_thread(flags);
        lttng_ust_mutex_nest_alloc_tls();
-       lttng_ust_perf_counter_alloc_tls();
+       lttng_ust_perf_counter_init_thread(flags);
        lttng_ust_common_alloc_tls();
-       lttng_cgroup_ns_alloc_tls();
-       lttng_ipc_ns_alloc_tls();
-       lttng_net_ns_alloc_tls();
-       lttng_time_ns_alloc_tls();
-       lttng_uts_ns_alloc_tls();
+       lttng_ust_cgroup_ns_init_thread(flags);
+       lttng_ust_ipc_ns_init_thread(flags);
+       lttng_ust_net_ns_init_thread(flags);
+       lttng_ust_time_ns_init_thread(flags);
+       lttng_ust_uts_ns_init_thread(flags);
        lttng_ust_ring_buffer_client_discard_alloc_tls();
        lttng_ust_ring_buffer_client_discard_rt_alloc_tls();
        lttng_ust_ring_buffer_client_overwrite_alloc_tls();
@@ -446,7 +446,7 @@ void lttng_ust_init_thread(void)
         * ensure those are initialized before a signal handler nesting over
         * this thread attempts to use them.
         */
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(LTTNG_UST_INIT_THREAD_MASK);
 }
 
 int lttng_get_notify_socket(void *owner)
@@ -1815,7 +1815,7 @@ void *ust_listener_thread(void *arg)
        int sock, ret, prev_connect_failed = 0, has_waited = 0, fd;
        long timeout;
 
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
        /*
         * If available, add '-ust' to the end of this thread's
         * process name
@@ -2183,7 +2183,7 @@ void lttng_ust_ctor(void)
         * to be the dynamic linker mutex) and ust_lock, taken within
         * the ust lock.
         */
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        lttng_ust_loaded = 1;
 
@@ -2497,7 +2497,7 @@ void lttng_ust_before_fork(sigset_t *save_sigset)
        int ret;
 
        /* Allocate lttng-ust TLS. */
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        if (URCU_TLS(lttng_ust_nest_count))
                return;
index 309a98fa2201243913dbf09fcc16c8e2ae134338..bd95c0432e4ca4616dac6bab1f735222305d9a17 100644 (file)
@@ -557,7 +557,7 @@ void lttng_ust_dl_update(void *ip)
         * Force the allocation of lttng-ust TLS variables when called from
         * dlopen/dlclose instrumentation.
         */
-       lttng_ust_alloc_tls();
+       lttng_ust_common_init_thread(0);
 
        data.exec_found = 0;
        data.first = true;
This page took 0.032408 seconds and 4 git commands to generate.