[PATCH 32/34] perf test cs-etm: Test trace is ordered with context switch records

James Clark james.clark at linaro.org
Wed Nov 18 08:29:54 PST 2026


Enable timestamps in the context switch attribution test and add an
additional check that decoded samples are output in order with context
switch events.

Signed-off-by: James Clark <james.clark at linaro.org>
---
 .../tests/shell/coresight/context_switch_thread.sh   | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/shell/coresight/context_switch_thread.sh b/tools/perf/tests/shell/coresight/context_switch_thread.sh
index 2b9c44b86c59..584661cf47b0 100755
--- a/tools/perf/tests/shell/coresight/context_switch_thread.sh
+++ b/tools/perf/tests/shell/coresight/context_switch_thread.sh
@@ -55,7 +55,7 @@ mkfifo "$cf" "$af"
 # Pin to one CPU so the two threads alternate running but record into the same
 # trace buffer. Start disabled and use the control FIFO to only record the
 # workload and not startup.
-perf record -o "$tmpdir/data" -e cs_etm/timestamp=0/u -C 0 -D -1 --control fifo:"$cf","$af" -- \
+perf record -o "$tmpdir/data" -e cs_etm//u -C 0 -D -1 --control fifo:"$cf","$af" -- \
 	taskset --cpu-list 0 perf test --record-ctl fifo:"$cf","$af" \
 	-w context_switch_loop > /dev/null 2>&1
 
@@ -65,5 +65,23 @@ check_samples
 perf script -i "$tmpdir/data" --itrace=b -F comm,pid,tid,ip,sym > "$tmpdir/script" 2>/dev/null
 check_samples
 
+# Decoded trace should be output in time order with the context switch records.
+# Allow 1ms for estimated trace timestamps.
+perf script -i "$tmpdir/data" --itrace=b --show-switch-events -F time,event > \
+	"$tmpdir/script" 2>/dev/null
+if ! awk 'match($0, /[0-9]+\.[0-9]+:/) {
+		t = substr($0, RSTART, RLENGTH - 1) + 0
+		if (t < last - 0.001) {
+			printf "Time went back %.6fs: %s\n", last - t, $0
+			exit 1
+		}
+		if (t > last)
+			last = t
+	}' "$tmpdir/script"; then
+	echo "Trace was output out of order with context switches"
+	cleanup
+	exit 1
+fi
+
 cleanup
 exit 0

-- 
2.43.0




More information about the linux-arm-kernel mailing list