perf parse-events: Set is_pmu_core for legacy hardware events
authorIan Rogers <irogers@google.com>
Thu, 3 Apr 2025 19:43:36 +0000 (12:43 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 May 2025 17:18:16 +0000 (14:18 -0300)
Also set the CPU map to all online CPU maps.

This is done so the behavior of legacy hardware and hardware cache
events better matches that of sysfs and JSON events during
__perf_evlist__propagate_maps().

Fix missing cpumap put in "Synthesize attr update" test.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Link: https://lore.kernel.org/r/20250403194337.40202-4-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c

index 7297ca3a4eec18925f64c3cf7bf73387b12361f3..cf4f9b59a18524dd1d551c11a89bd595911011ca 100644 (file)
@@ -233,21 +233,30 @@ __add_event(struct list_head *list, int *idx,
            struct perf_cpu_map *cpu_list, u64 alternate_hw_config)
 {
        struct evsel *evsel;
-       struct perf_cpu_map *cpus = perf_cpu_map__is_empty(cpu_list) && pmu ? pmu->cpus : cpu_list;
+       bool is_pmu_core;
+       struct perf_cpu_map *cpus;
 
-       cpus = perf_cpu_map__get(cpus);
-       if (pmu)
+       if (pmu) {
+               is_pmu_core = pmu->is_core;
+               cpus = perf_cpu_map__get(perf_cpu_map__is_empty(cpu_list) ? pmu->cpus : cpu_list);
                perf_pmu__warn_invalid_formats(pmu);
-
-       if (pmu && (attr->type == PERF_TYPE_RAW || attr->type >= PERF_TYPE_MAX)) {
-               perf_pmu__warn_invalid_config(pmu, attr->config, name,
-                                             PERF_PMU_FORMAT_VALUE_CONFIG, "config");
-               perf_pmu__warn_invalid_config(pmu, attr->config1, name,
-                                             PERF_PMU_FORMAT_VALUE_CONFIG1, "config1");
-               perf_pmu__warn_invalid_config(pmu, attr->config2, name,
-                                             PERF_PMU_FORMAT_VALUE_CONFIG2, "config2");
-               perf_pmu__warn_invalid_config(pmu, attr->config3, name,
-                                             PERF_PMU_FORMAT_VALUE_CONFIG3, "config3");
+               if (attr->type == PERF_TYPE_RAW || attr->type >= PERF_TYPE_MAX) {
+                       perf_pmu__warn_invalid_config(pmu, attr->config, name,
+                                               PERF_PMU_FORMAT_VALUE_CONFIG, "config");
+                       perf_pmu__warn_invalid_config(pmu, attr->config1, name,
+                                               PERF_PMU_FORMAT_VALUE_CONFIG1, "config1");
+                       perf_pmu__warn_invalid_config(pmu, attr->config2, name,
+                                               PERF_PMU_FORMAT_VALUE_CONFIG2, "config2");
+                       perf_pmu__warn_invalid_config(pmu, attr->config3, name,
+                                               PERF_PMU_FORMAT_VALUE_CONFIG3, "config3");
+               }
+       } else {
+               is_pmu_core = (attr->type == PERF_TYPE_HARDWARE ||
+                              attr->type == PERF_TYPE_HW_CACHE);
+               if (perf_cpu_map__is_empty(cpu_list))
+                       cpus = is_pmu_core ? perf_cpu_map__new_online_cpus() : NULL;
+               else
+                       cpus = perf_cpu_map__get(cpu_list);
        }
        if (init_attr)
                event_attr_init(attr);
@@ -262,7 +271,7 @@ __add_event(struct list_head *list, int *idx,
        evsel->core.cpus = cpus;
        evsel->core.own_cpus = perf_cpu_map__get(cpus);
        evsel->core.requires_cpu = pmu ? pmu->is_uncore : false;
-       evsel->core.is_pmu_core = pmu ? pmu->is_core : false;
+       evsel->core.is_pmu_core = is_pmu_core;
        evsel->auto_merge_stats = auto_merge_stats;
        evsel->pmu = pmu;
        evsel->alternate_hw_config = alternate_hw_config;