tracing: Add snapshot at end of kernel boot up
Subsystems (4)
Steven Rostedt
maintainerPATCH 1/1 tracing: Add snapshot at end of kernel boot up
From: "Steven Rostedt (Google)" <[email protected]>
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
--- .../admin-guide/kernel-parameters.txt | 8 ++++++++ include/linux/ftrace.h | 11 ++++++++++- kernel/trace/ftrace.c | 2 ++ kernel/trace/trace.c | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +8 -0
@@ -1435,6 +1435,14 @@ as early as possible in order to facilitate early boot debugging. + ftrace_boot_snapshot + [FTRACE] On boot up, a snapshot will be taken of the + ftrace ring buffer that can be read at: + /sys/kernel/tracing/snapshot. + This is useful if you need tracing information from kernel + boot up that is likely to be overridden by user space + start up functionality. + ftrace_dump_on_oops[=orig_cpu] [FTRACE] will dump the trace buffers on oops. If no parameter is passed, ftrace will dump
include/linux/ftrace.h +10 -1
@@ -30,6 +30,12 @@#define ARCH_SUPPORTS_FTRACE_OPS 0#endif +#ifdef CONFIG_TRACING +extern void ftrace_boot_snapshot (void ); +#else +static inline void ftrace_boot_snapshot (void ) { } +#endif +#ifdef CONFIG_FUNCTION_TRACER struct ftrace_ops ;struct ftrace_regs ;
@@ -216,7 +222,10 @@ void ftrace_free_init_mem(void);void ftrace_free_mem (struct module *mod,void *start,void *end);#else static inline void ftrace_free_init_mem (void ) { } -static inline void ftrace_free_mem (struct module *mod,void *start,void *end) { } +static inline void ftrace_free_mem (struct module *mod,void *start,void *end) +{ +ftrace_boot_snapshot (); +}#endif /*
kernel/trace/ftrace.c +2 -0
@@ -7123,6 +7123,8 @@ void __init ftrace_free_init_mem(void)void *start = (void *)(&__init_begin);void *end = (void *)(&__init_end); +ftrace_boot_snapshot (); +ftrace_free_mem (NULL , start, end); }
kernel/trace/trace.c +18 -0
@@ -185,6 +185,7 @@ static char bootup_tracer_buf[MAX_TRACER_SIZE] __initdata;static char *default_bootup_tracer;static bool allocate_snapshot; +static bool snapshot_at_boot;static int __init set_cmdline_ftrace (char *str) {
@@ -230,6 +231,15 @@ static int __init boot_alloc_snapshot(char *str)__setup ("alloc_snapshot" , boot_alloc_snapshot); +static int __init boot_snapshot (char *str) +{ + snapshot_at_boot = true; +boot_alloc_snapshot (str); +return 1 ; +} +__setup ("ftrace_boot_snapshot" , boot_snapshot); + +static char trace_boot_options_buf[MAX_TRACER_SIZE ]__initdata ;static int __init set_trace_boot_options (char *str)
@@ -10149,6 +10159,14 @@ __init static int tracer_alloc_buffers(void)return ret; } +void __init ftrace_boot_snapshot (void ) +{ +if (snapshot_at_boot) { +tracing_snapshot (); +internal_trace_puts ("** Boot snapshot taken **\n" ); + } +} +void __init early_trace_init (void ) {if (tracepoint_printk) {
Signature · 1 line
2.34.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Steven,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on linux/master hnaz-mm/master linus/master v5.17-rc7 next-20220310] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Steven-Rostedt/tracing-Add-snapshot-at-end-of-kernel-boot-up/20220311-104216 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: xtensa-buildonly-randconfig-r002-20220310 (https://download.01.org/0day-ci/archive/20220311/[email protected]/config) compiler: xtensa-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/60ed6397c93a264f9ccbc8a6ca0b3ecc4dfdf6da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Steven-Rostedt/tracing-Add-snapshot-at-end-of-kernel-boot-up/20220311-104216 git checkout 60ed6397c93a264f9ccbc8a6ca0b3ecc4dfdf6da
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=xtensa SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux.o(.text+0x7c164): Section mismatch in reference from the function __se_sys_delete_module() to the function .init.text:ftrace_boot_snapshot()
The function __se_sys_delete_module() references
the function __init ftrace_boot_snapshot().
This is often because __se_sys_delete_module lacks a __init annotation or the annotation of ftrace_boot_snapshot is wrong.
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Steven,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on rostedt-trace/for-next]
[also build test WARNING on linux/master hnaz-mm/master linus/master v5.17-rc7 next-20220310] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Steven-Rostedt/tracing-Add-snapshot-at-end-of-kernel-boot-up/20220311-104216 base: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git for-next config: x86_64-randconfig-a001 (https://download.01.org/0day-ci/archive/20220312/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 276ca87382b8f16a65bddac700202924228982f6)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/60ed6397c93a264f9ccbc8a6ca0b3ecc4dfdf6da
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Steven-Rostedt/tracing-Add-snapshot-at-end-of-kernel-boot-up/20220311-104216 git checkout 60ed6397c93a264f9ccbc8a6ca0b3ecc4dfdf6da
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux.o(.text+0x179120): Section mismatch in reference from the function do_init_module() to the function .init.text:ftrace_boot_snapshot()
The function do_init_module() references
the function __init ftrace_boot_snapshot().
This is often because do_init_module lacks a __init annotation or the annotation of ftrace_boot_snapshot is wrong.
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]