Commit 020e5f85cb087a40572c8b8b2dd06292a14fa212

Authored by Li Zefan
Committed by Ingo Molnar
1 parent c5cb5a2d8d

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 <lizf@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <4A4ACE29.3010407@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 5 changed files with 52 additions and 6 deletions Side-by-side Diff

Documentation/kernel-parameters.txt
... ... @@ -2478,6 +2478,11 @@
2478 2478 trace_buf_size=nn[KMG]
2479 2479 [FTRACE] will set tracing buffer size.
2480 2480  
  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 +
2481 2486 trix= [HW,OSS] MediaTrix AudioTrix Pro
2482 2487 Format:
2483 2488 <io>,<irq>,<dma>,<dma2>,<sb_io>,<sb_irq>,<sb_dma>,<mpu_io>,<mpu_irq>
Documentation/trace/events.txt
... ... @@ -83,6 +83,15 @@
83 83 X - there is a mixture of events enabled and disabled
84 84 ? - this file does not affect any event
85 85  
  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 +
86 95 3. Defining an event-enabled tracepoint
87 96 =======================================
88 97  
kernel/trace/trace.c
... ... @@ -49,7 +49,7 @@
49 49 * On boot up, the ring buffer is set to the minimum size, so that
50 50 * we do not waste memory on systems that are not using tracing.
51 51 */
52   -static int ring_buffer_expanded;
  52 +int ring_buffer_expanded;
53 53  
54 54 /*
55 55 * We need to change this state when a selftest is running.
... ... @@ -63,7 +63,7 @@
63 63 /*
64 64 * If a tracer is running, we do not want to run SELFTEST.
65 65 */
66   -static bool __read_mostly tracing_selftest_disabled;
  66 +bool __read_mostly tracing_selftest_disabled;
67 67  
68 68 /* For tracers that don't implement custom flags */
69 69 static struct tracer_opt dummy_tracer_opt[] = {
kernel/trace/trace.h
... ... @@ -517,6 +517,9 @@
517 517 extern int DYN_FTRACE_TEST_NAME(void);
518 518 #endif
519 519  
  520 +extern int ring_buffer_expanded;
  521 +extern bool tracing_selftest_disabled;
  522 +
520 523 #ifdef CONFIG_FTRACE_STARTUP_TEST
521 524 extern int trace_selftest_startup_function(struct tracer *trace,
522 525 struct trace_array *tr);
kernel/trace/trace_events.c
... ... @@ -17,6 +17,8 @@
17 17 #include <linux/ctype.h>
18 18 #include <linux/delay.h>
19 19  
  20 +#include <asm/setup.h>
  21 +
20 22 #include "trace_output.h"
21 23  
22 24 #define TRACE_SYSTEM "TRACE_SYSTEM"
... ... @@ -1133,6 +1135,18 @@
1133 1135 extern struct ftrace_event_call __start_ftrace_events[];
1134 1136 extern struct ftrace_event_call __stop_ftrace_events[];
1135 1137  
  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 +
1136 1150 static __init int event_trace_init(void)
1137 1151 {
1138 1152 struct ftrace_event_call *call;
... ... @@ -1140,6 +1154,8 @@
1140 1154 struct dentry *entry;
1141 1155 struct dentry *d_events;
1142 1156 int ret;
  1157 + char *buf = bootup_event_buf;
  1158 + char *token;
1143 1159  
1144 1160 d_tracer = tracing_init_dentry();
1145 1161 if (!d_tracer)
... ... @@ -1185,6 +1201,19 @@
1185 1201 &ftrace_event_format_fops);
1186 1202 }
1187 1203  
  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 +
1188 1217 ret = register_module_notifier(&trace_module_nb);
1189 1218 if (ret)
1190 1219 pr_warning("Failed to register trace events module notifier\n");
... ... @@ -1392,10 +1421,10 @@
1392 1421  
1393 1422 static __init int event_trace_self_tests_init(void)
1394 1423 {
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 + }
1399 1428  
1400 1429 return 0;
1401 1430 }