]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tracing: kprobe-event: Return directly when trace kprobes is empty
authorsunliming <sunliming@kylinos.cn>
Tue, 27 Jan 2026 05:38:48 +0000 (13:38 +0800)
committerMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 29 Jan 2026 00:23:43 +0000 (09:23 +0900)
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.

Link: https://lore.kernel.org/all/20260127053848.108473-1-sunliming@linux.dev/
Signed-off-by: sunliming <sunliming@kylinos.cn>
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
kernel/trace/trace_kprobe.c

index 9953506370a5ede4a1b32772171fe55ea7c52ada..95f2c42603d5751c612a724ee67d0ee1379da4ec 100644 (file)
@@ -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)