Skip to contentSkip to conversation

tracing: Override trace_instance parameter

PATCH Superseded Masami Hiramatsu (Google) 1 participant 3 messages Sep 19

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Masami Hiramatsu (Google)

author maintainer
#0 lore raw

cover tracing: Override trace_instance parameter

Hi,

This changes the trace_instance= kernel parameter to be overriden by latter parameters. Currently if the user specifies the same name trace_instance at boot time, the later one is skipped. However, this does not allow user to override the trace_instance setting via bootloader if user specifies the default trace_instance in the bootconfig, because the bootconfig parameter is prepend to the kernel cmdline. (IOW, the bootconfig expects kernel parameters are LAST_WIN policy.)

To fix this issue, the [1/2] splits the command line parsing loop and trace instance initialization loop. The parser checks the overlap of the trace instance name and override by the later one if those have the same name.

This series also have a test set as [2/2], which is based on ftrace boottime test patchset [1], which is currently on probes/core branch.

(Steve, can you review the boottime test series too? I think we should have this kind of test anyway, and is nicer to have one in the kernel tree.)

[1] https://lore.kernel.org/all/178649540853.438282.4271870161169100680.stgit@devnote2/

Thank you,

---

Masami Hiramatsu (Google) (2):
tracing: Override the same name trace_instance= by latter one selftests/ftrace: Add test case for overriding trace_instance parameter

 Documentation/admin-guide/kernel-parameters.txt    |    7 +
 Documentation/trace/debugging.rst                  |   15 ++
 kernel/trace/trace.c                               |  127 +++++++++++++++-----
 .../cmdline-07-trace-instance-override.bconf       |    2 
 .../cmdline-07-trace-instance-override.cmdline     |    1 
 .../tests/cmdline-07-trace-instance-override.sh    |   56 +++++++++
 6 files changed, 174 insertions(+), 34 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
 create mode 100644 tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
 create mode 100644 tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh

--
Masami Hiramatsu (Google) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/2 tracing: Override the same name trace_instance= by latter one

From: Masami Hiramatsu (Google) <[email protected]>

Override the same name boot instance by the latter parameter. This allows user to override the trace instance in bootconfig by the cmdline from bootloader.

For example, set default trace_instance parameter in bootconfig e.g.:

  kernel {
     reserve_mem=12M:32M:trace
     trace_instance=boot_map@trace
  }

This just add a persistent trace instance.

And when you need to record events, you can override the boot_map trace instance from bootloader:

trace_instance=boot_map@trace,sched:*

Then the boot_map instance is start tracing sched:* events.

---
 Documentation/admin-guide/kernel-parameters.txt |    7 +
 Documentation/trace/debugging.rst               |   15 +++
 kernel/trace/trace.c                            |  127 +++++++++++++++++------
 3 files changed, 115 insertions(+), 34 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -0
index b5493a7f8f22..232edcd9f2c9 100644
@@ -7768,6 +7768,13 @@ Kernel parameters
 
 			NB: Both the mapped address and size must be page aligned for the architecture.
 
+			Multiple trace_instance= options can be specified to
+			create multiple instances. If the same instance name is
+			specified more than once, the latter one will override
+			any earlier definitions for that instance. This allows
+			overriding an instance configuration that was defined
+			earlier on the command line or via bootconfig.
+
 			See also Documentation/trace/debugging.rst
 
 
Documentation/trace/debugging.rst +15 -0
index bca1710d92bf..b66cc070ae79 100644
@@ -178,3 +178,18 @@ instance without stopping the trace.
 Note that this "backup" instance is readonly, and will be removed automatically
 if you clear the trace data or read out all trace data from the "trace_pipe"
 or the "trace_pipe_raw" files.
+
+Overriding trace instances
+--------------------------
+
+Multiple ``trace_instance=`` options can be specified on the kernel command
+line to create multiple instances. If the same instance name is specified
+more than once, the latter definition will override any previous definitions
+for that instance.
+
+This is useful when an instance configuration is defined in bootconfig, but
+needs to be overridden or modified from the bootloader command line (for
+example, to change the enabled events or add flags like ``traceoff``)::
+
+  trace_instance=boot_map^traceoff@trace
+
kernel/trace/trace.c +93 -34

230 lines not on this page · raw message

author maintainer
#2 lore raw

PATCH 2/2 selftests/ftrace: Add test case for overriding trace_instance parameter

In reply to Masami Hiramatsu (Google)

From: Masami Hiramatsu (Google) <[email protected]>

Add a boot-time tracing test case to verify that specifying multiple trace_instance= parameters with the same instance name overrides earlier definitions:

- Verifies that a kernel command-line trace_instance= parameter overrides an earlier trace instance defined via bootconfig (kernel.trace_instance).
- Verifies that a latter kernel command-line trace_instance= parameter overrides an earlier trace_instance= on the same command line.
- Confirms that the overridden instance has its previous events disabled, new events enabled, and flags (such as traceoff) properly applied.

Assisted-by Antigravity:gemini-3.8-flash
---
 .../cmdline-07-trace-instance-override.bconf       |    2 +
 .../cmdline-07-trace-instance-override.cmdline     |    1 
 .../tests/cmdline-07-trace-instance-override.sh    |   56 ++++++++++++++++++++
 3 files changed, 59 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf
 create mode 100644 tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline
 create mode 100644 tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
tools/testing/selftests/ftrace/boottime/bootconfigs/cmdline-07-trace-instance-override.bconf new file +2 -0
new file mode 100644
index 000000000000..2551da39f722
@@ -0,0 +1,2 @@
+kernel.trace_instance = "foo,sched:sched_switch"
+
tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline new file +1 -0
new file mode 100644
index 000000000000..1953eb5d6f80
@@ -0,0 +1 @@
+trace_instance=foo^traceoff,sched:sched_waking trace_instance=bar,sched:sched_switch trace_instance=bar^traceoff,irq:irq_handler_entry
tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh new file +56 -0

56 lines not on this page · raw message