Skip to contentSkip to conversation

tools/bootconfig: Preserve tracing settings across export and replay

PATCH In review Eduardo Mucelli Rezende Oliveira 2 participants 7 messages Nov 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover tools/bootconfig: Preserve tracing settings across export and replay

Hi Masami,

Thanks for reviewing the earlier bootconfig fixes. I found two more cases where a tracefs export loses a setting when you use it again. The graph depth is exported under a name the kernel doesn't recognize at boot, and an all-f CPU mask is left out entirely.

I checked the rendered kernel command line and exercised export and replay on my Ubuntu machine using a tracefs fixture. The series is based on bootconfig/core, including the earlier CPU mask quoting fix.

Thanks,
Eduardo

Eduardo Mucelli Rezende Oliveira (2):
tools/bootconfig: Use the registered global tracing parameter names tools/bootconfig: Preserve all-f tracing CPU masks on export

 Documentation/trace/boottime-trace.rst   |  8 ++++----
 tools/bootconfig/scripts/bconf2ftrace.sh | 21 ++++++++++++++++-----
 tools/bootconfig/scripts/ftrace2bconf.sh |  9 ++++-----
 3 files changed, 24 insertions(+), 14 deletions(-)

base-commit: 0ad31c3252d4c626a93ae6251340ef86b18342d0

Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/2 tools/bootconfig: Use the registered global tracing parameter names

The boot-time tracing guide lists four kernel.* keys that do not match the parameters registered by the tracing code. For example, ftrace2bconf.sh emits kernel.fgraph_max_depth, which bootconfig passes as fgraph_max_depth on the kernel command line. The function-graph tracer registers ftrace_graph_max_depth.

Use the registered names in the guide and the exporter. Teach bconf2ftrace.sh to read those names, with the previous script keys as fallbacks so existing replay configurations still work.

Fixes 47781947947a ("Documentation: tracing: Add boot-time tracing document")
---
 Documentation/trace/boottime-trace.rst   |  8 ++++----
 tools/bootconfig/scripts/bconf2ftrace.sh | 21 ++++++++++++++++-----
 tools/bootconfig/scripts/ftrace2bconf.sh |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)
Documentation/trace/boottime-trace.rst +4 -4
index 2c3c1fedb..68fd6152c 100644
@@ -36,20 +36,20 @@ these options are passed as a part of kernel legacy command line.
 kernel.tp_printk
    Output trace-event data on printk buffer too.
 
-kernel.dump_on_oops [= MODE]
+kernel.ftrace_dump_on_oops [= MODE]
    Dump ftrace on Oops. If MODE = 1 or omitted, dump trace buffer
    on all CPUs. If MODE = 2, dump a buffer on a CPU which kicks Oops.
 
 kernel.traceoff_on_warning
    Stop tracing if WARN_ON() occurs.
 
-kernel.fgraph_max_depth = MAX_DEPTH
+kernel.ftrace_graph_max_depth = MAX_DEPTH
    Set MAX_DEPTH to maximum depth of fgraph tracer.
 
-kernel.fgraph_filters = FILTER[, FILTER2...]
+kernel.ftrace_graph_filter = FILTER[, FILTER2...]
    Add fgraph tracing function filters.
 
-kernel.fgraph_notraces = FILTER[, FILTER2...]
+kernel.ftrace_graph_notrace = FILTER[, FILTER2...]
    Add fgraph non-tracing function filters.
 
 
tools/bootconfig/scripts/bconf2ftrace.sh +16 -5
index 6a3535a2c..e7cda59d2 100755
@@ -276,15 +276,26 @@ setup_instance() { # [instance]
 }
 
 # ftrace global configs (kernel.*)
-if xbc_has_key "kernel.dump_on_oops"; then
-	dump_mode=`xbc_get_val "kernel.dump_on_oops" 1`
+# Prefer the kernel parameter names and accept the old script keys as fallbacks.
+dump_key=kernel.ftrace_dump_on_oops
+xbc_has_key "$dump_key" || dump_key=kernel.dump_on_oops
+if xbc_has_key "$dump_key"; then
+	dump_mode=`xbc_get_val "$dump_key" 1`
 	[ "$dump_mode" ] && dump_mode=`eval echo $dump_mode` || dump_mode=1
 	run_cmd "echo \"$dump_mode\" > /proc/sys/kernel/ftrace_dump_on_oops"
 fi
 
-set_value_of kernel.fgraph_max_depth $TRACEFS/max_graph_depth
-set_array_of kernel.fgraph_filters $TRACEFS/set_graph_function
-set_array_of kernel.fgraph_notraces $TRACEFS/set_graph_notrace
+graph_depth_key=kernel.ftrace_graph_max_depth
+xbc_has_key "$graph_depth_key" || graph_depth_key=kernel.fgraph_max_depth
+set_value_of "$graph_depth_key" $TRACEFS/max_graph_depth
+
+graph_filter_key=kernel.ftrace_graph_filter
+xbc_has_key "$graph_filter_key" || graph_filter_key=kernel.fgraph_filters
+set_array_of "$graph_filter_key" $TRACEFS/set_graph_function
+
+graph_notrace_key=kernel.ftrace_graph_notrace
+xbc_has_key "$graph_notrace_key" || graph_notrace_key=kernel.fgraph_notraces
+set_array_of "$graph_notrace_key" $TRACEFS/set_graph_notrace
 
 # Per-instance/per-event configs
 if ! xbc_has_branch "ftrace" ; then
tools/bootconfig/scripts/ftrace2bconf.sh +3 -2
index b3c976bc9..c23e7cc8a 100755
@@ -46,10 +46,11 @@ emit_kv() { # key =|+= value
 
 global_options() {
 	val=`cat $TRACEFS/max_graph_depth`
-	[ $val != 0 ] && emit_kv kernel.fgraph_max_depth = $val
+	[ $val != 0 ] && emit_kv kernel.ftrace_graph_max_depth = $val
 	if grep -qv "^#" $TRACEFS/set_graph_function $TRACEFS/set_graph_notrace ; then
 		cat 1>&2 << EOF
-# WARN: kernel.fgraph_filters and kernel.fgraph_notrace are not supported, since the wild card expression was expanded and lost from memory.
+# WARN: Cannot export kernel.ftrace_graph_filter and kernel.ftrace_graph_notrace.
+# Only the expanded function list is available.
 EOF
 	fi
 }
Signature · 1 line
2.53.0
#4 lore raw

PATCH 2/2 tools/bootconfig: Preserve all-f tracing CPU masks on export

In reply to Eduardo Mucelli Rezende Oliveira

ftrace2bconf.sh skips tracing_cpumask values consisting only of f digits. For example, on a four-CPU system this drops the mask f. If the mask is subsequently narrowed to 3, replaying the export cannot restore tracing on all four CPUs because the configuration has no cpumask entry.

Always emit the observed mask as one quoted bootconfig value so a replay can restore it.

Fixes 2b86062a34a8 ("tools/bootconfig: Add a script to generates bootconfig from ftrace")
---
 tools/bootconfig/scripts/ftrace2bconf.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
tools/bootconfig/scripts/ftrace2bconf.sh +1 -3
index c23e7cc8a..6d7a1bd68 100755
@@ -278,9 +278,7 @@ instance_options() { # [instance-name]
 		emit_kv $PREFIX.alloc_snapshot
 	fi
 	val=`cat $INSTANCE/tracing_cpumask`
-	if [ `echo $val | sed -e s/f//g`x != x ]; then
-		emit_kv $PREFIX.cpumask = "\"$val\""
-	fi
+	emit_kv $PREFIX.cpumask = "\"$val\""
 	val=`cat $INSTANCE/tracing_on`
 	if [ "$val" = "0" ]; then
 		emit_kv $PREFIX.tracing_on = 0
Signature · 1 line
2.53.0
#5 lore raw

Re: [PATCH 2/2] tools/bootconfig: Preserve all-f tracing CPU masks on export

Hi,

Quoted 6 lines · Eduardo Mucelli Rezende Oliveira

ftrace2bconf.sh skips tracing_cpumask values consisting only of f digits. For example, on a four-CPU system this drops the mask f. If the mask is subsequently narrowed to 3, replaying the export cannot restore tracing on all four CPUs because the configuration has no cpumask entry.

Always emit the observed mask as one quoted bootconfig value so a replay

ftrace2bconf.sh intentionally omits default ftrace settings (such as tracing_on=1, current_tracer=nop, trace_clock=local, max_graph_depth=0, and default trace_options) because bootconfig is primarily meant for boot-time tracing where ftrace starts in its default state. So I think the current implementation is good enough.

For replaying an exported bootconfig onto a live system, bconf2ftrace.sh provides --init (which calls initialize_ftrace() in tools/bootconfig/scripts/ftrace.sh). Rather than emitting default values in ftrace2bconf.sh, shouldn't initialize_ftrace() in tools/bootconfig/scripts/ftrace.sh be updated to reset tracing_cpumask back to all CPUs? Without --init, none of the other omitted defaults (e.g. tracing_on=1, current_tracer=nop, trace_clock=local) are restored on replay either.

Quoted 12 lines

can restore it.

Fixes 2b86062a34a8 ("tools/bootconfig: Add a script to generates bootconfig from ftrace")
---
 tools/bootconfig/scripts/ftrace2bconf.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

tools/bootconfig/scripts/ftrace2bconf.sh instance_options() { # [instance-name] · line 281

Quoted 4 lines
tools/bootconfig/scripts/ftrace2bconf.sh +1 -0
@@ -278,9 +278,7 @@ instance_options() { # [instance-name]
 		emit_kv $PREFIX.alloc_snapshot
 	fi
 	val=`cat $INSTANCE/tracing_cpumask`
+	emit_kv $PREFIX.cpumask = "\"$val\""

Unconditionally emitting cpumask here introduces a portability regression for boot-time tracing: if a user exports a bootconfig on a 4-CPU system with the default all-CPUs mask ("f"), this will now emit ftrace.cpumask = "f". When that bootconfig is used to boot a machine with more CPUs (e.g., 8 or 16 CPUs), tracing will be silently restricted to CPUs 0-3 instead of tracing all CPUs.

Skipping the default all-CPUs mask was intentional so exported bootconfigs remain portable across machines with different CPU counts. If the replay problem occurs with bconf2ftrace.sh --init, the right fix is to reset tracing_cpumask in tools/bootconfig/scripts/ftrace.sh:initialize_ftrace() rather than unconditionally emitting the default mask here.

Thanks,

Quoted 3 lines
tools/bootconfig/scripts/ftrace2bconf.sh +0 -2
-		emit_kv $PREFIX.cpumask = "\"$val\""
-	fi
 	val=`cat $INSTANCE/tracing_on`
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#2 lore raw

Re: [PATCH 1/2] tools/bootconfig: Use the registered global tracing parameter names

In reply to Eduardo Mucelli Rezende Oliveira
Quoted 11 lines · Eduardo Mucelli Rezende Oliveira

The boot-time tracing guide lists four kernel.* keys that do not match the parameters registered by the tracing code. For example, ftrace2bconf.sh emits kernel.fgraph_max_depth, which bootconfig passes as fgraph_max_depth on the kernel command line. The function-graph tracer registers ftrace_graph_max_depth.

Use the registered names in the guide and the exporter. Teach bconf2ftrace.sh to read those names, with the previous script keys as fallbacks so existing replay configurations still work.

Fixes 47781947947a ("Documentation: tracing: Add boot-time tracing document")

Since this patch also fixes the key names in bconf2ftrace.sh and ftrace2bconf.sh (which were added later than the documentation), consider adding the corresponding Fixes tags as well:

Fixes 7e66ef0046cc ("tools/bootconfig: Add a script to generate ftrace

shell-command from bootconfig")

Fixes 2b86062a34a8 ("tools/bootconfig: Add a script to generates

bootconfig from ftrace")

Thanks,

Quoted 6 lines
---
 Documentation/trace/boottime-trace.rst   |  8 ++++----
 tools/bootconfig/scripts/bconf2ftrace.sh | 21 ++++++++++++++++-----
 tools/bootconfig/scripts/ftrace2bconf.sh |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#3 lore raw

Re: [PATCH 1/2] tools/bootconfig: Use the registered global tracing parameter names

Quoted 13 lines · Masami Hiramatsu (Google)
Quoted 11 lines · Eduardo Mucelli Rezende Oliveira

The boot-time tracing guide lists four kernel.* keys that do not match the parameters registered by the tracing code. For example, ftrace2bconf.sh emits kernel.fgraph_max_depth, which bootconfig passes as fgraph_max_depth on the kernel command line. The function-graph tracer registers ftrace_graph_max_depth.

Use the registered names in the guide and the exporter. Teach bconf2ftrace.sh to read those names, with the previous script keys as fallbacks so existing replay configurations still work.

Fixes 47781947947a ("Documentation: tracing: Add boot-time tracing document")
Quoted 8 lines

Since this patch also fixes the key names in bconf2ftrace.sh and ftrace2bconf.sh (which were added later than the documentation), consider adding the corresponding Fixes tags as well:

Fixes 7e66ef0046cc ("tools/bootconfig: Add a script to generate ftrace

shell-command from bootconfig")

Fixes 2b86062a34a8 ("tools/bootconfig: Add a script to generates

bootconfig from ftrace")

BTW, I will update the Fixes tag and pick this patch in the series to bootconfig/fixes because it is obvious a buggy description.

So you can only update 2/2.

Thank you,

Quoted 15 lines

Thanks,

Quoted 6 lines
---
 Documentation/trace/boottime-trace.rst   |  8 ++++----
 tools/bootconfig/scripts/bconf2ftrace.sh | 21 ++++++++++++++++-----
 tools/bootconfig/scripts/ftrace2bconf.sh |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
#6 lore raw

PATCH v2 1/1 tools/bootconfig: Reset the tracing CPU mask with --init

In reply to Masami Hiramatsu (Google)

bconf2ftrace.sh --init resets tracing before replay but leaves the old CPU mask in place. Replaying a configuration without a cpumask can then keep CPUs excluded by an earlier session.

Read the initial mask from a temporary trace instance and restore it during initialization. The mask comes from the replay machine. An explicit cpumask in the configuration is applied after the reset.

Fixes 5675fd4ef51f ("tools/bootconfig: Add --init option for bconf2ftrace.sh")

---
Hi Masami,

Thanks for pointing out the portability issue. I moved the reset to --init. It reads the default mask from a fresh trace instance, so the replay uses the CPU mask of the machine it runs on.

I checked --init and --apply with a tracefs fixture, including a multiword mask and an explicit mask in the input config.

Thanks,
Eduardo

Changes in v2
- Reset the CPU mask in initialize_ftrace() and preserve exporter behavior.
- Restore the replay machine's default before applying config values.

 tools/bootconfig/scripts/bconf2ftrace.sh |  2 +-
 tools/bootconfig/scripts/ftrace.sh       | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
tools/bootconfig/scripts/bconf2ftrace.sh +1 -1
index 6a3535a2c..f105c7433 100755
@@ -64,7 +64,7 @@ fi
 
 if [ x"$INIT" != x ]; then
 	. `dirname $0`/ftrace.sh
-	(cd $TRACEFS; initialize_ftrace)
+	(cd "$TRACEFS" && initialize_ftrace) || exit 1
 fi
 
 . `dirname $0`/xbc.sh
tools/bootconfig/scripts/ftrace.sh +14 -1
index c2b993f8e..cf3b5b72e 100644
@@ -86,10 +86,19 @@ clear_synthetic_events() { # reset all current synthetic events
     done
 }
 
+default_tracing_cpumask() (
+    # A new trace instance starts with all CPUs enabled in its mask.
+    instance=$(mktemp -d instances/bootconfig-XXXXXX) || exit 1
+    trap 'rmdir "$instance" || exit 1' EXIT
+    trap 'exit 1' HUP INT TERM
+    cat "$instance/tracing_cpumask"
+)
+
 initialize_ftrace() { # Reset ftrace to initial-state
 # As the initial state, ftrace will be set to nop tracer,
 # no events, no triggers, no filters, no function filters,
-# no probes, and tracing on.
+# no probes, all CPUs, and tracing on.
+    default_mask=$(default_tracing_cpumask) || return 1
     disable_tracing
     reset_tracer
     reset_trigger
@@ -106,5 +115,9 @@ initialize_ftrace() { # Reset ftrace to initial-state
     [ -f synthetic_events ] && echo > synthetic_events
     [ -f snapshot ] && echo 0 > snapshot
     clear_trace
+    if ! printf '%s\n' "$default_mask" > tracing_cpumask; then
+        enable_tracing
+        return 1
+    fi
     enable_tracing
 }

base-commit: 0ad31c3252d4c626a93ae6251340ef86b18342d0

Signature · 1 line
2.53.0