diff mbox series

[1/4] tracing: Add creation of instances at boot command line

Message ID 20230111145842.376427803@goodmis.org (mailing list archive)
State Superseded
Headers show
Series tracing: Addition of tracing instances via kernel command line | expand

Commit Message

Steven Rostedt Jan. 11, 2023, 2:56 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Add kernel command line to add tracing instances. This only creates
instances at boot but still does not enable any events to them. Later
changes will extend this command line to add enabling of events, filters,
and triggers. As well as possibly redirecting trace_printk()!

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 .../admin-guide/kernel-parameters.txt         |  6 +++
 kernel/trace/trace.c                          | 51 +++++++++++++++++++
 2 files changed, 57 insertions(+)

Comments

Randy Dunlap Jan. 11, 2023, 4:33 p.m. UTC | #1
On 1/11/23 06:56, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Add kernel command line to add tracing instances. This only creates
> instances at boot but still does not enable any events to them. Later
> changes will extend this command line to add enabling of events, filters,
> and triggers. As well as possibly redirecting trace_printk()!
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  .../admin-guide/kernel-parameters.txt         |  6 +++
>  kernel/trace/trace.c                          | 51 +++++++++++++++++++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 6cfa6e3996cf..cec486217ccc 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6272,6 +6272,12 @@
>  			comma-separated list of trace events to enable. See
>  			also Documentation/trace/events.rst
>  
> +	trace_instance=[instance-info]
> +			[FTRACE] Create an ring buffer instance early in boot up.

s/an/a/

> +			This will be listed in:
> +
> +				/sys/kernel/tracing/instances
> +
>  	trace_options=[option-list]
>  			[FTRACE] Enable or disable tracer options at boot.
>  			The option-list is a comma delimited list of options
Ross Zwisler Jan. 12, 2023, 11:24 p.m. UTC | #2
On Wed, Jan 11, 2023 at 09:56:37AM -0500, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Add kernel command line to add tracing instances. This only creates
> instances at boot but still does not enable any events to them. Later
> changes will extend this command line to add enabling of events, filters,
> and triggers. As well as possibly redirecting trace_printk()!
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  .../admin-guide/kernel-parameters.txt         |  6 +++
>  kernel/trace/trace.c                          | 51 +++++++++++++++++++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index 6cfa6e3996cf..cec486217ccc 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6272,6 +6272,12 @@
>  			comma-separated list of trace events to enable. See
>  			also Documentation/trace/events.rst
>  
> +	trace_instance=[instance-info]
> +			[FTRACE] Create an ring buffer instance early in boot up.
> +			This will be listed in:
> +
> +				/sys/kernel/tracing/instances

Should this be "/sys/kernel/debug/tracing/instances"?

Ditto for the text for 'ftrace_boot_snapshot':

	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.

Everywhere else we use /sys/kernel/debug/tracing, though we do use
/sys/kernel/tracing in Documentation/trace/ftrace.txt ?

I guess either works, but having just 1 or the other will help us not confuse
users.

> +
>  	trace_options=[option-list]
>  			[FTRACE] Enable or disable tracer options at boot.
>  			The option-list is a comma delimited list of options
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index a555a861b978..34ed504ffca9 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -48,6 +48,9 @@
>  #include <linux/fsnotify.h>
>  #include <linux/irq_work.h>
>  #include <linux/workqueue.h>
> +#include <linux/workqueue.h>

Duplicate include 1 line above.

> +
> +#include <asm/setup.h> /* COMMAND_LINE_SIZE */
>  
>  #include "trace.h"
>  #include "trace_output.h"
> @@ -186,6 +189,9 @@ static char *default_bootup_tracer;
>  static bool allocate_snapshot;
>  static bool snapshot_at_boot;
>  
> +static char boot_instance_info[COMMAND_LINE_SIZE] __initdata;
> +static int boot_instance_index;
> +
>  static int __init set_cmdline_ftrace(char *str)
>  {
>  	strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
> @@ -239,6 +245,23 @@ static int __init boot_snapshot(char *str)
>  __setup("ftrace_boot_snapshot", boot_snapshot);
>  
>  
> +static int __init boot_instance(char *str)
> +{
> +	char *slot = boot_instance_info + boot_instance_index;
> +	int left = COMMAND_LINE_SIZE - boot_instance_index;

A bit safer to use sizeof(boot_instance_info) instead of COMMAND_LINE_SIZE,
so we can change the allocation size of boot_instance_info without having to
keep them in sync.

These are mostly nits, you can add:

Reviewed-by: Ross Zwisler <zwisler@google.com>
Steven Rostedt Jan. 12, 2023, 11:59 p.m. UTC | #3
On Thu, 12 Jan 2023 16:24:17 -0700
Ross Zwisler <zwisler@google.com> wrote:

> On Wed, Jan 11, 2023 at 09:56:37AM -0500, Steven Rostedt wrote:
> > From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> > 
> > Add kernel command line to add tracing instances. This only creates
> > instances at boot but still does not enable any events to them. Later
> > changes will extend this command line to add enabling of events, filters,
> > and triggers. As well as possibly redirecting trace_printk()!
> > 
> > Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> > ---
> >  .../admin-guide/kernel-parameters.txt         |  6 +++
> >  kernel/trace/trace.c                          | 51 +++++++++++++++++++
> >  2 files changed, 57 insertions(+)
> > 
> > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> > index 6cfa6e3996cf..cec486217ccc 100644
> > --- a/Documentation/admin-guide/kernel-parameters.txt
> > +++ b/Documentation/admin-guide/kernel-parameters.txt
> > @@ -6272,6 +6272,12 @@
> >  			comma-separated list of trace events to enable. See
> >  			also Documentation/trace/events.rst
> >  
> > +	trace_instance=[instance-info]
> > +			[FTRACE] Create an ring buffer instance early in boot up.
> > +			This will be listed in:
> > +
> > +				/sys/kernel/tracing/instances  
> 
> Should this be "/sys/kernel/debug/tracing/instances"?

No, the /sys/kernel/debug/tracing is deprecated. It only exists for
backward compatibility. If it's still in documentation, it should be
updated.

> 
> Ditto for the text for 'ftrace_boot_snapshot':
> 
> 	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.
> 
> Everywhere else we use /sys/kernel/debug/tracing, though we do use
> /sys/kernel/tracing in Documentation/trace/ftrace.txt ?

Right, that's because it was missed when I was updating it ;-)

All documentation that references /sys/kernel/debug/tracing should be
replaced with /sys/kernel/tracing.

> 
> I guess either works, but having just 1 or the other will help us not confuse
> users.

Agreed. Want to send a clean up patch? ;-)

> 
> > +
> >  	trace_options=[option-list]
> >  			[FTRACE] Enable or disable tracer options at boot.
> >  			The option-list is a comma delimited list of options
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index a555a861b978..34ed504ffca9 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> > @@ -48,6 +48,9 @@
> >  #include <linux/fsnotify.h>
> >  #include <linux/irq_work.h>
> >  #include <linux/workqueue.h>
> > +#include <linux/workqueue.h>  
> 
> Duplicate include 1 line above.

Good catch.

> 
> > +
> > +#include <asm/setup.h> /* COMMAND_LINE_SIZE */
> >  
> >  #include "trace.h"
> >  #include "trace_output.h"
> > @@ -186,6 +189,9 @@ static char *default_bootup_tracer;
> >  static bool allocate_snapshot;
> >  static bool snapshot_at_boot;
> >  
> > +static char boot_instance_info[COMMAND_LINE_SIZE] __initdata;
> > +static int boot_instance_index;
> > +
> >  static int __init set_cmdline_ftrace(char *str)
> >  {
> >  	strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
> > @@ -239,6 +245,23 @@ static int __init boot_snapshot(char *str)
> >  __setup("ftrace_boot_snapshot", boot_snapshot);
> >  
> >  
> > +static int __init boot_instance(char *str)
> > +{
> > +	char *slot = boot_instance_info + boot_instance_index;
> > +	int left = COMMAND_LINE_SIZE - boot_instance_index;  
> 
> A bit safer to use sizeof(boot_instance_info) instead of COMMAND_LINE_SIZE,
> so we can change the allocation size of boot_instance_info without having to
> keep them in sync.

Either way is fine. I wouldn't make this change if it was the only thing I
needed to fix, but as I need to get rid of the extra "workqueue.h", I can
make this change too.

> 
> These are mostly nits, you can add:
> 
> Reviewed-by: Ross Zwisler <zwisler@google.com>

Thanks!

-- Steve
diff mbox series

Patch

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 6cfa6e3996cf..cec486217ccc 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -6272,6 +6272,12 @@ 
 			comma-separated list of trace events to enable. See
 			also Documentation/trace/events.rst
 
+	trace_instance=[instance-info]
+			[FTRACE] Create an ring buffer instance early in boot up.
+			This will be listed in:
+
+				/sys/kernel/tracing/instances
+
 	trace_options=[option-list]
 			[FTRACE] Enable or disable tracer options at boot.
 			The option-list is a comma delimited list of options
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index a555a861b978..34ed504ffca9 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -48,6 +48,9 @@ 
 #include <linux/fsnotify.h>
 #include <linux/irq_work.h>
 #include <linux/workqueue.h>
+#include <linux/workqueue.h>
+
+#include <asm/setup.h> /* COMMAND_LINE_SIZE */
 
 #include "trace.h"
 #include "trace_output.h"
@@ -186,6 +189,9 @@  static char *default_bootup_tracer;
 static bool allocate_snapshot;
 static bool snapshot_at_boot;
 
+static char boot_instance_info[COMMAND_LINE_SIZE] __initdata;
+static int boot_instance_index;
+
 static int __init set_cmdline_ftrace(char *str)
 {
 	strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
@@ -239,6 +245,23 @@  static int __init boot_snapshot(char *str)
 __setup("ftrace_boot_snapshot", boot_snapshot);
 
 
+static int __init boot_instance(char *str)
+{
+	char *slot = boot_instance_info + boot_instance_index;
+	int left = COMMAND_LINE_SIZE - boot_instance_index;
+	int ret;
+
+	if (strlen(str) >= left)
+		return -1;
+
+	ret = snprintf(slot, left, "%s\t", str);
+	boot_instance_index += ret;
+
+	return 1;
+}
+__setup("trace_instance=", boot_instance);
+
+
 static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
 
 static int __init set_trace_boot_options(char *str)
@@ -10144,6 +10167,31 @@  ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
 	return ret;
 }
 
+__init static void enable_instances(void)
+{
+	struct trace_array *tr;
+	char *curr_str;
+	char *str;
+	char *tok;
+
+	/* A tab is always appended */
+	boot_instance_info[boot_instance_index - 1] = '\0';
+	str = boot_instance_info;
+
+	while ((curr_str = strsep(&str, "\t"))) {
+
+		tok = strsep(&curr_str, ",");
+
+		tr = trace_array_get_by_name(tok);
+		if (!tr) {
+			pr_warn("Failed to create instance buffer %s\n", curr_str);
+			continue;
+		}
+		/* Allow user space to delete it */
+		trace_array_put(tr);
+	}
+}
+
 __init static int tracer_alloc_buffers(void)
 {
 	int ring_buf_size;
@@ -10300,6 +10348,9 @@  void __init early_trace_init(void)
 void __init trace_init(void)
 {
 	trace_event_init();
+
+	if (boot_instance_index)
+		enable_instances();
 }
 
 __init static void clear_boot_tracer(void)