perf list pfm: Retry supported test with exclude_kernel
authorIan Rogers <irogers@google.com>
Wed, 6 Sep 2023 23:44:16 +0000 (16:44 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 12 Sep 2023 20:32:00 +0000 (17:32 -0300)
With paranoia set at 2 evsel__open will fail with EACCES for non-root
users. To avoid this stopping libpfm4 events from being printed, retry
with exclude_kernel enabled - copying the regular is_event_supported
test.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kang Minchul <tegongkang@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20230906234416.3472339-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/pfm.c

index 862e4a689868b632ba0d6de9074eff5455613ee8..5ccfe4b64cdfe49b7a8c1c71b98445e62839f6da 100644 (file)
@@ -145,7 +145,20 @@ static bool is_libpfm_event_supported(const char *name, struct perf_cpu_map *cpu
 
        evsel->is_libpfm_event = true;
 
-       if (evsel__open(evsel, cpus, threads) < 0)
+       ret = evsel__open(evsel, cpus, threads);
+       if (ret == -EACCES) {
+               /*
+                * This happens if the paranoid value
+                * /proc/sys/kernel/perf_event_paranoid is set to 2
+                * Re-run with exclude_kernel set; we don't do that
+                * by default as some ARM machines do not support it.
+                *
+                */
+               evsel->core.attr.exclude_kernel = 1;
+               ret = evsel__open(evsel, cpus, threads);
+
+       }
+       if (ret < 0)
                result = false;
 
        evsel__close(evsel);