public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiaxing Wang <hello.wjx@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Jiaxing Wang <hello.wjx@gmail.com>
Subject: [PATCH 3/3] tracing: Apply tracer specific options from kernel command line.
Date: Sun, 18 Oct 2015 19:58:10 +0800	[thread overview]
Message-ID: <1445169490-18315-4-git-send-email-hello.wjx@gmail.com> (raw)
In-Reply-To: <1445169490-18315-1-git-send-email-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 keep trace_boot_options_buf from overwritten by strsep() and strstrip()
and can be parsed again, a copy is made for them to work on.

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

Signed-off-by: Jiaxing Wang <hello.wjx@gmail.com>
---
 kernel/trace/trace.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2d3042f..d42af59 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1204,13 +1204,15 @@ static inline int run_tracer_selftest(struct tracer *type)
 }
 #endif /* CONFIG_FTRACE_STARTUP_TEST */
 
+static int __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;
@@ -1268,6 +1270,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
@@ -3603,6 +3608,33 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	return ret;
 }
 
+static int __init apply_trace_boot_options(void)
+{
+	char *option;
+	char *buf;
+	char *str;
+	size_t len;
+
+	if (trace_boot_options) {
+		len = strlen(trace_boot_options);
+
+		buf = str = kmalloc(len + 1, GFP_KERNEL);
+		if (!buf)
+			return -ENOMEM;
+
+		memcpy(buf, trace_boot_options, len + 1);
+
+		while (str) {
+			option = strsep(&str, ",");
+			trace_set_options(&global_trace, option);
+		}
+
+		kfree(buf);
+	}
+
+	return 0;
+}
+
 static ssize_t
 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
@@ -7153,12 +7185,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.1.4


  parent reply	other threads:[~2015-10-18 12:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-18 11:58 [PATCH 0/3] Some tracing fixes Jiaxing Wang
2015-10-18 11:58 ` [PATCH 1/3] tracing: Update instance_rmdir() to use tracefs_remove_recursive Jiaxing Wang
2015-10-18 11:58 ` [PATCH 2/3] tracing: Make tracing work when debugfs is not compiled or initialized Jiaxing Wang
2015-10-18 14:32   ` kbuild test robot
2015-10-19  1:54   ` Jiaxing Wang
2015-11-02 14:16     ` Steven Rostedt
2015-11-04  1:11       ` [PATCH RESEND] " Jiaxing Wang
2015-11-04 15:03         ` Steven Rostedt
2015-11-04 18:54           ` Greg Kroah-Hartman
2015-11-04 20:32             ` Steven Rostedt
2015-11-05  5:23           ` Jiaxing Wang
2015-11-05 15:54             ` Steven Rostedt
2015-11-06  8:02               ` Jiaxing Wang
2015-11-06  8:04               ` [PATCH] tracing: Make tracing work when debugfs is not configured in Jiaxing Wang
2015-10-18 11:58 ` Jiaxing Wang [this message]
2015-11-02 19:04   ` [PATCH 3/3] tracing: Apply tracer specific options from kernel command line Steven Rostedt
2015-11-04  1:14     ` [PATCH v2] " Jiaxing Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445169490-18315-4-git-send-email-hello.wjx@gmail.com \
    --to=hello.wjx@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox