Skip to content

Commit cb1f98c

Browse files
committed
tracing: Add creation of instances at boot command line
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()! Link: https://lkml.kernel.org/r/[email protected] Cc: Randy Dunlap <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Andrew Morton <[email protected]> Reviewed-by: Ross Zwisler <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 9971c3f commit cb1f98c

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6272,6 +6272,12 @@
62726272
comma-separated list of trace events to enable. See
62736273
also Documentation/trace/events.rst
62746274

6275+
trace_instance=[instance-info]
6276+
[FTRACE] Create a ring buffer instance early in boot up.
6277+
This will be listed in:
6278+
6279+
/sys/kernel/tracing/instances
6280+
62756281
trace_options=[option-list]
62766282
[FTRACE] Enable or disable tracer options at boot.
62776283
The option-list is a comma delimited list of options

kernel/trace/trace.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include <linux/irq_work.h>
5050
#include <linux/workqueue.h>
5151

52+
#include <asm/setup.h> /* COMMAND_LINE_SIZE */
53+
5254
#include "trace.h"
5355
#include "trace_output.h"
5456

@@ -186,6 +188,9 @@ static char *default_bootup_tracer;
186188
static bool allocate_snapshot;
187189
static bool snapshot_at_boot;
188190

191+
static char boot_instance_info[COMMAND_LINE_SIZE] __initdata;
192+
static int boot_instance_index;
193+
189194
static int __init set_cmdline_ftrace(char *str)
190195
{
191196
strlcpy(bootup_tracer_buf, str, MAX_TRACER_SIZE);
@@ -239,6 +244,23 @@ static int __init boot_snapshot(char *str)
239244
__setup("ftrace_boot_snapshot", boot_snapshot);
240245

241246

247+
static int __init boot_instance(char *str)
248+
{
249+
char *slot = boot_instance_info + boot_instance_index;
250+
int left = sizeof(boot_instance_info) - boot_instance_index;
251+
int ret;
252+
253+
if (strlen(str) >= left)
254+
return -1;
255+
256+
ret = snprintf(slot, left, "%s\t", str);
257+
boot_instance_index += ret;
258+
259+
return 1;
260+
}
261+
__setup("trace_instance=", boot_instance);
262+
263+
242264
static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
243265

244266
static int __init set_trace_boot_options(char *str)
@@ -10144,6 +10166,31 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
1014410166
return ret;
1014510167
}
1014610168

10169+
__init static void enable_instances(void)
10170+
{
10171+
struct trace_array *tr;
10172+
char *curr_str;
10173+
char *str;
10174+
char *tok;
10175+
10176+
/* A tab is always appended */
10177+
boot_instance_info[boot_instance_index - 1] = '\0';
10178+
str = boot_instance_info;
10179+
10180+
while ((curr_str = strsep(&str, "\t"))) {
10181+
10182+
tok = strsep(&curr_str, ",");
10183+
10184+
tr = trace_array_get_by_name(tok);
10185+
if (!tr) {
10186+
pr_warn("Failed to create instance buffer %s\n", curr_str);
10187+
continue;
10188+
}
10189+
/* Allow user space to delete it */
10190+
trace_array_put(tr);
10191+
}
10192+
}
10193+
1014710194
__init static int tracer_alloc_buffers(void)
1014810195
{
1014910196
int ring_buf_size;
@@ -10302,6 +10349,9 @@ void __init early_trace_init(void)
1030210349
void __init trace_init(void)
1030310350
{
1030410351
trace_event_init();
10352+
10353+
if (boot_instance_index)
10354+
enable_instances();
1030510355
}
1030610356

1030710357
__init static void clear_boot_tracer(void)

0 commit comments

Comments
 (0)