Perf all metrics test fails as below when perf_event access is restricted. ./perf test -v "perf all metrics test" Metric 'Memory_RD_BW_Chip' not printed in: Error: Access to performance monitoring and observability operations is limited. Enforced MAC policy settings (SELinux) can limit access to performance — access to performance monitoring and observability operations for processes without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability. — test child finished with -1 ---- end ---- perf all metrics test: FAILED!
The perf all metrics test picks the input events from "perf list --raw-dump metrics" and runs "perf stat -M "$m"" for each of the metrics in the list. It fails here for some of the metrics which needs access, since it collects system wide resource details/statistics. Fix the testcase to skip those metric events. The check is added at two places: - When metric is run for workload monitoring - when metric is run for system wide. It could happen that some of the metric events are not valid in per-thread mode. Example from an x86 system: $ ./perf stat -M smi_cycles true Error: Invalid event (msr/smi/u) in per-thread mode, enable system wide with '-a'. The test fallbacks to system wide if first stage fails. But when run with system wide for this metric, it hits the issue with access restriction. $ ./perf stat -M smi_cycles -a sleep 0.1 Error: Access to performance monitoring and observability operations is limited. Similar some events report not supported while running with system wide. Example from an x86 system: $ ./perf stat -M tma_info_system_socket_clks -a sleep 0.1 Performance counter stats for 'system wide': <not supported> cbox_0/event=0x0/u 0.102633747 seconds time elapsed Hence the checks for unsupported events and access restrictions is added for both cases. Signed-off-by: Athira Rajeev <atraj...@linux.vnet.ibm.com> --- Changelog: v1 -> v2: Added the check for access restriction in workload as well as system wide check. tools/perf/tests/shell/stat_all_metrics.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/shell/stat_all_metrics.sh b/tools/perf/tests/shell/stat_all_metrics.sh index 54774525e18a..b26420885560 100755 --- a/tools/perf/tests/shell/stat_all_metrics.sh +++ b/tools/perf/tests/shell/stat_all_metrics.sh @@ -1,18 +1,18 @@ #!/bin/bash # perf all metrics test # SPDX-License-Identifier: GPL-2.0 - err=0 +//list="tma_info_system_socket_clks" for m in $(perf list --raw-dump metrics); do echo "Testing $m" result=$(perf stat -M "$m" true 2>&1) - if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "<not supported>" ]] + if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "<not supported>" ]] || [[ "$result" =~ "Access to performance monitoring and observability operations is limited" ]] then continue fi # Failed so try system wide. result=$(perf stat -M "$m" -a sleep 0.01 2>&1) - if [[ "$result" =~ ${m:0:50} ]] + if [[ "$result" =~ ${m:0:50} ]] || [[ "$result" =~ "<not supported>" ]] || [[ "$result" =~ "Access to performance monitoring and observability operations is limited" ]] then continue fi -- 2.31.1