[RFT PATCH 5/7] perf-iostat: Support wilder wildcard-match for pmus

Yushan Wang wangyushan12 at huawei.com
Mon Jan 26 04:35:12 PST 2026


Current wildcard matching of pmu names only support the form of
"<pmu_name>%d", which may not be sufficient for pmus with other forms of
name (e.g. HiSilicon PCIe PMU has the name of "hisi_pcie%d_pmu%d").

To address that, change the wildcard matching function into a callback,
and add a new version of wildcard-matching function using the callback
to support more flexible pmu names.

Signed-off-by: Yushan Wang <wangyushan12 at huawei.com>
---
 tools/perf/util/pmus.c | 12 +++++++++---
 tools/perf/util/pmus.h |  3 +++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index 98be2eb8f1f0..35184d477d07 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -402,7 +402,8 @@ struct perf_pmu *perf_pmus__scan_for_event(struct perf_pmu *pmu, const char *eve
 	return NULL;
 }
 
-struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const char *wildcard)
+struct perf_pmu *perf_pmus__scan_matching(struct perf_pmu *pmu, const char *wildcard,
+					  perf_pmus_match_t match)
 {
 	bool use_core_pmus = !pmu || pmu->is_core;
 
@@ -436,19 +437,24 @@ struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const c
 	}
 	if (use_core_pmus) {
 		list_for_each_entry_continue(pmu, &core_pmus, list) {
-			if (perf_pmu__wildcard_match(pmu, wildcard))
+			if (match(pmu, wildcard))
 				return pmu;
 		}
 		pmu = NULL;
 		pmu = list_prepare_entry(pmu, &other_pmus, list);
 	}
 	list_for_each_entry_continue(pmu, &other_pmus, list) {
-		if (perf_pmu__wildcard_match(pmu, wildcard))
+		if (match(pmu, wildcard))
 			return pmu;
 	}
 	return NULL;
 }
 
+struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const char *wildcard)
+{
+	return perf_pmus__scan_matching(pmu, wildcard, perf_pmu__wildcard_match);
+}
+
 static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
 {
 	bool use_core_pmus = !pmu || pmu->is_core;
diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h
index 7cb36863711a..9308afb5a7b8 100644
--- a/tools/perf/util/pmus.h
+++ b/tools/perf/util/pmus.h
@@ -9,6 +9,8 @@ struct perf_event_attr;
 struct perf_pmu;
 struct print_callbacks;
 
+typedef _Bool (*perf_pmus_match_t)(const struct perf_pmu *, const char *);
+
 size_t pmu_name_len_no_suffix(const char *str);
 /* Exposed for testing only. */
 int pmu_name_cmp(const char *lhs_pmu_name, const char *rhs_pmu_name);
@@ -22,6 +24,7 @@ struct perf_pmu *perf_pmus__find_by_attr(const struct perf_event_attr *attr);
 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(struct perf_pmu *pmu, const char *wildcard, perf_pmus_match_t match);
 struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const char *wildcard);
 
 const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str);
-- 
2.33.0




More information about the linux-arm-kernel mailing list