Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf evsel x86: Make evsel__has_perf_metrics work for legacy events

Use PMU interface to better detect core PMU for legacy events. Look
for slots event on core PMU if it is appropriate for the event.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Cc: Yang Jihong <yangjihong@bytedance.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Yunseong Kim <yskelg@gmail.com>
Cc: Ze Gao <zegao2021@gmail.com>
Cc: Yicong Yang <yangyicong@hisilicon.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: ak@linux.intel.com
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20240926144851.245903-5-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
e2216fac d38461e9

+28 -6
+26 -5
tools/perf/arch/x86/util/evsel.c
··· 21 21 /* Check whether the evsel's PMU supports the perf metrics */ 22 22 bool evsel__sys_has_perf_metrics(const struct evsel *evsel) 23 23 { 24 - const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu"; 24 + struct perf_pmu *pmu; 25 + u32 type = evsel->core.attr.type; 25 26 26 27 /* 27 28 * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU ··· 32 31 * Checking both the PERF_TYPE_RAW type and the slots event 33 32 * should be good enough to detect the perf metrics feature. 34 33 */ 35 - if ((evsel->core.attr.type == PERF_TYPE_RAW) && 36 - perf_pmus__have_event(pmu_name, "slots")) 37 - return true; 34 + again: 35 + switch (type) { 36 + case PERF_TYPE_HARDWARE: 37 + case PERF_TYPE_HW_CACHE: 38 + type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; 39 + if (type) 40 + goto again; 41 + break; 42 + case PERF_TYPE_RAW: 43 + break; 44 + default: 45 + return false; 46 + } 38 47 39 - return false; 48 + pmu = evsel->pmu; 49 + if (pmu && perf_pmu__is_fake(pmu)) 50 + pmu = NULL; 51 + 52 + if (!pmu) { 53 + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { 54 + if (pmu->type == PERF_TYPE_RAW) 55 + break; 56 + } 57 + } 58 + return pmu && perf_pmu__have_event(pmu, "slots"); 40 59 } 41 60 42 61 bool arch_evsel__must_be_in_group(const struct evsel *evsel)
+1 -1
tools/perf/util/pmu.c
··· 1168 1168 return pmu; 1169 1169 } 1170 1170 1171 - static bool perf_pmu__is_fake(const struct perf_pmu *pmu) 1171 + bool perf_pmu__is_fake(const struct perf_pmu *pmu) 1172 1172 { 1173 1173 return pmu->type == PERF_PMU_TYPE_FAKE; 1174 1174 }
+1
tools/perf/util/pmu.h
··· 281 281 void perf_pmu__delete(struct perf_pmu *pmu); 282 282 struct perf_pmu *perf_pmus__find_core_pmu(void); 283 283 const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config); 284 + bool perf_pmu__is_fake(const struct perf_pmu *pmu); 284 285 285 286 #endif /* __PMU_H */