Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1262361

[for-next][PATCH 12/13] tracing: Apply tracer specific options from kernel command line.

From Steven Rostedt <rostedt@goodmis.org>
Newsgroups linux.kernel
Subject [for-next][PATCH 12/13] tracing: Apply tracer specific options from kernel command line.
Date 2015-11-04 16:40 +0100
Message-ID <qr8ki-2go-19@gated-at.bofh.it> (permalink)
References <qr8kh-2go-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Jiaxing Wang <hello.wjx@gmail.com>

Currently, the trace_options parameter is only applied in
tracer_alloc_buffers() when global_trace.current_trace is nop_trace,
so a tracer specific option will not be applied even when the specific
tracer is also enabled from kernel command line. For example, the
'func_stack_trace' option can't be enabled with the following kernel
parameter:

  ftrace=function ftrace_filter=kfree trace_options=func_stack_trace

We can enable tracer specific options by simply apply the options again
if the specific tracer is also supplied from command line and started
in register_tracer().

To make trace_boot_options_buf can be parsed again, a comma and a space
is put back if they were replaced by strsep and strstrip respectively.

Also make register_tracer() be __init to access the __init data, and
in fact register_tracer is only called from __init code.

Link: http://lkml.kernel.org/r/1446599669-9294-1-git-send-email-hello.wjx@gmail.com

Signed-off-by: Jiaxing Wang <hello.wjx@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace.c | 45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 6459e141aac3..7fe7cc987dab 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -214,12 +214,10 @@ __setup("alloc_snapshot", boot_alloc_snapshot);
 
 
 static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
-static char *trace_boot_options __initdata;
 
 static int __init set_trace_boot_options(char *str)
 {
 	strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
-	trace_boot_options = trace_boot_options_buf;
 	return 0;
 }
 __setup("trace_options=", set_trace_boot_options);
@@ -1223,13 +1221,15 @@ static inline int run_tracer_selftest(struct tracer *type)
 
 static void add_tracer_options(struct trace_array *tr, struct tracer *t);
 
+static void __init apply_trace_boot_options(void);
+
 /**
  * register_tracer - register a tracer with the ftrace system.
  * @type - the plugin for the tracer
  *
  * Register a new plugin tracer.
  */
-int register_tracer(struct tracer *type)
+int __init register_tracer(struct tracer *type)
 {
 	struct tracer *t;
 	int ret = 0;
@@ -1288,6 +1288,9 @@ int register_tracer(struct tracer *type)
 	/* Do we want this tracer to start on bootup? */
 	tracing_set_tracer(&global_trace, type->name);
 	default_bootup_tracer = NULL;
+
+	apply_trace_boot_options();
+
 	/* disable other selftests, since this will break it. */
 	tracing_selftest_disabled = true;
 #ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -3589,6 +3592,7 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	int neg = 0;
 	int ret = -ENODEV;
 	int i;
+	size_t orig_len = strlen(option);
 
 	cmp = strstrip(option);
 
@@ -3612,9 +3616,37 @@ static int trace_set_options(struct trace_array *tr, char *option)
 
 	mutex_unlock(&trace_types_lock);
 
+	/*
+	 * If the first trailing whitespace is replaced with '\0' by strstrip,
+	 * turn it back into a space.
+	 */
+	if (orig_len > strlen(option))
+		option[strlen(option)] = ' ';
+
 	return ret;
 }
 
+static void __init apply_trace_boot_options(void)
+{
+	char *buf = trace_boot_options_buf;
+	char *option;
+
+	while (true) {
+		option = strsep(&buf, ",");
+
+		if (!option)
+			break;
+		if (!*option)
+			continue;
+
+		trace_set_options(&global_trace, option);
+
+		/* Put back the comma to allow this to be called again */
+		if (buf)
+			*(buf - 1) = ',';
+	}
+}
+
 static ssize_t
 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
@@ -7248,12 +7280,7 @@ __init static int tracer_alloc_buffers(void)
 	INIT_LIST_HEAD(&global_trace.events);
 	list_add(&global_trace.list, &ftrace_trace_arrays);
 
-	while (trace_boot_options) {
-		char *option;
-
-		option = strsep(&trace_boot_options, ",");
-		trace_set_options(&global_trace, option);
-	}
+	apply_trace_boot_options();
 
 	register_snapshot_cmd();
 
-- 
2.6.1


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[for-next][PATCH 00/13] tracing: Some more last minute cleanups and fixes for 4.4 Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 13/13] tracing: Put back comma for empty fields in boot string parsing Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 05/13] tracing: Rename max_stack_lock to stack_trace_max_lock Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 12/13] tracing: Apply tracer specific options from kernel command line. Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 09/13] tracing: Allow dumping traces without tracking trace started cpus Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 02/13] recordmcount: Fix endianness handling bug for nop_mcount Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 07/13] ring_buffer: Do no not complete benchmark reader too early Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 06/13] tracing: Remove redundant TP_ARGS redefining Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 08/13] ring_buffer: Fix more races when terminating the producer in the  benchmark Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 10/13] ring_buffer: Remove unneeded smp_wmb() before wakeup of reader  benchmark Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 04/13] tracing: Allow arch-specific stack tracer Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 03/13] recordmcount: arm64: Replace the ignored mcount call into nop Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100
  [for-next][PATCH 01/13] tracepoints: Fix documentation of RCU lockdep checks Steven Rostedt <rostedt@goodmis.org> - 2015-11-04 16:40 +0100

csiph-web