[PATCH v4 09/21] perf evsel: Don't dump probe events to PERF_TEST_ATTR
From: Arnaldo Carvalho de Melo
Date: Fri Oct 16 2026 - 17:22:53 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Events opened just to ask if they are supported, i.e. the ones in
is_event_supported() and is_libpfm_event_supported(), go through the
regular evsel__open() path and thus end up in the event files written to
$PERF_TEST_ATTR, with everything but type, config and disabled zeroed:
[event-0-38654705664-3]
fd=3
cpu=-1
pid=0
type=0
size=0
config=38654705664
sample_type=0
...
which 'perf test attr' then takes as one of the events that were asked
for, failing with:
expected cpu=0, got -1
expected size=176, got 0
expected sample_type=65927, got 0
expected freq=1, got 0
This started showing up when there is more than one core PMU, as
perf_pmus__supports_extended_type() probes one such event per core PMU,
but these records were always bogus: nothing asked for them.
Flag those evsels as support probes, keeping the name clear of the
kprobe/uprobe meaning probe already has in evsel, and leave them out of
the dump.
Reported-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Link: https://lore.kernel.org/linux-perf-users/asWQvXRdqp_RK85c@xxxxxxxxxx/
Assisted-by: LLM
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/evsel.c | 6 +++++-
tools/perf/util/evsel.h | 1 +
tools/perf/util/pfm.c | 1 +
tools/perf/util/print-events.c | 1 +
4 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index e61f309e93dccc7f..59318fef03cb17ff 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -3104,7 +3104,11 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
bpf_counter__install_pe(evsel, idx, fd);
- if (unlikely(test_attr__enabled())) {
+ /*
+ * Support probes aren't what was asked for, leave them
+ * out of the PERF_TEST_ATTR dump.
+ */
+ if (unlikely(test_attr__enabled() && !evsel->support_probe)) {
test_attr__open(&evsel->core.attr, pid, cpu,
fd, group_fd, evsel->open_flags);
}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 174f3414fd3cfa0d..53f3641b66e18674 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -120,6 +120,7 @@ struct evsel {
u64 db_id;
bool uniquified_name;
bool supported;
+ bool support_probe; /* Opened just to check for support. */
bool needs_swap;
bool disabled;
bool no_aux_samples;
diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c
index f80d6b0df47ae64d..ad9bc481da70604e 100644
--- a/tools/perf/util/pfm.c
+++ b/tools/perf/util/pfm.c
@@ -141,6 +141,7 @@ static bool is_libpfm_event_supported(const char *name, struct perf_cpu_map *cpu
return false;
evsel->is_libpfm_event = true;
+ evsel->support_probe = true;
ret = evsel__open(evsel, cpus, threads);
if (ret == -EACCES) {
diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c
index 0242243681b6b6f9..77428d9e73c4f1b6 100644
--- a/tools/perf/util/print-events.c
+++ b/tools/perf/util/print-events.c
@@ -147,6 +147,7 @@ bool is_event_supported(u8 type, u64 config)
evsel = evsel__new(&attr);
if (evsel) {
+ evsel->support_probe = true;
ret = evsel__open(evsel, NULL, tmap) >= 0;
if (!ret) {
--
2.55.0