[PATCH] perf test: Fix fails of perf stat --bpf-counters --for-each-cgroup on s390

From: Thomas Richter
Date: Thu Dec 07 2023 - 07:57:36 EST


On s390 this test fails very often, as can be observed in the output
below. This is caused by the second test function
check_cpu_list_counted(). The perf stat is triggered for 2 CPUs
0 and 1. On s390, which usually has a lot more CPUs, most often
this ends up in no counter increments on these 2 CPUs 0 and 1.

Fix this and trigger explicit workload on CPU 0 and 1 for
systemd. This is a better approach than calculating a long
list of CPUs (which is basicly the same as option -a), or
wait a longer period of time.

Output before:
# for i in $(seq 10)
> do ./perf test 100
> done
100: perf stat --bpf-counters --for-each-cgroup test : FAILED!
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : FAILED!
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : FAILED!
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : FAILED!
100: perf stat --bpf-counters --for-each-cgroup test : Ok
#

Output after:
# for i in $(seq 10);
do ./perf test 100;
done
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
100: perf stat --bpf-counters --for-each-cgroup test : Ok
#

Signed-off-by: Thomas Richter <tmricht@xxxxxxxxxxxxx>
---
tools/perf/tests/shell/stat_bpf_counters_cgrp.sh | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
index e75d0780dc78..f67602321403 100755
--- a/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
+++ b/tools/perf/tests/shell/stat_bpf_counters_cgrp.sh
@@ -60,6 +60,7 @@ check_system_wide_counted()

check_cpu_list_counted()
{
+ taskset -c 0,1 systemctl daemon-reexec &
check_cpu_list_counted_output=$(perf stat -C 0,1 --bpf-counters --for-each-cgroup ${test_cgroups} -e cpu-clock -x, taskset -c 1 sleep 1 2>&1)
if echo ${check_cpu_list_counted_output} | grep -q -F "<not "; then
echo "Some CPU events are not counted"
--
2.43.0