perf tests: Add auto counter reload (ACR) sampling test
PATCH v2 1/1 perf tests: Add auto counter reload (ACR) sampling test
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.
---
V2: 1) add ratio_to_prev option test. 2) Adjust sampling period to better match the "perf test -w thloop" workload
v1: https://lore.kernel.org/all/[email protected]/
tools/perf/tests/shell/record.sh | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+)
tools/perf/tests/shell/record.sh +89 -0
@@ -402,6 +402,94 @@ test_callgraph() { echo "Callgraph test [Success]" } +test_acr_sampling() { + events="{instructions/period=40000,acr_mask=0x2/u,cycles/period=20000,acr_mask=0x3/u}" + pebs_events="{instructions/period=40000,acr_mask=0x2/pu,cycles/period=20000,acr_mask=0x3/u}" + ratio_events="{instructions:u,cycles/period=20000,ratio-to-prev=0.5/u}" + p_core_ratio_events="{cpu_core/instructions/u,cpu_core/cycles,period=20000,ratio-to-prev=0.5/u}" + e_core_ratio_events="{cpu_atom/instructions/u,cpu_atom/cycles,period=20000,ratio-to-prev=0.5/u}" + echo "Auto counter reload (ACR) 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}" -F event | grep -q "instructions" + then + echo "Auto counter reload sampling [Failed missing instructions event]" + err=1 + return + fi + if perf script -i "${perfdata}" -F event | grep -q "cycles" + 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}" -F event | grep -q "instructions" + then + echo "Auto counter reload PEBS sampling [Failed missing instructions event]" + err=1 + return + fi + if perf script -i "${perfdata}" -F event | grep -q "cycles" + then + echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]" + err=1 + return + fi + + ratio_err=0 + do_ratio_to_prev_test() { + local events=$1 + local cpu=$2 + if ! perf record -o "${perfdata}" -e "${events}" ${testprog} 2> /dev/null + then + echo "Auto counter reload ${cpu} ratio-to-prev sampling [Failed not supported]" + ratio_err=1 + return + fi + if ! perf script -i "${perfdata}" -F event | grep -q "instructions" + then + echo "Auto counter reload ${cpu} ratio-to-prev sampling [Failed missing instructions event]" + ratio_err=1 + return + fi + if perf script -i "${perfdata}" -F event | grep -q "cycles" + then + echo "Auto counter reload ${cpu} ratio-to-prev sampling [Failed cycles event shouldn't be sampled]" + ratio_err=1 + return + fi + } + + # ratio-to-prev sampling would fallback to normal sampling if ACR sampling + # is not supported, so acr_mask must be checked before testing ratio-to-prev sampling. + if [ -e /sys/bus/event_source/devices/cpu/format/acr_mask ] + then + do_ratio_to_prev_test "${ratio_events}" "" + fi + if [ -e /sys/bus/event_source/devices/cpu_core/format/acr_mask ] + then + do_ratio_to_prev_test "${p_core_ratio_events}" "P-core" + fi + if [ -e /sys/bus/event_source/devices/cpu_atom/format/acr_mask ] + then + do_ratio_to_prev_test "${e_core_ratio_events}" "E-core" + fi + if test "$ratio_err" -eq 0 + then + echo "Auto counter reload sampling [Success]" + else + err="${ratio_err}" + fi +} + 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/}" \
@@ -458,6 +546,7 @@ test_topdown_leader_sampling test_precise_max test_callgraph test_ratio_to_prev +test_acr_sampling # restore the default value ulimit -Sn $default_fd_limit
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko AI review found 1 potential issue(s): - [Medium] Early return in the PEBS support check unintentionally skips subsequent ratio-to-prev tests and the final success message. --
Sashiko AI review found 1 potential issue(s):
- [Medium] Early return in the PEBS support check unintentionally skips subsequent ratio-to-prev tests and the final success message. --
commit 4863d01ec678cdb7aeb26a69a3ff812dd0a8e16c
Author: Dapeng Mi <[email protected]>
perf tests: Add auto counter reload (ACR) sampling test
This commit adds an auto counter reload sampling test to verify that the intended event records can be captured and that self-reloaded events won't generate any records.
Quoted 5 lines
tools/perf/tests/shell/record.sh +0
-0@@ -402,6 +402,94 @@ test_callgraph() {
[ ... ]
tools/perf/tests/shell/record.sh test_callgraph() { · line 433
Quoted 5 lines
tools/perf/tests/shell/record.sh +5
-0+ 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 PEBS is not supported, this early return exits the entire function. Does this unintentionally skip the subsequent ratio-to-prev tests and prevent the script from printing the final "Auto counter reload sampling [Success]" message?
The ratio-to-prev tests use the u modifier rather than the p modifier, so it appears they should be allowed to run even if PEBS is not supported.
Quoted 6 lines
tools/perf/tests/shell/record.sh +6
-0+ if ! perf script -i "${perfdata}" -F event | grep -q "instructions" + then + echo "Auto counter reload PEBS sampling [Failed missing instructions event]" + err=1 + return + fi
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 25 lines · On 4/20/2026 11:10 AM, [email protected] wrote:
Sashiko AI review found 1 potential issue(s):
- [Medium] Early return in the PEBS support check unintentionally skips subsequent ratio-to-prev tests and the final success message. --commit
4863d01ec678cdb7aeb26a69a3ff812dd0a8e16c
Author: Dapeng Mi <[email protected]>perf tests: Add auto counter reload (ACR) sampling test
This commit adds an auto counter reload sampling test to verify that the intended event records can be captured and that self-reloaded events won't generate any records.
Quoted 5 lines
tools/perf/tests/shell/record.sh +0
-0@@ -402,6 +402,94 @@ test_callgraph() {[ ... ]
tools/perf/tests/shell/record.sh test_callgraph() { · line 433
Quoted 5 lines
tools/perf/tests/shell/record.sh +5
-0+ if ! perf record -o "${perfdata}" -e "${pebs_events}" ${testprog} 2> /dev/null + then + echo "Auto counter reload PEBS sampling [Skipped not supported]" + return + fi
Quoted 7 lines
If PEBS is not supported, this early return exits the entire function. Does this unintentionally skip the subsequent ratio-to-prev tests and prevent the script from printing the final "Auto counter reload sampling [Success]" message?
The ratio-to-prev tests use the u modifier rather than the p modifier, so it appears they should be allowed to run even if PEBS is not supported.
Hmm, maybe It's a better choice to integrate the ratio_prev_test sampling test into the test_ratio_to_prev case. Thanks.
Quoted 7 lines
Quoted 7 lines
tools/perf/tests/shell/record.sh +6
-0+ if ! perf script -i "${perfdata}" -F event | grep -q "instructions" + then + echo "Auto counter reload PEBS sampling [Failed missing instructions event]" + err=1 + return + fi