perf pmu: Use available core PMU for raw events
authorNamhyung Kim <namhyung@kernel.org>
Wed, 7 May 2025 21:59:39 +0000 (14:59 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 9 May 2025 17:44:44 +0000 (14:44 -0300)
When it finds a matching PMU for a legacy event, it should look for
core PMUs.  The raw events also refers to core events so it should be
handled similarly.

On x86, PERF_TYPE_RAW should match with the existing cpu PMU.  But on
ARM, there's no PMU with the matching type so it'll pick the first core
PMU for it.

Suggested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250507215939.54399-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/pmus.c

index b99292de76693dbb79dcdc596104de686b9867b1..3bbd26fec78a10e2b08149d62545fceefaf7858f 100644 (file)
@@ -727,14 +727,21 @@ struct perf_pmu *evsel__find_pmu(const struct evsel *evsel)
        legacy_core_type =
                evsel->core.attr.type == PERF_TYPE_HARDWARE ||
                evsel->core.attr.type == PERF_TYPE_HW_CACHE;
-       if (!pmu && legacy_core_type) {
-               if (perf_pmus__supports_extended_type()) {
-                       u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
+       if (!pmu && legacy_core_type && perf_pmus__supports_extended_type()) {
+               u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
 
-                       pmu = perf_pmus__find_by_type(type);
-               } else {
-                       pmu = perf_pmus__find_core_pmu();
-               }
+               pmu = perf_pmus__find_by_type(type);
+       }
+       if (!pmu && (legacy_core_type || evsel->core.attr.type == PERF_TYPE_RAW)) {
+               /*
+                * For legacy events, if there was no extended type info then
+                * assume the PMU is the first core PMU.
+                *
+                * On architectures like ARM there is no sysfs PMU with type
+                * PERF_TYPE_RAW, assume the RAW events are going to be handled
+                * by the first core PMU.
+                */
+               pmu = perf_pmus__find_core_pmu();
        }
        ((struct evsel *)evsel)->pmu = pmu;
        return pmu;