Skip to content

Commit 020e5f8

Browse files
Li ZefanIngo Molnar
authored andcommitted
tracing/events: Add trace_event boot option
We already have ftrace= boot option, and this adds a similar boot option for trace events, so allow trace events to be enabled at boot, for boot debugging purpose. Signed-off-by: Li Zefan <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Frederic Weisbecker <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent c5cb5a2 commit 020e5f8

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

Documentation/kernel-parameters.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,11 @@ and is between 256 and 4096 characters. It is defined in the file
24782478
trace_buf_size=nn[KMG]
24792479
[FTRACE] will set tracing buffer size.
24802480

2481+
trace_event=[event-list]
2482+
[FTRACE] Set and start specified trace events in order
2483+
to facilitate early boot debugging.
2484+
See also Documentation/trace/events.txt
2485+
24812486
trix= [HW,OSS] MediaTrix AudioTrix Pro
24822487
Format:
24832488
<io>,<irq>,<dma>,<dma2>,<sb_io>,<sb_irq>,<sb_dma>,<mpu_io>,<mpu_irq>

Documentation/trace/events.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ When reading one of these enable files, there are four results:
8383
X - there is a mixture of events enabled and disabled
8484
? - this file does not affect any event
8585

86+
2.3 Boot option
87+
---------------
88+
89+
In order to facilitate early boot debugging, use boot option:
90+
91+
trace_event=[event-list]
92+
93+
The format of this boot option is the same as described in section 2.1.
94+
8695
3. Defining an event-enabled tracepoint
8796
=======================================
8897

kernel/trace/trace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ unsigned long __read_mostly tracing_thresh;
4949
* On boot up, the ring buffer is set to the minimum size, so that
5050
* we do not waste memory on systems that are not using tracing.
5151
*/
52-
static int ring_buffer_expanded;
52+
int ring_buffer_expanded;
5353

5454
/*
5555
* We need to change this state when a selftest is running.
@@ -63,7 +63,7 @@ static bool __read_mostly tracing_selftest_running;
6363
/*
6464
* If a tracer is running, we do not want to run SELFTEST.
6565
*/
66-
static bool __read_mostly tracing_selftest_disabled;
66+
bool __read_mostly tracing_selftest_disabled;
6767

6868
/* For tracers that don't implement custom flags */
6969
static struct tracer_opt dummy_tracer_opt[] = {

kernel/trace/trace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ extern unsigned long ftrace_update_tot_cnt;
517517
extern int DYN_FTRACE_TEST_NAME(void);
518518
#endif
519519

520+
extern int ring_buffer_expanded;
521+
extern bool tracing_selftest_disabled;
522+
520523
#ifdef CONFIG_FTRACE_STARTUP_TEST
521524
extern int trace_selftest_startup_function(struct tracer *trace,
522525
struct trace_array *tr);

kernel/trace/trace_events.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/ctype.h>
1818
#include <linux/delay.h>
1919

20+
#include <asm/setup.h>
21+
2022
#include "trace_output.h"
2123

2224
#define TRACE_SYSTEM "TRACE_SYSTEM"
@@ -1133,13 +1135,27 @@ struct notifier_block trace_module_nb = {
11331135
extern struct ftrace_event_call __start_ftrace_events[];
11341136
extern struct ftrace_event_call __stop_ftrace_events[];
11351137

1138+
static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1139+
1140+
static __init int setup_trace_event(char *str)
1141+
{
1142+
strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1143+
ring_buffer_expanded = 1;
1144+
tracing_selftest_disabled = 1;
1145+
1146+
return 1;
1147+
}
1148+
__setup("trace_event=", setup_trace_event);
1149+
11361150
static __init int event_trace_init(void)
11371151
{
11381152
struct ftrace_event_call *call;
11391153
struct dentry *d_tracer;
11401154
struct dentry *entry;
11411155
struct dentry *d_events;
11421156
int ret;
1157+
char *buf = bootup_event_buf;
1158+
char *token;
11431159

11441160
d_tracer = tracing_init_dentry();
11451161
if (!d_tracer)
@@ -1185,6 +1201,19 @@ static __init int event_trace_init(void)
11851201
&ftrace_event_format_fops);
11861202
}
11871203

1204+
while (true) {
1205+
token = strsep(&buf, ",");
1206+
1207+
if (!token)
1208+
break;
1209+
if (!*token)
1210+
continue;
1211+
1212+
ret = ftrace_set_clr_event(token, 1);
1213+
if (ret)
1214+
pr_warning("Failed to enable trace event: %s\n", token);
1215+
}
1216+
11881217
ret = register_module_notifier(&trace_module_nb);
11891218
if (ret)
11901219
pr_warning("Failed to register trace events module notifier\n");
@@ -1392,10 +1421,10 @@ static __init void event_trace_self_test_with_function(void)
13921421

13931422
static __init int event_trace_self_tests_init(void)
13941423
{
1395-
1396-
event_trace_self_tests();
1397-
1398-
event_trace_self_test_with_function();
1424+
if (!tracing_selftest_disabled) {
1425+
event_trace_self_tests();
1426+
event_trace_self_test_with_function();
1427+
}
13991428

14001429
return 0;
14011430
}

0 commit comments

Comments
 (0)