lttng_ust_init_thread: initialise cached context values
PATCH v2 1/2 lttng_ust_init_thread: initialise cached context values
From: Norbert Lange <[email protected]>
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.
---
v1 -> v2:
* instead of a bool, use a flag variable
* try to improve consistency for some funciton names
v1:
* see https://lore.kernel.org/all/CADYdroN3=pAe66crtsVT9aHE4T+bT61-tvHFKCuwZYkHhuyFjw@mail.gmail.com/
* Will update docs after review, and do some more tests
during the week
--- src/lib/lttng-ust/lttng-context-cgroup-ns.c | 4 ++- src/lib/lttng-ust/lttng-context-ipc-ns.c | 4 ++- src/lib/lttng-ust/lttng-context-net-ns.c | 4 ++- .../lttng-ust/lttng-context-perf-counters.c | 3 +- src/lib/lttng-ust/lttng-context-procname.c | 4 ++- src/lib/lttng-ust/lttng-context-provider.c | 4 +-- src/lib/lttng-ust/lttng-context-time-ns.c | 4 ++- src/lib/lttng-ust/lttng-context-uts-ns.c | 4 ++- src/lib/lttng-ust/lttng-context-vtid.c | 4 ++- src/lib/lttng-ust/lttng-probes.c | 4 +-- src/lib/lttng-ust/lttng-tracer-core.h | 26 ++++++++------ src/lib/lttng-ust/lttng-ust-comm.c | 34 +++++++++---------- src/lib/lttng-ust/lttng-ust-statedump.c | 2 +- 13 files changed, 61 insertions(+), 40 deletions(-)
src/lib/lttng-ust/lttng-context-cgroup-ns.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_cgroup_ns))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )get_cgroup_ns (); }
src/lib/lttng-ust/lttng-context-ipc-ns.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_ipc_ns))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )get_ipc_ns (); }
src/lib/lttng-ust/lttng-context-net-ns.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_net_ns))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )get_net_ns (); }
src/lib/lttng-ust/lttng-context-perf-counters.c +2 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (ust_perf_mutex_nest))); + (void )flags; }void lttng_perf_lock (void )
src/lib/lttng-ust/lttng-context-procname.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_procname)[0 ])); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )wrapper_getprocname (); }
src/lib/lttng-ust/lttng-context-provider.c +2 -2
@@ -67,7 +67,7 @@ struct lttng_ust_registered_context_provider *lttng_ust_context_provider_registesize_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;
src/lib/lttng-ust/lttng-context-time-ns.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_time_ns))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )get_time_ns (); }
src/lib/lttng-ust/lttng-context-uts-ns.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_uts_ns))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )get_uts_ns (); }
src/lib/lttng-ust/lttng-context-vtid.c +3 -1
@@ -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) { asmvolatile ("" : :"m" (URCU_TLS (cached_vtid))); +if (flags <TNG_UST_INIT_THREAD_CONTEXT_CACHE ) + (void )wrapper_getvtid (); }
src/lib/lttng-ust/lttng-probes.c +2 -2
@@ -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 ;
src/lib/lttng-ust/lttng-tracer-core.h +16 -10
@@ -16,6 +16,11 @@#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,8 +93,9 @@ 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) { + (void )flags; }static inline void lttng_perf_lock (void )
src/lib/lttng-ust/lttng-ust-comm.c +17 -17
@@ -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 ) { asmvolatile ("" : :"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 ;
src/lib/lttng-ust/lttng-ust-statedump.c +1 -1
@@ -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;
Signature · 6 lines
2.35.1 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
PATCH v2 2/2 lttng_ust_init_thread: call urcu_register_thread
From: Norbert Lange <[email protected]>
Eagerly register the thread, and avoid taking mutex during the first tracepoint.
--- src/lib/lttng-ust/lttng-ust-comm.c | 2 ++ 1 file changed, 2 insertions(+)
src/lib/lttng-ust/lttng-ust-comm.c +2 -0
@@ -447,6 +447,8 @@ void lttng_ust_init_thread(void)* this thread attempts to use them. */ lttng_ust_common_init_thread (LTTNG_UST_INIT_THREAD_MASK ); + +lttng_ust_urcu_register_thread (); }int lttng_get_notify_socket (void *owner)
Signature · 6 lines
2.35.1 _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Mathieu Desnoyers via lttng-dev
AppliedRe: [lttng-dev] [PATCH v2 2/2] lttng_ust_init_thread: call urcu_register_thread
Quoted 4 lines · ----- On Aug 1, 2022, at 10:37 AM, Norbert Lange [email protected] wrote:
From: Norbert Lange <[email protected]>
Eagerly register the thread, and avoid taking mutex during the first tracepoint.
Merged, thanks!
Mathieu
Quoted 23 lines
Signed-off-by Norbert Lange <[email protected]>---
src/lib/lttng-ust/lttng-ust-comm.c| 2 ++1 file changed, 2 insertions(+)src/lib/lttng-ust/lttng-ust-comm.c +2
-1@@ -447,6 +447,8 @@ void lttng_ust_init_thread(void)* this thread attempts to use them. */ lttng_ust_common_init_thread (LTTNG_UST_INIT_THREAD_MASK ); + +lttng_ust_urcu_register_thread (); }int lttng_get_notify_socket (void *owner) --2.35.1
Signature · 7 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Review
Quoted 4 lines · ----- On Aug 1, 2022, at 10:36 AM, Norbert Lange via lttng-dev…
#else /* #ifdef
HAVE_LINUX_PERF_EVENT_H*/
static inline(quoted diff) +1
-1-void lttng_ust_perf_counter_alloc_tls(void) +void lttng_ust_perf_counter_init_thread(int flags)
Using
void lttng_ust_perf_counter_init_thread(int flags __attribute__((unused)))
instead.
Quoted 3 lines
{
(quoted diff) +1
-0+ (void)flags;}
Will fixup locally and merge.
Thanks,
Mathieu
Signature · 7 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com _______________________________________________ lttng-dev mailing list [email protected] https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev