]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf metricgroup: Avoid scanning unnecessary PMUs for identifier match
authorIan Rogers <irogers@google.com>
Thu, 30 Apr 2026 16:17:25 +0000 (09:17 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 14 May 2026 23:59:08 +0000 (20:59 -0300)
Only uncore PMUs can have an identifier, so add an optimized
perf_pmus__scan routine for that case to avoid all PMU types being
created.

Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Leo Yan <leo.yan@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/metricgroup.c
tools/perf/util/pmus.c
tools/perf/util/pmus.h

index 4db9578efd811cf91d192cc13fb757cf5aab21f7..5a489e97c4130474aeedeb48cedab3f9ef0d43c4 100644 (file)
@@ -415,14 +415,9 @@ static int metricgroup__sys_event_iter(const struct pmu_metric *pm,
        if (!pm->metric_expr || !pm->compat)
                return 0;
 
-       while ((pmu = perf_pmus__scan(pmu))) {
-
-               if (!pmu->id || !pmu_uncore_identifier_match(pm->compat, pmu->id))
-                       continue;
-
-               return d->fn(pm, table, d->data);
-       }
-       return 0;
+       /* Only process with the iterator if there is a a PMU that matches the ID. */
+       pmu = perf_pmus__scan_for_uncore_id(pmu, pm->compat);
+       return pmu ? d->fn(pm, table, d->data) : 0;
 }
 
 int metricgroup__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn,
index 9a2023ceeefd933a960976a5de723e2016fea060..5e3f571450fe7fa519f40ab55f5e39900daed654 100644 (file)
@@ -409,7 +409,7 @@ struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const c
        if (!pmu) {
                /*
                 * Core PMUs, other sysfs PMUs and tool PMU can have any name or
-                * aren't wother optimizing for.
+                * aren't worth optimizing for.
                 */
                unsigned int to_read_pmus =  PERF_TOOL_PMU_TYPE_PE_CORE_MASK |
                        PERF_TOOL_PMU_TYPE_PE_OTHER_MASK |
@@ -486,6 +486,22 @@ static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
        return NULL;
 }
 
+struct perf_pmu *perf_pmus__scan_for_uncore_id(struct perf_pmu *pmu, const char *compat)
+{
+       if (!pmu) {
+               /* Only uncore PMUs can have identifiers. */
+               unsigned int to_read_pmus = PERF_TOOL_PMU_TYPE_PE_OTHER_MASK;
+
+               pmu_read_sysfs(to_read_pmus);
+               pmu = list_prepare_entry(pmu, &other_pmus, list);
+       }
+       list_for_each_entry_continue(pmu, &other_pmus, list) {
+               if (pmu->id && pmu_uncore_identifier_match(compat, pmu->id))
+                       return pmu;
+       }
+       return NULL;
+}
+
 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str)
 {
        struct perf_pmu *pmu = NULL;
index 7cb36863711a6e08f182ab730bda36f9500b66dc..0d55edb3f2fc311ad9d0f3a79f8a5ea3a2753eec 100644 (file)
@@ -23,6 +23,7 @@ struct perf_pmu *perf_pmus__scan(struct perf_pmu *pmu);
 struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu);
 struct perf_pmu *perf_pmus__scan_for_event(struct perf_pmu *pmu, const char *event);
 struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const char *wildcard);
+struct perf_pmu *perf_pmus__scan_for_uncore_id(struct perf_pmu *pmu, const char *compat);
 
 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str);