Skip to content

Commit 4ee7c60

Browse files
committed
init, tracing: Add initcall trace events
Being able to trace the start and stop of initcalls is useful to see where the timings are an issue. There is already an "initcall_debug" parameter, but that can cause a large overhead itself, as the printing of the information may take longer than the initcall functions. Adding in a start and finish trace event around the initcall functions, as well as a trace event that records the level of the initcalls, one can get a much finer measurement of the times and interactions of the initcalls themselves, as trace events are much lighter than printk()s. Suggested-by: Abderrahmane Benbachir <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 8ec8405 commit 4ee7c60

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

include/trace/events/initcall.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#undef TRACE_SYSTEM
3+
#define TRACE_SYSTEM initcall
4+
5+
#if !defined(_TRACE_INITCALL_H) || defined(TRACE_HEADER_MULTI_READ)
6+
#define _TRACE_INITCALL_H
7+
8+
#include <linux/tracepoint.h>
9+
10+
TRACE_EVENT(initcall_level,
11+
12+
TP_PROTO(const char *level),
13+
14+
TP_ARGS(level),
15+
16+
TP_STRUCT__entry(
17+
__string(level, level)
18+
),
19+
20+
TP_fast_assign(
21+
__assign_str(level, level);
22+
),
23+
24+
TP_printk("level=%s", __get_str(level))
25+
);
26+
27+
TRACE_EVENT(initcall_start,
28+
29+
TP_PROTO(initcall_t func),
30+
31+
TP_ARGS(func),
32+
33+
TP_STRUCT__entry(
34+
__field(initcall_t, func)
35+
),
36+
37+
TP_fast_assign(
38+
__entry->func = func;
39+
),
40+
41+
TP_printk("func=%pS", __entry->func)
42+
);
43+
44+
TRACE_EVENT(initcall_finish,
45+
46+
TP_PROTO(initcall_t func, int ret),
47+
48+
TP_ARGS(func, ret),
49+
50+
TP_STRUCT__entry(
51+
__field(initcall_t, func)
52+
__field(int, ret)
53+
),
54+
55+
TP_fast_assign(
56+
__entry->func = func;
57+
__entry->ret = ret;
58+
),
59+
60+
TP_printk("func=%pS ret=%d", __entry->func, __entry->ret)
61+
);
62+
63+
#endif /* if !defined(_TRACE_GPIO_H) || defined(TRACE_HEADER_MULTI_READ) */
64+
65+
/* This part must be outside protection */
66+
#include <trace/define_trace.h>

init/main.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
#include <asm/sections.h>
9898
#include <asm/cacheflush.h>
9999

100+
#define CREATE_TRACE_POINTS
101+
#include <trace/events/initcall.h>
102+
100103
static int kernel_init(void *);
101104

102105
extern void init_IRQ(void);
@@ -827,10 +830,12 @@ int __init_or_module do_one_initcall(initcall_t fn)
827830
if (initcall_blacklisted(fn))
828831
return -EPERM;
829832

833+
trace_initcall_start(fn);
830834
if (initcall_debug)
831835
ret = do_one_initcall_debug(fn);
832836
else
833837
ret = fn();
838+
trace_initcall_finish(fn, ret);
834839

835840
msgbuf[0] = 0;
836841

@@ -895,6 +900,7 @@ static void __init do_initcall_level(int level)
895900
level, level,
896901
NULL, &repair_env_string);
897902

903+
trace_initcall_level(initcall_level_names[level]);
898904
for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
899905
do_one_initcall(*fn);
900906
}
@@ -929,6 +935,7 @@ static void __init do_pre_smp_initcalls(void)
929935
{
930936
initcall_t *fn;
931937

938+
trace_initcall_level("early");
932939
for (fn = __initcall_start; fn < __initcall0_start; fn++)
933940
do_one_initcall(*fn);
934941
}

0 commit comments

Comments
 (0)