Skip to content

Commit 0c2580a

Browse files
Yaxiong Tianrostedt
authored andcommitted
blktrace: Make init_blk_tracer() asynchronous
The init_blk_tracer() function causes significant boot delay as it waits for the trace_event_sem lock held by trace_event_update_all(). Specifically, its child function register_trace_event() requires this lock, which is occupied for an extended period during boot. To resolve this, the execution of primary init_blk_tracer() is moved to the trace_init_wq workqueue, allowing it to run asynchronously, and prevent blocking the main boot thread. Link: https://patch.msgid.link/20260204015353.163331-1-tianyaxiong@kylinos.cn Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Yaxiong Tian <tianyaxiong@kylinos.cn> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 1c48f7a commit 0c2580a

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

kernel/trace/blktrace.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,9 @@ static struct trace_event trace_blk_event = {
18321832
.funcs = &trace_blk_event_funcs,
18331833
};
18341834

1835-
static int __init init_blk_tracer(void)
1835+
static struct work_struct blktrace_works __initdata;
1836+
1837+
static int __init __init_blk_tracer(void)
18361838
{
18371839
if (!register_trace_event(&trace_blk_event)) {
18381840
pr_warn("Warning: could not register block events\n");
@@ -1852,6 +1854,25 @@ static int __init init_blk_tracer(void)
18521854
return 0;
18531855
}
18541856

1857+
static void __init blktrace_works_func(struct work_struct *work)
1858+
{
1859+
__init_blk_tracer();
1860+
}
1861+
1862+
static int __init init_blk_tracer(void)
1863+
{
1864+
int ret = 0;
1865+
1866+
if (trace_init_wq) {
1867+
INIT_WORK(&blktrace_works, blktrace_works_func);
1868+
queue_work(trace_init_wq, &blktrace_works);
1869+
} else {
1870+
ret = __init_blk_tracer();
1871+
}
1872+
1873+
return ret;
1874+
}
1875+
18551876
device_initcall(init_blk_tracer);
18561877

18571878
static int blk_trace_remove_queue(struct request_queue *q)

0 commit comments

Comments
 (0)