tracing: Override trace_instance parameter
Subsystems (3)
Masami Hiramatsu (Google)
maintainerv3 cover tracing: Override trace_instance parameter
Hi,
Here is the 3rd version of the patches to change the "trace_instance=" kernel parameter to be overridden by later parameters.
The previous version is here:
https://lore.kernel.org/all/179091984881.537422.15308457677039592540.stgit@devnote2/
This version fixes some issues pointed by Sashiko and add more selftests. (the selftest is optional.)
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 prepended to the kernel cmdline. (IOW, the bootconfig expects kernel parameters follow a LAST_WIN policy.)
To fix this issue, [01/02] splits the command line parsing loop and trace instance initialization loop. The parser checks the overlap of the trace instance name and overrides with the later one if those have the same name.
This series also includes a test set as [02/02], which is based on the ftrace boottime test patchset [1], currently on probes/core.
Detailed changes are here:
Changes in v3:
[01/02]
- Count the number of instances in enable_instances().
- Check whether source instance exists before the backup instance.
- Fix memmap_area leaking across loop iterations.
- Add array index range check for boot_instances array.
[02/02]
- Add test cases for overriding memory-mapped instances (@trace).
- Add test cases for overriding backup instances (=source).
- Add test cases for multiple tabs and empty strings.
[1] https://lore.kernel.org/all/178649540853.438282.4271870161169100680.stgit@devnote2/
Thank you,
---
base-commit: b15df7805dc52555e7c867d33a496edf5be11289
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 | 150 +++++++++++++++----- .../cmdline-07-trace-instance-override.bconf | 4 + .../cmdline-07-trace-instance-override.cmdline | 1 .../selftests/ftrace/boottime/run_boottime_test.sh | 2 .../tests/cmdline-07-trace-instance-override.sh | 148 ++++++++++++++++++++ 7 files changed, 290 insertions(+), 37 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 100755 tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh
--
Masami Hiramatsu (Google) <[email protected]>
Masami Hiramatsu (Google)
maintainerPATCH v3 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 adds 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 starts tracing sched:* events.
---
Changes in v3:
- Count the number of tabs in trace_instance= option as the number of trace instance.
- Check whether source instance exists before the backup instance.
- Fix memmap_area leaking in the next loop.
- Count nr_instances in enable_instances().
- Add index range check for boot_instances array.
--- Documentation/admin-guide/kernel-parameters.txt | 7 + Documentation/trace/debugging.rst | 15 ++ kernel/trace/trace.c | 150 +++++++++++++++++------ 3 files changed, 135 insertions(+), 37 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +7 -0
@@ -7806,6 +7806,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
@@ -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 +113 -37
244 lines not on this page · raw message
Masami Hiramatsu (Google)
maintainerPATCH v3 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 later kernel command-line trace_instance= parameter overrides an earlier trace_instance= on the same command line.
- Verifies overriding a memory-mapped trace instance (@trace).
- Verifies overriding a backup trace instance (=source).
- Verifies parsing parameters containing multiple tabs and gracefully handling empty strings.
- Confirms that the overridden instance has its previous events disabled, new events enabled, and flags (such as traceoff) properly applied.
---
Changes in v3:
- Add test cases for overriding memory-mapped instances (@trace).
- Add test cases for overriding backup instances.
- Add test cases for multiple tabs and empty strings.
- Add dmesg and basename to required busybox applets.
--- .../cmdline-07-trace-instance-override.bconf | 4 + .../cmdline-07-trace-instance-override.cmdline | 1 .../selftests/ftrace/boottime/run_boottime_test.sh | 2 .../tests/cmdline-07-trace-instance-override.sh | 148 ++++++++++++++++++++ 4 files changed, 155 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 100755 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 +4 -0
@@ -0,0 +1,4 @@ +kernel.trace_instance = "boot_map@trace,sched:sched_switch", + "bak_to_norm=boot_map", + "bak_from_norm,sched:sched_switch", + "foo,sched:sched_switch"
tools/testing/selftests/ftrace/boottime/cmdlines/cmdline-07-trace-instance-override.cmdline new file +1 -0
@@ -0,0 +1 @@ +reserve_mem=12M:32M:trace trace_instance=foo^traceoff,sched:sched_waking trace_instance=bar,sched:sched_switch trace_instance=bar^traceoff,irq:irq_handler_entry trace_instance=boot_map^traceoff@trace,sched:sched_waking trace_instance=bak_to_norm^traceoff,irq:irq_handler_entry trace_instance=bak_from_norm=boot_map trace_instance="tab1,sched:sched_switch tab2,sched:sched_switch" trace_instance=tab1^traceoff,sched:sched_waking trace_instance= trace_instance="" trace_instance=,
tools/testing/selftests/ftrace/boottime/run_boottime_test.sh +2 -0
@@ -46,6 +46,8 @@ BUSYBOX_APPLETS=( grep sleep sed + dmesg + basename ) usage() {
tools/testing/selftests/ftrace/boottime/tests/cmdline-07-trace-instance-override.sh new file +148 -0
148 lines not on this page · raw message