Linux Trace Kernel
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Yaxiong Tian <tianyaxiong@kylinos.cn>
Cc: rostedt@goodmis.org, axboe@kernel.dk,
	mathieu.desnoyers@efficios.com, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] tracing/kprobes: Make setup_boot_kprobe_events() asynchronous
Date: Wed, 28 Jan 2026 13:49:36 +0900	[thread overview]
Message-ID: <20260128134936.539782c2112073e55e7a0304@kernel.org> (raw)
In-Reply-To: <20260127012312.84659-1-tianyaxiong@kylinos.cn>

On Tue, 27 Jan 2026 09:23:12 +0800
Yaxiong Tian <tianyaxiong@kylinos.cn> 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 waiting for the trace_event_sem  read-write lock,
> which is held for an extended period by trace_event_update_all().
> 
> To resolve this, we have moved the execution of
> setup_boot_kprobe_events() to the trace_init_wq  workqueue, allowing
> it to run asynchronously.
> 
> Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn>
> ---
>  kernel/trace/trace_kprobe.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 9953506370a5..4c6621f02696 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -2031,6 +2031,13 @@ static __init int init_kprobe_trace_early(void)
>  }
>  core_initcall(init_kprobe_trace_early);
>  
> +static struct work_struct kprobe_trace_work __initdata;
> +
> +static void __init kprobe_trace_works_func(struct work_struct *work)
> +{
> +	setup_boot_kprobe_events();
> +}
> +
>  /* Make a tracefs interface for controlling probe points */
>  static __init int init_kprobe_trace(void)
>  {
> @@ -2048,7 +2055,12 @@ static __init int init_kprobe_trace(void)
>  	trace_create_file("kprobe_profile", TRACE_MODE_READ,
>  			  NULL, NULL, &kprobe_profile_ops);
>  
> -	setup_boot_kprobe_events();
> +	if (trace_init_wq) {
> +		INIT_WORK(&kprobe_trace_work, kprobe_trace_works_func);
> +		queue_work(trace_init_wq, &kprobe_trace_work);

Hmm, this queue_work is not required if kprobe_boot_events_buf[] is
empty. We should check it because most of the time we don't need it.
Also, deferring initialization makes it indeterminate when this
tracing will begin.

For kprobe event use case, I think setup_boot_kprobe_events() should
check the kprobe_boot_events_buf is empty at first. But I think Yaxiong
use case happens when you are using kprobe events via cmdline, is that
correct?

I think introducing "async" cmdline option is more preferable.

BTW, I found that the kprobe events from kernel cmdline will be made
after boot-time tracing from bootconfig. Maybe it should be run this
earlier timing too.

Thank you,


> +	} else {
> +		setup_boot_kprobe_events();
> +	}
>  
>  	return 0;
>  }
> -- 
> 2.25.1
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2026-01-28  4:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  1:20 [PATCH v3 0/3] Tracing: Accelerate Kernel Boot by Asynchronizing Yaxiong Tian
2026-01-27  1:23 ` [PATCH v3 1/3] tracing: Rename `eval_map_wq` and allow other parts of tracing use it Yaxiong Tian
2026-01-27  1:23 ` [PATCH v3 2/3] tracing/kprobes: Make setup_boot_kprobe_events() asynchronous Yaxiong Tian
2026-01-28  4:49   ` Masami Hiramatsu [this message]
2026-01-28  7:24     ` Yaxiong Tian
2026-01-28  7:53       ` Masami Hiramatsu
2026-01-28  8:39         ` Yaxiong Tian
2026-01-27  1:23 ` [PATCH v3 3/3] blktrace: Make init_blk_tracer() asynchronous Yaxiong Tian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260128134936.539782c2112073e55e7a0304@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=rostedt@goodmis.org \
    --cc=tianyaxiong@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox