Skip to content

Commit b6fc31b

Browse files
committed
tracing: Add "traceoff" flag to boot time tracing instances
Add a "flags" delimiter (^) to the "trace_instance" kernel command line parameter, and add the "traceoff" flag. The format is: trace_instance=<name>[^<flag1>[^<flag2>]][@<memory>][,<events>] The code allows for more than one flag to be added, but currently only "traceoff" is done so. The motivation for this change came from debugging with the persistent ring buffer and having trace_printk() writing to it. The trace_printk calls are always enabled, and the boot after the crash was having the unwanted trace_printks from the current boot inject into the ring buffer with the trace_printks of the crash kernel, making the output very confusing. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vineeth Pillai <[email protected]> Cc: Beau Belgrave <[email protected]> Cc: Alexander Graf <[email protected]> Cc: Baoquan He <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Cc: David Howells <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Tony Luck <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Kees Cook <[email protected]> Cc: Alexander Aring <[email protected]> Cc: "Luis Claudio R. Goncalves" <[email protected]> Cc: Tomas Glozar <[email protected]> Cc: John Kacur <[email protected]> Cc: Clark Williams <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: "Jonathan Corbet" <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent eb2dcde commit b6fc31b

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6743,6 +6743,15 @@
67436743
the same thing would happen if it was left off). The irq_handler_entry
67446744
event, and all events under the "initcall" system.
67456745

6746+
Flags can be added to the instance to modify its behavior when it is
6747+
created. The flags are separated by '^'. Currently there's only one flag
6748+
defined, and that's "traceoff", to have the tracing instance tracing
6749+
disabled after it is created.
6750+
6751+
trace_instance=foo^traceoff,sched,irq
6752+
6753+
The flags must come before the defined events.
6754+
67466755
If memory has been reserved (see memmap for x86), the instance
67476756
can use that memory:
67486757

@@ -6765,6 +6774,14 @@
67656774
kernel versions where the validator will fail and reset the ring buffer
67666775
if the layout is not the same as the previous kernel.
67676776

6777+
If the ring buffer is used for persistent bootups and has events enabled,
6778+
it is recommend to disable tracing so that events from a previous boot do not
6779+
mix with events of the current boot (unless you are debugging a random crash
6780+
at boot up).
6781+
6782+
reserve_mem=12M:4096:trace trace_instance=boot_map^traceoff@trace,sched,irq
6783+
6784+
67686785
trace_options=[option-list]
67696786
[FTRACE] Enable or disable tracer options at boot.
67706787
The option-list is a comma delimited list of options

kernel/trace/trace.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10468,10 +10468,36 @@ __init static void enable_instances(void)
1046810468
phys_addr_t start = 0;
1046910469
phys_addr_t size = 0;
1047010470
unsigned long addr = 0;
10471+
bool traceoff = false;
10472+
char *flag_delim;
10473+
char *addr_delim;
1047110474

1047210475
tok = strsep(&curr_str, ",");
10473-
name = strsep(&tok, "@");
1047410476

10477+
flag_delim = strchr(tok, '^');
10478+
addr_delim = strchr(tok, '@');
10479+
10480+
if (addr_delim)
10481+
*addr_delim++ = '\0';
10482+
10483+
if (flag_delim)
10484+
*flag_delim++ = '\0';
10485+
10486+
name = tok;
10487+
10488+
if (flag_delim) {
10489+
char *flag;
10490+
10491+
while ((flag = strsep(&flag_delim, "^"))) {
10492+
if (strcmp(flag, "traceoff") == 0)
10493+
traceoff = true;
10494+
else
10495+
pr_info("Tracing: Invalid instance flag '%s' for %s\n",
10496+
flag, name);
10497+
}
10498+
}
10499+
10500+
tok = addr_delim;
1047510501
if (tok && isdigit(*tok)) {
1047610502
start = memparse(tok, &tok);
1047710503
if (!start) {
@@ -10519,6 +10545,9 @@ __init static void enable_instances(void)
1051910545
continue;
1052010546
}
1052110547

10548+
if (traceoff)
10549+
tracer_tracing_off(tr);
10550+
1052210551
/* Only allow non mapped buffers to be deleted */
1052310552
if (!start)
1052410553
trace_array_put(tr);

0 commit comments

Comments
 (0)