Skip to contentSkip to conversation

tracing: kprobe-event: Return directly when trace kprobes is empty

PATCH In review [email protected] 2 participants 2 messages Jan 27 – Jan 28 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tracing: kprobe-event: Return directly when trace kprobes is empty

From: sunliming <[email protected]>

In enable_boot_kprobe_events(), it returns directly when trace kprobes 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 trace kprobes is empty.

---
v2:
- wrap the the null check for the dyn_event_list with macro trace_kprobe_list_empty

---
 kernel/trace/trace_kprobe.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_kprobe.c +4 -0
index 9953506370a5..95f2c42603d5 100644
@@ -82,6 +82,7 @@ static struct trace_kprobe *to_trace_kprobe(struct dyn_event *ev)
 #define for_each_trace_kprobe(pos, dpos)	\
 	for_each_dyn_event(dpos)		\
 		if (is_trace_kprobe(dpos) && (pos = to_trace_kprobe(dpos)))
+#define trace_kprobe_list_empty() list_empty(&dyn_event_list)
 
 static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
 {
@@ -1982,6 +1983,9 @@ static __init void enable_boot_kprobe_events(void)
 	struct trace_kprobe *tk;
 	struct dyn_event *pos;
 
+	if (trace_kprobe_list_empty())
+		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
#1 lore raw
Quoted 8 lines · On Tue, 27 Jan 2026 13:38:48 +0800 [email protected] wrote:

From: sunliming <[email protected]>

In enable_boot_kprobe_events(), it returns directly when trace kprobes 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 trace kprobes is empty.

Looks good to me. Let me pick it.

Thanks,

Quoted 32 lines

---
v2:
- wrap the the null check for the dyn_event_list with macro trace_kprobe_list_empty

---
 kernel/trace/trace_kprobe.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_kprobe.c +4 -0
index 9953506370a5..95f2c42603d5 100644
@@ -82,6 +82,7 @@ static struct trace_kprobe *to_trace_kprobe(struct dyn_event *ev)
 #define for_each_trace_kprobe(pos, dpos)	\
 	for_each_dyn_event(dpos)		\
 		if (is_trace_kprobe(dpos) && (pos = to_trace_kprobe(dpos)))
+#define trace_kprobe_list_empty() list_empty(&dyn_event_list)
 
 static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
 {
@@ -1982,6 +1983,9 @@ static __init void enable_boot_kprobe_events(void)
 	struct trace_kprobe *tk;
 	struct dyn_event *pos;
 
+	if (trace_kprobe_list_empty())
+		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
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>