[PATCH] perf tests: Add auto counter reload (ACR) sampling test

Dapeng Mi
2026-04-13T01:14:09Z

Add auto counter reload sampling test to verify that the intended event
records can be captured and the self-reloaded events won't generate any
records.

Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
---
tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)

diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index 7cb81cf3444a..1068843282f5 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -402,6 +402,47 @@ test_callgraph() {
echo "Callgraph test [Success]"
}

+test_acr_sampling() {
+ events="{instructions/period=20000,acr_mask=0x2/u,cycles/period=40000,acr_mask=0x3/u}"
+ pebs_events="{instructions/period=20000,acr_mask=0x2/pu,cycles/period=40000,acr_mask=0x3/u}"
+ echo "Auto counter reload sampling test"
+ if ! perf record -o "${perfdata}" -e "${events}" ${testprog} 2> /dev/null
+ then
+ echo "Auto counter reload sampling [Skipped not supported]"
+ return
+ fi
+ if ! perf script -i "${perfdata}" | grep -q "period=20000,acr_mask=0x2"
+ then
+ echo "Auto counter reload sampling [Failed missing instructions event]"
+ err=1
+ return
+ fi
+ if perf script -i "${perfdata}" | grep -q "period=40000,acr_mask=0x3"
+ then
+ echo "Auto counter reload sampling [Failed cycles event shouldn't be sampled]"
+ err=1
+ return
+ fi
+ if ! perf record -o "${perfdata}" -e "${pebs_events}" ${testprog} 2> /dev/null
+ then
+ echo "Auto counter reload PEBS sampling [Skipped not supported]"
+ return
+ fi
+ if ! perf script -i "${perfdata}" | grep -q "period=20000,acr_mask=0x2"
+ then
+ echo "Auto counter reload PEBS sampling [Failed missing instructions event]"
+ err=1
+ return
+ fi
+ if perf script -i "${perfdata}" | grep -q "period=40000,acr_mask=0x3"
+ then
+ echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+ err=1
+ return
+ fi
+ echo "Auto counter reload sampling [Success]"
+}
+
test_ratio_to_prev() {
echo "ratio-to-prev test"
if ! perf record -o /dev/null -e "{instructions, cycles/period=100000,ratio-to-prev=0.5/}" \
@@ -457,6 +498,7 @@ test_leader_sampling
test_topdown_leader_sampling
test_precise_max
test_callgraph
+test_acr_sampling
test_ratio_to_prev

# restore the default value

base-commit: 4e03d6494f9504f8af46ba68a2a8b6877c196789
--
2.34.1