Skip to contentSkip to conversation

tracing: kprobe-event: Return directly when dyn_event_list is empty

PATCH In review [email protected] 2 participants 4 messages Jan 23 – Jan 26 2 messages not in the archive Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: kprobe-event: Return directly when dyn_event_list is empty

From: sunliming <[email protected]>

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.

---
 kernel/trace/trace_kprobe.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_kprobe.c +3 -0
index 9953506370a5..d89a403c99d4 100644
@@ -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)
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 6 lines · On Fri, 23 Jan 2026 09:36:41 +0800 [email protected] wrote:

From: sunliming <[email protected]>

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.

Quoted 11 lines
---
 kernel/trace/trace_kprobe.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_kprobe.c +0 -0
index 9953506370a5..d89a403c99d4 100644

kernel/trace/trace_kprobe.c static __init void enable_boot_kprobe_events(void) · line 1986

Quoted 5 lines
kernel/trace/trace_kprobe.c +2 -0
@@ -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

Quoted 4 lines
kernel/trace/trace_kprobe.c +1 -0
+
 	guard(mutex)(&event_mutex);
 	for_each_trace_kprobe(tk, pos) {
 		list_for_each_entry(file, &tr->events, list)

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw
Quoted 9 lines · On Mon, 26 Jan 2026 10:56:59 +0800 sunliming <[email protected]> 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).

Quoted 11 lines

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:

Quoted 12 lines
[ 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

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#5 lore raw
Quoted 2 lines · On Mon, 26 Jan 2026 15:17:28 +0800 sunliming <[email protected]> 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