Re: [PATCH] perf/x86: Fix open counting event error

From: Ravi Bangoria
Date: Thu Apr 24 2025 - 02:52:34 EST


On 23-Apr-25 12:17 PM, Luo Gengkun wrote:
> Perf doesn't work at perf stat for hardware events:
>
> $perf stat -- sleep 1
> Performance counter stats for 'sleep 1':
> 16.44 msec task-clock # 0.016 CPUs utilized
> 2 context-switches # 121.691 /sec
> 0 cpu-migrations # 0.000 /sec
> 54 page-faults # 3.286 K/sec
> <not supported> cycles
> <not supported> instructions
> <not supported> branches
> <not supported> branch-misses

Wondering if it is worth to add this in perf test. Something like
below?

--- a/tools/perf/tests/shell/stat.sh
+++ b/tools/perf/tests/shell/stat.sh
@@ -16,6 +16,24 @@ test_default_stat() {
echo "Basic stat command test [Success]"
}

+test_stat_count() {
+ echo "stat count test"
+
+ if ! perf list | grep -q "cpu-cycles OR cycles"
+ then
+ echo "stat count test [Skipped cpu-cycles event missing]"
+ return
+ fi
+
+ if perf stat -e cycles true 2>&1 | grep -E -q "<not supported>"
+ then
+ echo "stat count test [Failed]"
+ err=1
+ return
+ fi
+ echo "stat count test [Success]"
+}
+
test_stat_record_report() {
echo "stat record and report test"
if ! perf stat record -o - true | perf stat report -i - 2>&1 | \
@@ -201,6 +219,7 @@ test_hybrid() {
}

test_default_stat
+test_stat_count
test_stat_record_report
test_stat_record_script
test_stat_repeat_weak_groups
---

Thanks,
Ravi