Skip to content

Commit 380af29

Browse files
committed
tracing: Add snapshot at end of kernel boot up
Add ftrace_boot_snapshot kernel parameter that will take a snapshot at the end of boot up just before switching over to user space (it happens during the kernel freeing of init memory). This is useful when there's interesting data that can be collected from kernel start up, but gets overridden by user space start up code. With this option, the ring buffer content from the boot up traces gets saved in the snapshot at the end of boot up. This trace can be read from: /sys/kernel/tracing/snapshot Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent b3bc854 commit 380af29

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,14 @@
14351435
as early as possible in order to facilitate early
14361436
boot debugging.
14371437

1438+
ftrace_boot_snapshot
1439+
[FTRACE] On boot up, a snapshot will be taken of the
1440+
ftrace ring buffer that can be read at:
1441+
/sys/kernel/tracing/snapshot.
1442+
This is useful if you need tracing information from kernel
1443+
boot up that is likely to be overridden by user space
1444+
start up functionality.
1445+
14381446
ftrace_dump_on_oops[=orig_cpu]
14391447
[FTRACE] will dump the trace buffers on oops.
14401448
If no parameter is passed, ftrace will dump

include/linux/ftrace.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
#define ARCH_SUPPORTS_FTRACE_OPS 0
3131
#endif
3232

33+
#ifdef CONFIG_TRACING
34+
extern void ftrace_boot_snapshot(void);
35+
#else
36+
static inline void ftrace_boot_snapshot(void) { }
37+
#endif
38+
3339
#ifdef CONFIG_FUNCTION_TRACER
3440
struct ftrace_ops;
3541
struct ftrace_regs;
@@ -215,7 +221,10 @@ struct ftrace_ops_hash {
215221
void ftrace_free_init_mem(void);
216222
void ftrace_free_mem(struct module *mod, void *start, void *end);
217223
#else
218-
static inline void ftrace_free_init_mem(void) { }
224+
static inline void ftrace_free_init_mem(void)
225+
{
226+
ftrace_boot_snapshot();
227+
}
219228
static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
220229
#endif
221230

kernel/trace/ftrace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7096,6 +7096,8 @@ void __init ftrace_free_init_mem(void)
70967096
void *start = (void *)(&__init_begin);
70977097
void *end = (void *)(&__init_end);
70987098

7099+
ftrace_boot_snapshot();
7100+
70997101
ftrace_free_mem(NULL, start, end);
71007102
}
71017103

kernel/trace/trace.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata;
185185
static char *default_bootup_tracer;
186186

187187
static bool allocate_snapshot;
188+
static bool snapshot_at_boot;
188189

189190
static int __init set_cmdline_ftrace(char *str)
190191
{
@@ -230,6 +231,15 @@ static int __init boot_alloc_snapshot(char *str)
230231
__setup("alloc_snapshot", boot_alloc_snapshot);
231232

232233

234+
static int __init boot_snapshot(char *str)
235+
{
236+
snapshot_at_boot = true;
237+
boot_alloc_snapshot(str);
238+
return 1;
239+
}
240+
__setup("ftrace_boot_snapshot", boot_snapshot);
241+
242+
233243
static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
234244

235245
static int __init set_trace_boot_options(char *str)
@@ -10149,6 +10159,14 @@ __init static int tracer_alloc_buffers(void)
1014910159
return ret;
1015010160
}
1015110161

10162+
void __init ftrace_boot_snapshot(void)
10163+
{
10164+
if (snapshot_at_boot) {
10165+
tracing_snapshot();
10166+
internal_trace_puts("** Boot snapshot taken **\n");
10167+
}
10168+
}
10169+
1015210170
void __init early_trace_init(void)
1015310171
{
1015410172
if (tracepoint_printk) {

0 commit comments

Comments
 (0)