[RFT PATCH 5/7] perf-iostat: Support wilder wildcard-match for pmus
wangyushan
wangyushan12 at huawei.com
Thu Jan 29 07:14:30 PST 2026
On 1/27/2026 12:44 AM, Ian Rogers wrote:
> On Mon, Jan 26, 2026 at 4:35 AM Yushan Wang <wangyushan12 at huawei.com> wrote:
>> 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.
> There's some discussion around PMU name matching here (and the replies):
> https://lore.kernel.org/lkml/20251231224233.113839-12-zide.chen@intel.com/
> that I think is relevant.
The complexity of name matching is sad. Do you think it's a good idea to add a callback for specific use? Maybe the wildcard matching needs more complete split, that extracts the match logic of core and uncore pmus into individual functions?
>> 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 *);
> nit: can we use stdbool.h and make this return a bool?
> nit: in general Linux style is to avoid typedefs:
> https://www.kernel.org/doc/html/v4.10/process/coding-style.html#typedefs
Yes, thanks for pointing out, I will fix them.
>
> Thanks,
> Ian
Thanks,
Yushan
>
>> +
>> 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