[PATCH v1 03/13] libperf evlist: Recompute CPU map when an evsel goes system wide
From: Ian Rogers
Date: Mon Nov 23 2026 - 02:19:41 EST
perf_evlist__go_system_wide() marks the evsel as system wide and then
propagates the evlist's maps to it. __perf_evlist__propagate_maps()
only assigns the PMU CPUs to evsel->cpus if the map is empty, but an
evsel added after the evlist's maps were created already has the user
requested CPUs propagated (e.g. the "any CPU" map of -1 in per-thread
or workload mode). Going system wide then leaves the evsel opened on
the wrong CPUs.
Drop the existing CPU map before propagating so the evsel is given all
of its PMU's CPUs, as is expected for a system wide event. Propagate the
maps of all evsels, rather than just the one going system wide, so that
evlist->all_cpus is rebuilt. Otherwise the evsel's previous CPUs, such
as the "any CPU" -1, remain in evlist->all_cpus and may cause per-thread
rather than per-CPU mmaps to be used.
Fixes: 811082e4b668 ("perf parse-events: Support user CPUs mixed with threads/processes")
Reviewed-by: James Clark <james.clark@xxxxxxxxxx>
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/lib/perf/evlist.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c
index c1c5b0684eed..c6ce56b46ac1 100644
--- a/tools/lib/perf/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -835,7 +835,15 @@ void perf_evlist__go_system_wide(struct perf_evlist *evlist, struct perf_evsel *
{
if (!evsel->system_wide) {
evsel->system_wide = true;
- if (evlist->needs_map_propagation)
- __perf_evlist__propagate_maps(evlist, evsel);
+ if (evlist->needs_map_propagation) {
+ perf_cpu_map__put(evsel->cpus);
+ evsel->cpus = NULL;
+ /*
+ * Propagate the maps of all evsels, rather than just
+ * this one, so that evlist->all_cpus is rebuilt and
+ * doesn't retain this evsel's previous CPUs.
+ */
+ perf_evlist__propagate_maps(evlist);
+ }
}
}
--
2.56.1.750.gf70dc682cf-goog