All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/2] tools/perf/tests: perf all metrics test fails when perf_event access is restricted
@ 2023-08-04  5:00 ` Athira Rajeev
  0 siblings, 0 replies; 7+ messages in thread
From: Athira Rajeev @ 2023-08-04  5:00 UTC (permalink / raw)
  To: acme, jolsa, irogers, namhyung
  Cc: linux-perf-users, linuxppc-dev, maddy, atrajeev, kjain, disgoel

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 <atrajeev@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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-07 22:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04  5:00 [PATCH V2 1/2] tools/perf/tests: perf all metrics test fails when perf_event access is restricted Athira Rajeev
2023-08-04  5:00 ` Athira Rajeev
2023-08-04  5:00 ` [PATCH V2 2/2] tools/perf/tests: perf all metricgroups " Athira Rajeev
2023-08-04  5:00   ` Athira Rajeev
2023-08-07 14:44   ` Disha Goel
2023-08-07 21:19     ` Arnaldo Carvalho de Melo
2023-08-07 21:19       ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.