Skip to contentSkip to conversation

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

PATCH Superseded Dapeng Mi 3 participants 10 messages Apr 13 – Apr 16 perf events

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Dapeng Mi

author
#0 lore raw

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

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +42 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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

Signature · 1 line
2.34.1
#1 lore raw
Sashiko AI review found 1 potential issue(s): - [Medium] The test fails to genuinely verify that self-reloaded events do not generate records because the chosen sample periods and workload ensure…

Sashiko AI review found 1 potential issue(s):
- [Medium] The test fails to genuinely verify that self-reloaded events do not generate records because the chosen sample periods and workload ensure the self-reloaded event never actually overflows. --

commit 5e7a7e069f4c078327e3d8166d7f74d9084ec8a4
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 self-reloaded events do not generate any records.

Quoted 4 lines
tools/perf/tests/shell/record.sh +0 -0
index 7cb81cf3444a7..1068843282f51 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,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}"

Does this test configuration actually verify that self-reloaded events do not generate records?

The test runs the thloop workload, which is a tight CPU loop with an inherently high IPC (typically > 0.5). With periods of 20000 for instructions and 40000 for cycles, the instructions event will always overflow first.

When the instructions event overflows, its acr_mask=0x2 triggers an auto-reload of the cycles counter, resetting its progress toward overflow.

Because it is continually reset by the instructions event before reaching 40000, the cycles counter never overflows.

The test asserts that no records are generated for cycles and passes, but is this simply because the event never fired rather than due to self-reloaded PMI suppression working correctly?

If the hardware PMI suppression for self-reloaded events was broken, wouldn't this test still pass?

Additionally, if the test ran on a system with IPC < 0.5, wouldn't the cycles event overflow first, resetting both itself and instructions (acr_mask=0x3)? This would prevent instructions from generating a record, causing the test to fail.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author
#2 lore raw
Quoted 28 lines · On 4/13/2026 9:26 AM, [email protected] wrote:

Sashiko AI review found 1 potential issue(s):
- [Medium] The test fails to genuinely verify that self-reloaded events do not generate records because the chosen sample periods and workload ensure the self-reloaded event never actually overflows. --

commit 5e7a7e069f4c078327e3d8166d7f74d9084ec8a4
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 self-reloaded events do not generate any records.

Quoted 4 lines
tools/perf/tests/shell/record.sh +0 -0
index 7cb81cf3444a7..1068843282f51 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,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}"

Does this test configuration actually verify that self-reloaded events do not generate records?

Quoted 3 lines

The test runs the thloop workload, which is a tight CPU loop with an inherently high IPC (typically > 0.5). With periods of 20000 for instructions and 40000 for cycles, the instructions event will always overflow first.

Hmm, makes sense. I would check the IPC of the thloop workload. Suppose setting periods of both instructions and cycles to 20000 (IPC=1) could be a better choice.

Thanks.

Quoted 19 lines

When the instructions event overflows, its acr_mask=0x2 triggers an auto-reload of the cycles counter, resetting its progress toward overflow.

Because it is continually reset by the instructions event before reaching 40000, the cycles counter never overflows.

The test asserts that no records are generated for cycles and passes, but is this simply because the event never fired rather than due to self-reloaded PMI suppression working correctly?

If the hardware PMI suppression for self-reloaded events was broken, wouldn't this test still pass?

Additionally, if the test ran on a system with IPC < 0.5, wouldn't the cycles event overflow first, resetting both itself and instructions (acr_mask=0x3)? This would prevent instructions from generating a record, causing the test to fail.

reviewer
#3 lore raw
In reply to Dapeng Mi
Quoted 47 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +29 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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]"

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

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

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Thanks,
Ian

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

author
#4 lore raw
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Good idea. Sure.

Quoted 22 lines

Thanks,
Ian

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

author
#5 lore raw
In reply to Ian Rogers
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Ian, it could be hard to validate ratio-to-prev option in this test. On platforms which don't support ACR, perf would automatically fallback the ACR sampling to normal sampling, this would lead to false positives on checking the existence of records from cycles event. I didn't find a good way to figure out this fallback.

Since we already have independent test case to validate the ratio_to_prev parsing. It may be unnecessary to add ratio-to-prev validation in this ACR test.

Quoted 22 lines

Thanks,
Ian

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

reviewer
#6 lore raw
Quoted 69 lines · Dapeng
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Ian, it could be hard to validate ratio-to-prev option in this test. On platforms which don't support ACR, perf would automatically fallback the ACR sampling to normal sampling, this would lead to false positives on checking the existence of records from cycles event. I didn't find a good way to figure out this fallback.

Quoted 3 lines

Since we already have independent test case to validate the ratio_to_prev parsing. It may be unnecessary to add ratio-to-prev validation in this ACR test.

So the ratio_to_prev test covers parsing the ratio-to-prev option (it only has perf record commands) and ensures it is acted upon, but it doesn't check the option's functional behavior - what the output is. This test makes sure the acr_mask option is functional and so would be complemented by ratio-to-prev testing somethig like:

```
  rtp_events="{instructions,cycles/period=40000,ratio-to-prev=0.5/u}"

  # Test ratio-to-prev
  if ! perf record -o "${perfdata}" -e "${rtp_events}" ${testprog} 2> /dev/null
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed record
ratio-to-prev]"
    err=1
    return
  fi
  if ! perf script -i "${perfdata}" | grep -q "instructions"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed missing
instructions event]"
    err=1
    return
  fi
  if perf script -i "${perfdata}" | grep -q "cycles"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed cycles
event shouldn't be sampled]"
    err=1
    return
  fi
```

The first thing your test does is to make sure the acr_mask is supported, so I'm not sure how the fall back can happen? We could additionally check for /sys/bus/event_source/devices/cpu*/format/acr_mask.

Thanks,
Ian

Quoted 22 lines
Quoted 22 lines

Thanks,
Ian

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

author
#7 lore raw
Quoted 102 lines · Ian Rogers
Quoted 67 lines · Dapeng
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Ian, it could be hard to validate ratio-to-prev option in this test. On platforms which don't support ACR, perf would automatically fallback the ACR sampling to normal sampling, this would lead to false positives on checking the existence of records from cycles event. I didn't find a good way to figure out this fallback.

Quoted 3 lines

Since we already have independent test case to validate the ratio_to_prev parsing. It may be unnecessary to add ratio-to-prev validation in this ACR test.

So the ratio_to_prev test covers parsing the ratio-to-prev option (it only has perf record commands) and ensures it is acted upon, but it doesn't check the option's functional behavior - what the output is. This test makes sure the acr_mask option is functional and so would be complemented by ratio-to-prev testing somethig like:

```
  rtp_events="{instructions,cycles/period=40000,ratio-to-prev=0.5/u}"

  # Test ratio-to-prev
  if ! perf record -o "${perfdata}" -e "${rtp_events}" ${testprog} 2> /dev/null
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed record
ratio-to-prev]"
    err=1
    return
  fi
  if ! perf script -i "${perfdata}" | grep -q "instructions"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed missing
instructions event]"
    err=1
    return
  fi
  if perf script -i "${perfdata}" | grep -q "cycles"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed cycles
event shouldn't be sampled]"
    err=1
    return
  fi
```
Quoted 4 lines

The first thing your test does is to make sure the acr_mask is supported, so I'm not sure how the fall back can happen? We could additionally check for /sys/bus/event_source/devices/cpu*/format/acr_mask.

Yes, that's initially what I intended to do, but it would cause false positives on some hybrid platform, like PTL which only supports ACR on E-core.

```

$ grep . /sys/bus/event_source/devices/cpu_core/format/*
/sys/bus/event_source/devices/cpu_core/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_core/format/edge:config:18
/sys/bus/event_source/devices/cpu_core/format/eq:config:36
/sys/bus/event_source/devices/cpu_core/format/event:config:0-7
/sys/bus/event_source/devices/cpu_core/format/frontend:config1:0-23
/sys/bus/event_source/devices/cpu_core/format/inv:config:23
/sys/bus/event_source/devices/cpu_core/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_core/format/metrics_clear:config1:0
/sys/bus/event_source/devices/cpu_core/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_core/format/pc:config:19
/sys/bus/event_source/devices/cpu_core/format/umask:config:8-15,40-47

$ grep . /sys/bus/event_source/devices/cpu_atom/format/*
/sys/bus/event_source/devices/cpu_atom/format/acr_mask:config2:0-63
/sys/bus/event_source/devices/cpu_atom/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_atom/format/edge:config:18
/sys/bus/event_source/devices/cpu_atom/format/eq:config:36
/sys/bus/event_source/devices/cpu_atom/format/event:config:0-7
/sys/bus/event_source/devices/cpu_atom/format/inv:config:23
/sys/bus/event_source/devices/cpu_atom/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_atom/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/pc:config:19
/sys/bus/event_source/devices/cpu_atom/format/snoop_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/umask:config:8-15,40-47

```

So strictly speaking, we need to check if it's a hybrid platform first and then check if the exact P-core/E-core supports ACR, then run the above ACR tests. It seems a little bit over-complicated and I'm not sure if it's accepted to add so much Intel specific check in the record.sh.

How's your idea on this? Thanks.

Quoted 25 lines

Thanks,
Ian

Quoted 21 lines
Quoted 21 lines

Thanks,
Ian

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

reviewer
#8 lore raw
Quoted 143 lines · Dapeng
Quoted 102 lines · Ian Rogers
Quoted 67 lines · Dapeng
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Ian, it could be hard to validate ratio-to-prev option in this test. On platforms which don't support ACR, perf would automatically fallback the ACR sampling to normal sampling, this would lead to false positives on checking the existence of records from cycles event. I didn't find a good way to figure out this fallback.

Quoted 3 lines

Since we already have independent test case to validate the ratio_to_prev parsing. It may be unnecessary to add ratio-to-prev validation in this ACR test.

So the ratio_to_prev test covers parsing the ratio-to-prev option (it only has perf record commands) and ensures it is acted upon, but it doesn't check the option's functional behavior - what the output is. This test makes sure the acr_mask option is functional and so would be complemented by ratio-to-prev testing somethig like:

```
  rtp_events="{instructions,cycles/period=40000,ratio-to-prev=0.5/u}"

  # Test ratio-to-prev
  if ! perf record -o "${perfdata}" -e "${rtp_events}" ${testprog} 2> /dev/null
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed record
ratio-to-prev]"
    err=1
    return
  fi
  if ! perf script -i "${perfdata}" | grep -q "instructions"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed missing
instructions event]"
    err=1
    return
  fi
  if perf script -i "${perfdata}" | grep -q "cycles"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed cycles
event shouldn't be sampled]"
    err=1
    return
  fi
```
Quoted 4 lines

The first thing your test does is to make sure the acr_mask is supported, so I'm not sure how the fall back can happen? We could additionally check for /sys/bus/event_source/devices/cpu*/format/acr_mask.

Yes, that's initially what I intended to do, but it would cause false positives on some hybrid platform, like PTL which only supports ACR on E-core.

```

$ grep . /sys/bus/event_source/devices/cpu_core/format/*
/sys/bus/event_source/devices/cpu_core/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_core/format/edge:config:18
/sys/bus/event_source/devices/cpu_core/format/eq:config:36
/sys/bus/event_source/devices/cpu_core/format/event:config:0-7
/sys/bus/event_source/devices/cpu_core/format/frontend:config1:0-23
/sys/bus/event_source/devices/cpu_core/format/inv:config:23
/sys/bus/event_source/devices/cpu_core/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_core/format/metrics_clear:config1:0
/sys/bus/event_source/devices/cpu_core/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_core/format/pc:config:19
/sys/bus/event_source/devices/cpu_core/format/umask:config:8-15,40-47

$ grep . /sys/bus/event_source/devices/cpu_atom/format/*
/sys/bus/event_source/devices/cpu_atom/format/acr_mask:config2:0-63
/sys/bus/event_source/devices/cpu_atom/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_atom/format/edge:config:18
/sys/bus/event_source/devices/cpu_atom/format/eq:config:36
/sys/bus/event_source/devices/cpu_atom/format/event:config:0-7
/sys/bus/event_source/devices/cpu_atom/format/inv:config:23
/sys/bus/event_source/devices/cpu_atom/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_atom/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/pc:config:19
/sys/bus/event_source/devices/cpu_atom/format/snoop_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/umask:config:8-15,40-47

```
Quoted 6 lines

So strictly speaking, we need to check if it's a hybrid platform first and then check if the exact P-core/E-core supports ACR, then run the above ACR tests. It seems a little bit over-complicated and I'm not sure if it's accepted to add so much Intel specific check in the record.sh.

How's your idea on this? Thanks.

Potentially auto counter reload and ratio to prev are generic concepts, it just happens that we only have Intel e-core implementations :-) Matching against cpu* already misses ARM core PMUs. I'm always happy for as much testing as possible. The last code coverage number I have for Linux v6.17 is 38.6% of lines under tools/perf. Since then, I've added quite a bit of testing for commands like perf top. Perhaps we now cover over 50% of the lines of code.

Thanks,
Ian

Quoted 25 lines
Quoted 25 lines

Thanks,
Ian

Quoted 21 lines
Quoted 21 lines

Thanks,
Ian

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

author
#9 lore raw
Quoted 146 lines · Ian Rogers
Quoted 145 lines · Dapeng
Quoted 101 lines · Ian Rogers
Quoted 66 lines · Dapeng
Quoted 51 lines · Ian Rogers
Quoted 50 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.

---
 tools/perf/tests/shell/record.sh | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/shell/record.sh +33 -0
index 7cb81cf3444a..1068843282f5 100755
@@ -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"
Quoted 8 lines

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

Quoted 6 lines
tools/perf/tests/shell/record.sh +6 -0
+  then
+    echo "Auto counter reload PEBS sampling [Failed cycles event shouldn't be sampled]"
+    err=1
+    return
+  fi
+  echo "Auto counter reload sampling [Success]"

Thanks Dapeng! Could we also test ratio-to-prev as well as just the plain acr_mask?

Ian, it could be hard to validate ratio-to-prev option in this test. On platforms which don't support ACR, perf would automatically fallback the ACR sampling to normal sampling, this would lead to false positives on checking the existence of records from cycles event. I didn't find a good way to figure out this fallback.

Quoted 3 lines

Since we already have independent test case to validate the ratio_to_prev parsing. It may be unnecessary to add ratio-to-prev validation in this ACR test.

So the ratio_to_prev test covers parsing the ratio-to-prev option (it only has perf record commands) and ensures it is acted upon, but it doesn't check the option's functional behavior - what the output is. This test makes sure the acr_mask option is functional and so would be complemented by ratio-to-prev testing somethig like:

```
  rtp_events="{instructions,cycles/period=40000,ratio-to-prev=0.5/u}"

  # Test ratio-to-prev
  if ! perf record -o "${perfdata}" -e "${rtp_events}" ${testprog} 2> /dev/null
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed record
ratio-to-prev]"
    err=1
    return
  fi
  if ! perf script -i "${perfdata}" | grep -q "instructions"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed missing
instructions event]"
    err=1
    return
  fi
  if perf script -i "${perfdata}" | grep -q "cycles"
  then
    echo "Auto counter reload ratio-to-prev sampling [Failed cycles
event shouldn't be sampled]"
    err=1
    return
  fi
```
Quoted 4 lines

The first thing your test does is to make sure the acr_mask is supported, so I'm not sure how the fall back can happen? We could additionally check for /sys/bus/event_source/devices/cpu*/format/acr_mask.

Yes, that's initially what I intended to do, but it would cause false positives on some hybrid platform, like PTL which only supports ACR on E-core.

```

$ grep . /sys/bus/event_source/devices/cpu_core/format/*
/sys/bus/event_source/devices/cpu_core/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_core/format/edge:config:18
/sys/bus/event_source/devices/cpu_core/format/eq:config:36
/sys/bus/event_source/devices/cpu_core/format/event:config:0-7
/sys/bus/event_source/devices/cpu_core/format/frontend:config1:0-23
/sys/bus/event_source/devices/cpu_core/format/inv:config:23
/sys/bus/event_source/devices/cpu_core/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_core/format/metrics_clear:config1:0
/sys/bus/event_source/devices/cpu_core/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_core/format/pc:config:19
/sys/bus/event_source/devices/cpu_core/format/umask:config:8-15,40-47

$ grep . /sys/bus/event_source/devices/cpu_atom/format/*
/sys/bus/event_source/devices/cpu_atom/format/acr_mask:config2:0-63
/sys/bus/event_source/devices/cpu_atom/format/cmask:config:24-31
/sys/bus/event_source/devices/cpu_atom/format/edge:config:18
/sys/bus/event_source/devices/cpu_atom/format/eq:config:36
/sys/bus/event_source/devices/cpu_atom/format/event:config:0-7
/sys/bus/event_source/devices/cpu_atom/format/inv:config:23
/sys/bus/event_source/devices/cpu_atom/format/ldlat:config1:0-15
/sys/bus/event_source/devices/cpu_atom/format/offcore_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/pc:config:19
/sys/bus/event_source/devices/cpu_atom/format/snoop_rsp:config1:0-63
/sys/bus/event_source/devices/cpu_atom/format/umask:config:8-15,40-47

```

So strictly speaking, we need to check if it's a hybrid platform first and then check if the exact P-core/E-core supports ACR, then run the above ACR tests. It seems a little bit over-complicated and I'm not sure if it's accepted to add so much Intel specific check in the record.sh.

Quoted 8 lines
Quoted 1 line

How's your idea on this? Thanks.

Potentially auto counter reload and ratio to prev are generic concepts, it just happens that we only have Intel e-core implementations :-) Matching against cpu* already misses ARM core PMUs. I'm always happy for as much testing as possible. The last code coverage number I have for Linux v6.17 is 38.6% of lines under tools/perf. Since then, I've added quite a bit of testing for commands like perf top. Perhaps we now cover over 50% of the lines of code.

Ok, incomplete tests are always better than no tests. I would add the test although it looks not so pretty. :)

Quoted 28 lines

Thanks,
Ian

Quoted 24 lines
Quoted 24 lines

Thanks,
Ian

Quoted 21 lines
Quoted 21 lines

Thanks,
Ian

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