From: Norbert Lange Date: Mon, 1 Aug 2022 14:36:59 +0000 (+0200) Subject: lttng_ust_init_thread: initialise cached context values X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c246521ddcba1d1d28cfa0482aa500b9122e7264;p=lttng-ust.git lttng_ust_init_thread: initialise cached context values 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/src/lib/lttng-ust/lttng-context-cgroup-ns.c b/src/lib/lttng-ust/lttng-context-cgroup-ns.c index 34523ea1..5accd2df 100644 --- a/src/lib/lttng-ust/lttng-context-cgroup-ns.c +++ b/src/lib/lttng-ust/lttng-context-cgroup-ns.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-ipc-ns.c b/src/lib/lttng-ust/lttng-context-ipc-ns.c index 63401e8d..078e6461 100644 --- a/src/lib/lttng-ust/lttng-context-ipc-ns.c +++ b/src/lib/lttng-ust/lttng-context-ipc-ns.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-net-ns.c b/src/lib/lttng-ust/lttng-context-net-ns.c index 960591c2..66fcb045 100644 --- a/src/lib/lttng-ust/lttng-context-net-ns.c +++ b/src/lib/lttng-ust/lttng-context-net-ns.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-perf-counters.c b/src/lib/lttng-ust/lttng-context-perf-counters.c index 2db11436..52371a0d 100644 --- a/src/lib/lttng-ust/lttng-context-perf-counters.c +++ b/src/lib/lttng-ust/lttng-context-perf-counters.c @@ -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) diff --git a/src/lib/lttng-ust/lttng-context-procname.c b/src/lib/lttng-ust/lttng-context-procname.c index b5bf77be..16f34c46 100644 --- a/src/lib/lttng-ust/lttng-context-procname.c +++ b/src/lib/lttng-ust/lttng-context-procname.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-provider.c b/src/lib/lttng-ust/lttng-context-provider.c index 4e7e429f..5000657d 100644 --- a/src/lib/lttng-ust/lttng-context-provider.c +++ b/src/lib/lttng-ust/lttng-context-provider.c @@ -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; diff --git a/src/lib/lttng-ust/lttng-context-time-ns.c b/src/lib/lttng-ust/lttng-context-time-ns.c index ec32a1de..e84b7048 100644 --- a/src/lib/lttng-ust/lttng-context-time-ns.c +++ b/src/lib/lttng-ust/lttng-context-time-ns.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-uts-ns.c b/src/lib/lttng-ust/lttng-context-uts-ns.c index 06a978fd..51d6092e 100644 --- a/src/lib/lttng-ust/lttng-context-uts-ns.c +++ b/src/lib/lttng-ust/lttng-context-uts-ns.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-context-vtid.c b/src/lib/lttng-ust/lttng-context-vtid.c index 880e34b9..e9bbbf85 100644 --- a/src/lib/lttng-ust/lttng-context-vtid.c +++ b/src/lib/lttng-ust/lttng-context-vtid.c @@ -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(); } diff --git a/src/lib/lttng-ust/lttng-probes.c b/src/lib/lttng-ust/lttng-probes.c index e8e08ff1..2d47bf19 100644 --- a/src/lib/lttng-ust/lttng-probes.c +++ b/src/lib/lttng-ust/lttng-probes.c @@ -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; diff --git a/src/lib/lttng-ust/lttng-tracer-core.h b/src/lib/lttng-ust/lttng-tracer-core.h index eadc43ed..61cd740c 100644 --- a/src/lib/lttng-ust/lttng-tracer-core.h +++ b/src/lib/lttng-ust/lttng-tracer-core.h @@ -16,6 +16,11 @@ #include #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 diff --git a/src/lib/lttng-ust/lttng-ust-comm.c b/src/lib/lttng-ust/lttng-ust-comm.c index 7f34efe7..0a039fef 100644 --- a/src/lib/lttng-ust/lttng-ust-comm.c +++ b/src/lib/lttng-ust/lttng-ust-comm.c @@ -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; diff --git a/src/lib/lttng-ust/lttng-ust-statedump.c b/src/lib/lttng-ust/lttng-ust-statedump.c index 309a98fa..bd95c043 100644 --- a/src/lib/lttng-ust/lttng-ust-statedump.c +++ b/src/lib/lttng-ust/lttng-ust-statedump.c @@ -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;