Re: [PATCH] tracing: kprobe-event: Return directly when dyn_event_list is empty

2026-01-26 Thread Steven Rostedt
On Mon, 26 Jan 2026 15:17:28 +0800
sunliming  wrote:

> Alternatively, could both optimization solutions coexist (as lock 
> contention may

Yes, the two are orthogonal to each other, and can go in on their own merit.

-- Steve



Re: [PATCH] tracing: kprobe-event: Return directly when dyn_event_list is empty

2026-01-25 Thread Steven Rostedt
On Mon, 26 Jan 2026 10:56:59 +0800
sunliming  wrote:

> During kernel boot, the setup_boot_kprobe_events() function causes
> significant delays, increasing overall startup time.
> 
> The root cause is a lock contention chain: its child function
> 
> enable_boot_kprobe_events() requires the event_mutex, which is already
> 
> held by early_event_add_tracer(). early_event_add_tracer() itself is 
> blocked

Ah, early_event_add_tracer() is called by the work function that sets
up tracers (and the event directories within them).

> 
> waiting for the trace_event_sem  read-write lock, which is held for an 
> extended
> 
>   period by trace_event_update_all(). trace_event_update_all()  is 
> runing in
> 
> eval_map_work_func() in   eval_map_wq.
> 
> On my ARM64 platform machine, the latency can reach around 200ms:
> 
> [ 0.268848] trace_kprobe: try_get_event_mutex 
> kernel/trace/tracekprobe.c,1902,enable_boot_kprobe_events
> [ 0.268849] try down_write 
> kernel/trace/traceevents.c,4114,early_event_add_tracer
> [ 0.482382] done up_write 
> kernel/trace/trace_events.c,3074,trace_event_eval_update
> [ 0.482386] done down_write 
> kernel/trace/trace_events.c,4116,early_event_add_tracer
> [ 0.482868] done up_write 
> kernel/trace/trace_events.c,4119,early_event_add_tracer
> [ 0.482877] trace_kprobe: enable_boot_kprobe_events geted eventmutex
> [ 0.482879] trace_kprobe: enable_bootk_probe_events release eventmutex

I take it that you are aware of this work, as it comes from someone
with the same email domain as you have.

  https://lore.kernel.org/all/[email protected]/

That is moving the kprobe setup into the same work function.

-- Steve



Re: [PATCH] tracing: kprobe-event: Return directly when dyn_event_list is empty

2026-01-24 Thread Steven Rostedt
On Fri, 23 Jan 2026 09:36:41 +0800
[email protected] wrote:

> From: sunliming 
> 
> In enable_boot_kprobe_events(), it returns directly when dyn_event_list is
> empty, thereby reducing the function's execution time. This function may
> otherwise wait for the event_mutex lock for tens of milliseconds on certain
> machines, which is unnecessary when dyn_event_list is empty.

Have you measured this?

I'm curious as to what may be holding the event_mutex at this time.
This is called by the initcall functions which are currently all
serialized. Any conflict would have to be caused by a worker or kthread
and not another initcall callback.

I'm not against the patch, I just want to understand more about it.

> 
> Signed-off-by: sunliming 
> ---
>  kernel/trace/trace_kprobe.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 9953506370a5..d89a403c99d4 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1982,6 +1982,9 @@ static __init void enable_boot_kprobe_events(void)
>   struct trace_kprobe *tk;
>   struct dyn_event *pos;
>  
> + if (list_empty(&dyn_event_list))
> + return;

The above should definitely have a comment or we should wrap that with
another macro because the above is assuming that
for_each_trace_kprobe() uses dyn_event_list. If that ever changes in
the future, this will be broken.

Perhaps we should add a:

if (trace_kprobe_list_empty())
return;

?

-- Steve



> +
>   guard(mutex)(&event_mutex);
>   for_each_trace_kprobe(tk, pos) {
>   list_for_each_entry(file, &tr->events, list)




[PATCH] tracing: kprobe-event: Return directly when dyn_event_list is empty

2026-01-22 Thread sunliming
From: sunliming 

In enable_boot_kprobe_events(), it returns directly when dyn_event_list is
empty, thereby reducing the function's execution time. This function may
otherwise wait for the event_mutex lock for tens of milliseconds on certain
machines, which is unnecessary when dyn_event_list is empty.

Signed-off-by: sunliming 
---
 kernel/trace/trace_kprobe.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 9953506370a5..d89a403c99d4 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1982,6 +1982,9 @@ static __init void enable_boot_kprobe_events(void)
struct trace_kprobe *tk;
struct dyn_event *pos;
 
+   if (list_empty(&dyn_event_list))
+   return;
+
guard(mutex)(&event_mutex);
for_each_trace_kprobe(tk, pos) {
list_for_each_entry(file, &tr->events, list)
-- 
2.25.1