Skip to contentSkip to conversation

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

PATCH Applied Dapeng Mi 3 participants 3 messages Jun 24 – Jul 6 perf events

lore
Share & tools
lore

Dapeng Mi

author
#0 lore raw

PATCH v4 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.

---

V4: Remove model-specific ACR sampling test in ratio_to_prev test to avoid false positive. Some hybrid platforms only support ACR on E-cores, e.g., PTL. If the test process is scheduled on P-core, it leads to false positive since P-core doesn't support ACR. test_acr_sampling() is already fair enough to validate ACR sampling functionalities.

History:
V3: https://lore.kernel.org/all/[email protected]/
V2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

 tools/perf/tests/shell/record.sh | 43 ++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tools/perf/tests/shell/record.sh +43 -0
index 7cb81cf3444a..5819f11ad3a9 100755
@@ -402,6 +402,48 @@ 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}"
+  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]"
+    echo "Auto counter reload sampling [Success]"
+    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
+  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 +499,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: 40db90ac9f66c8246c1746c56d397283d161655c

Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Test `test_acr_sampling` is flaky because it structurally relies on the `thloop` workload…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Test test_acr_sampling is flaky because it structurally relies on the thloop workload sustaining an IPC > 2.0. --

commit 8d4447d6783576282b44d2b951b516b17d5c46b1
Author: Dapeng Mi <[email protected]>

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

This commit adds a new sampling test to verify that the intended event records can be captured and that self-reloaded events do not generate any records.

Quoted 4 lines
tools/perf/tests/shell/record.sh +0 -0
index 7cb81cf3444a7..5819f11ad3a90 100755

[ ... ]

tools/perf/tests/shell/record.sh test_callgraph() { · line 407

Quoted 7 lines
tools/perf/tests/shell/record.sh +3 -0
@@ -402,6 +402,48 @@ 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}"

[Severity: Medium]
Does this test configuration require the workload to sustain an IPC greater than 2.0 to pass?

With acr_mask=0x3 on the cycles event, if cycles reaches 20000 before instructions reaches 40000, both counters will automatically reload and no samples will be generated.

tools/perf/tests/shell/record.sh test_callgraph() { · line 414

Quoted 7 lines
tools/perf/tests/shell/record.sh +7 -0
+  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"

If the actual IPC drops to 2.0 or lower (which might happen due to SMT contention, execution on E-cores, or cache effects), the cycles event will repeatedly overflow first. This means zero samples will be recorded, and the grep check here will fail.

Should the event periods be adjusted to tolerate lower IPC values?

Quoted 5 lines
tools/perf/tests/shell/record.sh +5 -0
+  then
+    echo "Auto counter reload sampling [Failed missing instructions event]"
+    err=1
+    return
+  fi

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Dapeng Mi
Quoted 5 lines · Dapeng Mi

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.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung