]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
perf evsel x86: Make evsel__has_perf_metrics work for legacy events
authorIan Rogers <irogers@google.com>
Thu, 26 Sep 2024 14:48:35 +0000 (15:48 +0100)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 26 Sep 2024 20:26:11 +0000 (13:26 -0700)
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>
tools/perf/arch/x86/util/evsel.c
tools/perf/util/pmu.c
tools/perf/util/pmu.h

index 090d0f371891f5499bf3304b8aa07dce6073aff8..ec2ac3bbb76f2cb1cc21fa409e21d8ca2e222490 100644 (file)
@@ -21,7 +21,8 @@ void arch_evsel__set_sample_weight(struct evsel *evsel)
 /* Check whether the evsel's PMU supports the perf metrics */
 bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
 {
-       const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu";
+       struct perf_pmu *pmu;
+       u32 type = evsel->core.attr.type;
 
        /*
         * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU
@@ -31,11 +32,31 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evsel)
         * Checking both the PERF_TYPE_RAW type and the slots event
         * should be good enough to detect the perf metrics feature.
         */
-       if ((evsel->core.attr.type == PERF_TYPE_RAW) &&
-           perf_pmus__have_event(pmu_name, "slots"))
-               return true;
+again:
+       switch (type) {
+       case PERF_TYPE_HARDWARE:
+       case PERF_TYPE_HW_CACHE:
+               type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT;
+               if (type)
+                       goto again;
+               break;
+       case PERF_TYPE_RAW:
+               break;
+       default:
+               return false;
+       }
+
+       pmu = evsel->pmu;
+       if (pmu && perf_pmu__is_fake(pmu))
+               pmu = NULL;
 
-       return false;
+       if (!pmu) {
+               while ((pmu = perf_pmus__scan_core(pmu)) != NULL) {
+                       if (pmu->type == PERF_TYPE_RAW)
+                               break;
+               }
+       }
+       return pmu && perf_pmu__have_event(pmu, "slots");
 }
 
 bool arch_evsel__must_be_in_group(const struct evsel *evsel)
index e32d601b48f1ed74d8b49a7586ee2b7b16b99851..8993b5853687b1db29c91f764fc5ded5070503f9 100644 (file)
@@ -1168,7 +1168,7 @@ struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pm
        return pmu;
 }
 
-static bool perf_pmu__is_fake(const struct perf_pmu *pmu)
+bool perf_pmu__is_fake(const struct perf_pmu *pmu)
 {
        return pmu->type == PERF_PMU_TYPE_FAKE;
 }
index f4271395c374453e21edd2ecec8abad64e4d05d4..d352d53b8d55c284e06274dde1a61f9ead8d8d2b 100644 (file)
@@ -281,5 +281,6 @@ struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pm
 void perf_pmu__delete(struct perf_pmu *pmu);
 struct perf_pmu *perf_pmus__find_core_pmu(void);
 const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config);
+bool perf_pmu__is_fake(const struct perf_pmu *pmu);
 
 #endif /* __PMU_H */