Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Add trace_options kernel command line parameter

Add trace_options to the kernel command line parameter to be able to
set options at early boot. For example, to enable stack dumps of
events, add the following:

trace_options=stacktrace

This along with the trace_event option, you can get not only
traces of the events but also the stack dumps with them.

Requested-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

authored by

Steven Rostedt and committed by
Steven Rostedt
7bcfaf54 0d5c6e1c

+55 -15
+16
Documentation/kernel-parameters.txt
··· 2859 2859 to facilitate early boot debugging. 2860 2860 See also Documentation/trace/events.txt 2861 2861 2862 + trace_options=[option-list] 2863 + [FTRACE] Enable or disable tracer options at boot. 2864 + The option-list is a comma delimited list of options 2865 + that can be enabled or disabled just as if you were 2866 + to echo the option name into 2867 + 2868 + /sys/kernel/debug/tracing/trace_options 2869 + 2870 + For example, to enable stacktrace option (to dump the 2871 + stack trace of each event), add to the command line: 2872 + 2873 + trace_options=stacktrace 2874 + 2875 + See also Documentation/trace/ftrace.txt "trace options" 2876 + section. 2877 + 2862 2878 transparent_hugepage= 2863 2879 [KNL] 2864 2880 Format: [always|madvise|never]
+39 -15
kernel/trace/trace.c
··· 155 155 } 156 156 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops); 157 157 158 + 159 + static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata; 160 + static char *trace_boot_options __initdata; 161 + 162 + static int __init set_trace_boot_options(char *str) 163 + { 164 + strncpy(trace_boot_options_buf, str, MAX_TRACER_SIZE); 165 + trace_boot_options = trace_boot_options_buf; 166 + return 0; 167 + } 168 + __setup("trace_options=", set_trace_boot_options); 169 + 158 170 unsigned long long ns2usecs(cycle_t nsec) 159 171 { 160 172 nsec += 500; ··· 2850 2838 trace_printk_start_stop_comm(enabled); 2851 2839 } 2852 2840 2853 - static ssize_t 2854 - tracing_trace_options_write(struct file *filp, const char __user *ubuf, 2855 - size_t cnt, loff_t *ppos) 2841 + static int trace_set_options(char *option) 2856 2842 { 2857 - char buf[64]; 2858 2843 char *cmp; 2859 2844 int neg = 0; 2860 - int ret; 2845 + int ret = 0; 2861 2846 int i; 2862 2847 2863 - if (cnt >= sizeof(buf)) 2864 - return -EINVAL; 2865 - 2866 - if (copy_from_user(&buf, ubuf, cnt)) 2867 - return -EFAULT; 2868 - 2869 - buf[cnt] = 0; 2870 - cmp = strstrip(buf); 2848 + cmp = strstrip(option); 2871 2849 2872 2850 if (strncmp(cmp, "no", 2) == 0) { 2873 2851 neg = 1; ··· 2876 2874 mutex_lock(&trace_types_lock); 2877 2875 ret = set_tracer_option(current_trace, cmp, neg); 2878 2876 mutex_unlock(&trace_types_lock); 2879 - if (ret) 2880 - return ret; 2881 2877 } 2878 + 2879 + return ret; 2880 + } 2881 + 2882 + static ssize_t 2883 + tracing_trace_options_write(struct file *filp, const char __user *ubuf, 2884 + size_t cnt, loff_t *ppos) 2885 + { 2886 + char buf[64]; 2887 + 2888 + if (cnt >= sizeof(buf)) 2889 + return -EINVAL; 2890 + 2891 + if (copy_from_user(&buf, ubuf, cnt)) 2892 + return -EFAULT; 2893 + 2894 + trace_set_options(buf); 2882 2895 2883 2896 *ppos += cnt; 2884 2897 ··· 5149 5132 &trace_panic_notifier); 5150 5133 5151 5134 register_die_notifier(&trace_die_notifier); 5135 + 5136 + while (trace_boot_options) { 5137 + char *option; 5138 + 5139 + option = strsep(&trace_boot_options, ","); 5140 + trace_set_options(option); 5141 + } 5152 5142 5153 5143 return 0; 5154 5144