[PATCH v1 2/2] perf list pfm: Retry supported test with exclude_kernel

From: Ian Rogers
Date: Wed Sep 06 2023 - 19:44:33 EST


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@xxxxxxxxxx>
---
tools/perf/util/pfm.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c
index 862e4a689868..5ccfe4b64cdf 100644
--- a/tools/perf/util/pfm.c
+++ b/tools/perf/util/pfm.c
@@ -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);
--
2.42.0.283.g2d96d420d3-goog