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

Eduardo Mucelli Rezende Oliveira posted 1 patch 1 day, 21 hours ago
tools/bootconfig/scripts/bconf2ftrace.sh |  2 +-
tools/bootconfig/scripts/ftrace.sh       | 15 ++++++++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
[PATCH v2] tools/bootconfig: Reset the tracing CPU mask with --init
Posted by Eduardo Mucelli Rezende Oliveira 1 day, 21 hours ago
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")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <edumucelli@gmail.com>
---
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(-)

diff --git a/tools/bootconfig/scripts/bconf2ftrace.sh b/tools/bootconfig/scripts/bconf2ftrace.sh
index 6a3535a2c..f105c7433 100755
--- a/tools/bootconfig/scripts/bconf2ftrace.sh
+++ b/tools/bootconfig/scripts/bconf2ftrace.sh
@@ -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
diff --git a/tools/bootconfig/scripts/ftrace.sh b/tools/bootconfig/scripts/ftrace.sh
index c2b993f8e..cf3b5b72e 100644
--- a/tools/bootconfig/scripts/ftrace.sh
+++ b/tools/bootconfig/scripts/ftrace.sh
@@ -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
-- 
2.53.0