* [PATCH v2 0/1] perf: Add --pmu-filter option for filtering PMUs
@ 2026-03-10 4:06 Qinxin Xia
2026-03-10 4:06 ` [PATCH v2 1/1] " Qinxin Xia
2026-03-27 21:01 ` [PATCH v2 0/1] " Namhyung Kim
0 siblings, 2 replies; 8+ messages in thread
From: Qinxin Xia @ 2026-03-10 4:06 UTC (permalink / raw)
To: namhyung, irogers, peterz, mingo, acme, wangyushan12, hejunhao3,
jonathan.cameron, xiaqinxin
Cc: linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin,
jolsa, adrian.hunter, james.clark, linuxarm
This patch adds a new --pmu-filter option to perf-stat command to allow
filtering events on specific PMUs. This is useful when there are
multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0).
[root@localhost tmp]# perf stat -M cpa_p0_avg_bw
Performance counter stats for 'system wide':
19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw
0 hisi_sicl0_cpa0/cpa_p0_wr_dat/
0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/
19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw
0 hisi_sicl10_cpa0/cpa_p0_wr_dat/
0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/
19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw
75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/
18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/
19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw
0 hisi_sicl8_cpa0/cpa_p0_wr_dat/
0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/
19.417734480 seconds time elapsed
[root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw
Performance counter stats for 'system wide':
6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw
50,548,465 cpa_p0_wr_dat
7,552,182 cpa_p0_rd_dat_64b
0 cpa_p0_rd_dat_32b
6.234139320 seconds time elapsed
wildcard match:
[root@localhost ~]# ./perf stat --pmu-filter hisi_sicl[2,8]_cpa0 -M cpa_p0_avg_bw
Performance counter stats for 'system wide':
18,505,025,031 hisi_sicl2_cpa0/cpa_cycles/ # 0.42 cpa_p0_avg_bw
80,007,944 hisi_sicl2_cpa0/cpa_p0_wr_dat/
42,014,906 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/
18,504,957,351 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw
0 hisi_sicl8_cpa0/cpa_p0_wr_dat/
0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/
0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/
18.504994880 seconds time elapsed
Changes since V1:
- Address the comments from Namhyung, the description of the event filter in commit
info is omitted, and wildcard matching is supported for pmu-filter.
- Link: https://lore.kernel.org/all/20260225034125.2157622-2-xiaqinxin@huawei.com/
Changes since RFC:
- Address the comments from Ian, replace '--uncorepmu' with '--pmu-filter'.
- Link: https://lore.kernel.org/linux-perf-users/20260120095058.2778834-1-xiaqinxin@huawei.com/
Qinxin Xia (1):
perf: Add --pmu-filter option for filtering PMUs
tools/perf/Documentation/perf-stat.txt | 4 ++++
tools/perf/builtin-stat.c | 19 +++++++++++++++++++
tools/perf/util/metricgroup.c | 18 +++++++++++++-----
tools/perf/util/parse-events.c | 2 +-
4 files changed, 37 insertions(+), 6 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-10 4:06 [PATCH v2 0/1] perf: Add --pmu-filter option for filtering PMUs Qinxin Xia @ 2026-03-10 4:06 ` Qinxin Xia 2026-03-12 18:07 ` Namhyung Kim 2026-03-27 21:01 ` [PATCH v2 0/1] " Namhyung Kim 1 sibling, 1 reply; 8+ messages in thread From: Qinxin Xia @ 2026-03-10 4:06 UTC (permalink / raw) To: namhyung, irogers, peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, xiaqinxin Cc: linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm This patch adds a new --pmu-filter option to perf-stat command to allow filtering events on specific PMUs. This is useful when there are multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). [root@localhost tmp]# perf stat -M cpa_p0_avg_bw Performance counter stats for 'system wide': 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ 19.417734480 seconds time elapsed [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw Performance counter stats for 'system wide': 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw 50,548,465 cpa_p0_wr_dat 7,552,182 cpa_p0_rd_dat_64b 0 cpa_p0_rd_dat_32b 6.234139320 seconds time elapsed Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> --- tools/perf/Documentation/perf-stat.txt | 4 ++++ tools/perf/builtin-stat.c | 19 +++++++++++++++++++ tools/perf/util/metricgroup.c | 18 +++++++++++++----- tools/perf/util/parse-events.c | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt index 7cccc3a847d1..b72a29c9223c 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)" +--pmu-filter:: +Only enable events on applying pmu with specified for multiple +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) + EXAMPLES -------- diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 73c2ba7e3076..69c83a5beb71 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, return 0; } +static int parse_pmu_filter(const struct option *opt, + const char *str, + int unset __maybe_unused) +{ + struct evlist *evlist = *(struct evlist **)opt->value; + + if (!list_empty(&evlist->core.entries)) { + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); + return -1; + } + + parse_events_option_args.pmu_filter = str; + return 0; +} + static int parse_cache_level(const struct option *opt, const char *str, int unset __maybe_unused) @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) "Only enable events on applying cpu with this type " "for hybrid platform (e.g. core or atom)", parse_cputype), + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", + "Only enable events on applying pmu with specified " + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", + parse_pmu_filter), #ifdef HAVE_LIBPFM OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", "libpfm4 event selector. use 'perf list' to list available events", diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 46bf4dfeebc8..89b83ca38483 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p const char *metric_or_groups) { const char *pm_pmu = pm->pmu ?: "cpu"; + struct perf_pmu *perf_pmu = NULL; - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) + if (pm->pmu) + perf_pmu = perf_pmus__find(pm->pmu); + + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) return false; return match_metric_or_groups(pm->metric_group, metric_or_groups) || @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, static int parse_ids(bool metric_no_merge, bool fake_pmu, struct expr_parse_ctx *ids, const char *modifier, bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], - struct evlist **out_evlist) + struct evlist **out_evlist, + const char *filter_pmu) { struct parse_events_error parse_error; struct evlist *parsed_evlist; @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, } pr_debug("Parsing metric events '%s'\n", events.buf); parse_events_error__init(&parse_error); - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, &parse_error, fake_pmu, /*warn_if_reordered=*/false, /*fake_tp=*/false); if (ret) { @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, /*modifier=*/NULL, /*group_events=*/false, tool_events, - &combined_evlist); + &combined_evlist, + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); } if (combined) expr__ctx_free(combined); @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, } if (!metric_evlist) { ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, - m->group_events, tool_events, &m->evlist); + m->group_events, tool_events, &m->evlist, + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); if (ret) goto out; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b9efb296bba5..789ff4d15e47 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, if (parse_state->pmu_filter == NULL) return false; - return strcmp(parse_state->pmu_filter, pmu->name) != 0; + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; } static int parse_events_add_pmu(struct parse_events_state *parse_state, -- 2.33.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-10 4:06 ` [PATCH v2 1/1] " Qinxin Xia @ 2026-03-12 18:07 ` Namhyung Kim 2026-03-19 10:23 ` Qinxin Xia 0 siblings, 1 reply; 8+ messages in thread From: Namhyung Kim @ 2026-03-12 18:07 UTC (permalink / raw) To: Qinxin Xia, irogers Cc: peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On Tue, Mar 10, 2026 at 12:06:07PM +0800, Qinxin Xia wrote: > This patch adds a new --pmu-filter option to perf-stat command to allow > filtering events on specific PMUs. This is useful when there are > multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). > > [root@localhost tmp]# perf stat -M cpa_p0_avg_bw > Performance counter stats for 'system wide': > > 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ > 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ > 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ > 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ > 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ > 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ > 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw > 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ > 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ > 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ > 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ > 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ > 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ > > 19.417734480 seconds time elapsed > > [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw > Performance counter stats for 'system wide': > > 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw > 50,548,465 cpa_p0_wr_dat > 7,552,182 cpa_p0_rd_dat_64b > 0 cpa_p0_rd_dat_32b > > 6.234139320 seconds time elapsed Ian, can you please take a look at this? Thanks, Namhyung > > Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> > --- > tools/perf/Documentation/perf-stat.txt | 4 ++++ > tools/perf/builtin-stat.c | 19 +++++++++++++++++++ > tools/perf/util/metricgroup.c | 18 +++++++++++++----- > tools/perf/util/parse-events.c | 2 +- > 4 files changed, 37 insertions(+), 6 deletions(-) > > diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt > index 7cccc3a847d1..b72a29c9223c 100644 > --- a/tools/perf/Documentation/perf-stat.txt > +++ b/tools/perf/Documentation/perf-stat.txt > @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true > Only enable events on applying cpu with this type for hybrid platform > (e.g. core or atom)" > > +--pmu-filter:: > +Only enable events on applying pmu with specified for multiple > +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) > + > EXAMPLES > -------- > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > index 73c2ba7e3076..69c83a5beb71 100644 > --- a/tools/perf/builtin-stat.c > +++ b/tools/perf/builtin-stat.c > @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, > return 0; > } > > +static int parse_pmu_filter(const struct option *opt, > + const char *str, > + int unset __maybe_unused) > +{ > + struct evlist *evlist = *(struct evlist **)opt->value; > + > + if (!list_empty(&evlist->core.entries)) { > + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); > + return -1; > + } > + > + parse_events_option_args.pmu_filter = str; > + return 0; > +} > + > static int parse_cache_level(const struct option *opt, > const char *str, > int unset __maybe_unused) > @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) > "Only enable events on applying cpu with this type " > "for hybrid platform (e.g. core or atom)", > parse_cputype), > + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", > + "Only enable events on applying pmu with specified " > + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", > + parse_pmu_filter), > #ifdef HAVE_LIBPFM > OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", > "libpfm4 event selector. use 'perf list' to list available events", > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > index 46bf4dfeebc8..89b83ca38483 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p > const char *metric_or_groups) > { > const char *pm_pmu = pm->pmu ?: "cpu"; > + struct perf_pmu *perf_pmu = NULL; > > - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) > + if (pm->pmu) > + perf_pmu = perf_pmus__find(pm->pmu); > + > + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && > + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) > return false; > > return match_metric_or_groups(pm->metric_group, metric_or_groups) || > @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, > static int parse_ids(bool metric_no_merge, bool fake_pmu, > struct expr_parse_ctx *ids, const char *modifier, > bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], > - struct evlist **out_evlist) > + struct evlist **out_evlist, > + const char *filter_pmu) > { > struct parse_events_error parse_error; > struct evlist *parsed_evlist; > @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, > } > pr_debug("Parsing metric events '%s'\n", events.buf); > parse_events_error__init(&parse_error); > - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, > + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, > &parse_error, fake_pmu, /*warn_if_reordered=*/false, > /*fake_tp=*/false); > if (ret) { > @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, > /*modifier=*/NULL, > /*group_events=*/false, > tool_events, > - &combined_evlist); > + &combined_evlist, > + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > } > if (combined) > expr__ctx_free(combined); > @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, > } > if (!metric_evlist) { > ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, > - m->group_events, tool_events, &m->evlist); > + m->group_events, tool_events, &m->evlist, > + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > if (ret) > goto out; > > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > index b9efb296bba5..789ff4d15e47 100644 > --- a/tools/perf/util/parse-events.c > +++ b/tools/perf/util/parse-events.c > @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, > if (parse_state->pmu_filter == NULL) > return false; > > - return strcmp(parse_state->pmu_filter, pmu->name) != 0; > + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; > } > > static int parse_events_add_pmu(struct parse_events_state *parse_state, > -- > 2.33.0 > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-12 18:07 ` Namhyung Kim @ 2026-03-19 10:23 ` Qinxin Xia 2026-03-20 22:56 ` Ian Rogers 0 siblings, 1 reply; 8+ messages in thread From: Qinxin Xia @ 2026-03-19 10:23 UTC (permalink / raw) To: Namhyung Kim, irogers Cc: peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On 2026/3/13 02:07:17, Namhyung Kim <namhyung@kernel.org> wrote: > On Tue, Mar 10, 2026 at 12:06:07PM +0800, Qinxin Xia wrote: >> This patch adds a new --pmu-filter option to perf-stat command to allow >> filtering events on specific PMUs. This is useful when there are >> multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). >> >> [root@localhost tmp]# perf stat -M cpa_p0_avg_bw >> Performance counter stats for 'system wide': >> >> 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >> 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ >> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ >> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ >> 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >> 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ >> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ >> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ >> 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw >> 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ >> 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ >> 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ >> 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >> 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ >> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ >> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ >> >> 19.417734480 seconds time elapsed >> >> [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw >> Performance counter stats for 'system wide': >> >> 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw >> 50,548,465 cpa_p0_wr_dat >> 7,552,182 cpa_p0_rd_dat_64b >> 0 cpa_p0_rd_dat_32b >> >> 6.234139320 seconds time elapsed > > Ian, can you please take a look at this? > > Thanks, > Namhyung > >> >> Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> >> --- >> tools/perf/Documentation/perf-stat.txt | 4 ++++ >> tools/perf/builtin-stat.c | 19 +++++++++++++++++++ >> tools/perf/util/metricgroup.c | 18 +++++++++++++----- >> tools/perf/util/parse-events.c | 2 +- >> 4 files changed, 37 insertions(+), 6 deletions(-) >> >> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt >> index 7cccc3a847d1..b72a29c9223c 100644 >> --- a/tools/perf/Documentation/perf-stat.txt >> +++ b/tools/perf/Documentation/perf-stat.txt >> @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true >> Only enable events on applying cpu with this type for hybrid platform >> (e.g. core or atom)" >> >> +--pmu-filter:: >> +Only enable events on applying pmu with specified for multiple >> +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) >> + >> EXAMPLES >> -------- >> >> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c >> index 73c2ba7e3076..69c83a5beb71 100644 >> --- a/tools/perf/builtin-stat.c >> +++ b/tools/perf/builtin-stat.c >> @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, >> return 0; >> } >> >> +static int parse_pmu_filter(const struct option *opt, >> + const char *str, >> + int unset __maybe_unused) >> +{ >> + struct evlist *evlist = *(struct evlist **)opt->value; >> + >> + if (!list_empty(&evlist->core.entries)) { >> + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); >> + return -1; >> + } >> + >> + parse_events_option_args.pmu_filter = str; >> + return 0; >> +} >> + >> static int parse_cache_level(const struct option *opt, >> const char *str, >> int unset __maybe_unused) >> @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) >> "Only enable events on applying cpu with this type " >> "for hybrid platform (e.g. core or atom)", >> parse_cputype), >> + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", >> + "Only enable events on applying pmu with specified " >> + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", >> + parse_pmu_filter), >> #ifdef HAVE_LIBPFM >> OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", >> "libpfm4 event selector. use 'perf list' to list available events", >> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c >> index 46bf4dfeebc8..89b83ca38483 100644 >> --- a/tools/perf/util/metricgroup.c >> +++ b/tools/perf/util/metricgroup.c >> @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p >> const char *metric_or_groups) >> { >> const char *pm_pmu = pm->pmu ?: "cpu"; >> + struct perf_pmu *perf_pmu = NULL; >> >> - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) >> + if (pm->pmu) >> + perf_pmu = perf_pmus__find(pm->pmu); >> + >> + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && >> + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) >> return false; >> >> return match_metric_or_groups(pm->metric_group, metric_or_groups) || >> @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, >> static int parse_ids(bool metric_no_merge, bool fake_pmu, >> struct expr_parse_ctx *ids, const char *modifier, >> bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], >> - struct evlist **out_evlist) >> + struct evlist **out_evlist, >> + const char *filter_pmu) >> { >> struct parse_events_error parse_error; >> struct evlist *parsed_evlist; >> @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, >> } >> pr_debug("Parsing metric events '%s'\n", events.buf); >> parse_events_error__init(&parse_error); >> - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, >> + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, >> &parse_error, fake_pmu, /*warn_if_reordered=*/false, >> /*fake_tp=*/false); >> if (ret) { >> @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, >> /*modifier=*/NULL, >> /*group_events=*/false, >> tool_events, >> - &combined_evlist); >> + &combined_evlist, >> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); >> } >> if (combined) >> expr__ctx_free(combined); >> @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, >> } >> if (!metric_evlist) { >> ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, >> - m->group_events, tool_events, &m->evlist); >> + m->group_events, tool_events, &m->evlist, >> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); >> if (ret) >> goto out; >> >> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c >> index b9efb296bba5..789ff4d15e47 100644 >> --- a/tools/perf/util/parse-events.c >> +++ b/tools/perf/util/parse-events.c >> @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, >> if (parse_state->pmu_filter == NULL) >> return false; >> >> - return strcmp(parse_state->pmu_filter, pmu->name) != 0; >> + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; >> } >> >> static int parse_events_add_pmu(struct parse_events_state *parse_state, >> -- >> 2.33.0 >> > Gentle ping. -- Thanks, Qinxin ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-19 10:23 ` Qinxin Xia @ 2026-03-20 22:56 ` Ian Rogers 2026-03-27 6:40 ` Qinxin Xia 0 siblings, 1 reply; 8+ messages in thread From: Ian Rogers @ 2026-03-20 22:56 UTC (permalink / raw) To: Qinxin Xia Cc: Namhyung Kim, peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On Thu, Mar 19, 2026 at 3:23 AM Qinxin Xia <xiaqinxin@huawei.com> wrote: > > > On 2026/3/13 02:07:17, Namhyung Kim <namhyung@kernel.org> wrote: > > On Tue, Mar 10, 2026 at 12:06:07PM +0800, Qinxin Xia wrote: > >> This patch adds a new --pmu-filter option to perf-stat command to allow > >> filtering events on specific PMUs. This is useful when there are > >> multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). > >> > >> [root@localhost tmp]# perf stat -M cpa_p0_avg_bw > >> Performance counter stats for 'system wide': > >> > >> 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >> 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ > >> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ > >> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ > >> 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >> 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ > >> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ > >> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ > >> 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw > >> 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ > >> 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ > >> 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ > >> 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >> 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ > >> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ > >> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ > >> > >> 19.417734480 seconds time elapsed > >> > >> [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw > >> Performance counter stats for 'system wide': > >> > >> 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw > >> 50,548,465 cpa_p0_wr_dat > >> 7,552,182 cpa_p0_rd_dat_64b > >> 0 cpa_p0_rd_dat_32b > >> > >> 6.234139320 seconds time elapsed > > > > Ian, can you please take a look at this? > > > > Thanks, > > Namhyung > > > >> > >> Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> Sorry for the delay. Reviewed-by: Ian Rogers <irogers@google.com> Thanks, Ian > >> --- > >> tools/perf/Documentation/perf-stat.txt | 4 ++++ > >> tools/perf/builtin-stat.c | 19 +++++++++++++++++++ > >> tools/perf/util/metricgroup.c | 18 +++++++++++++----- > >> tools/perf/util/parse-events.c | 2 +- > >> 4 files changed, 37 insertions(+), 6 deletions(-) > >> > >> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt > >> index 7cccc3a847d1..b72a29c9223c 100644 > >> --- a/tools/perf/Documentation/perf-stat.txt > >> +++ b/tools/perf/Documentation/perf-stat.txt > >> @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true > >> Only enable events on applying cpu with this type for hybrid platform > >> (e.g. core or atom)" > >> > >> +--pmu-filter:: > >> +Only enable events on applying pmu with specified for multiple > >> +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) > >> + > >> EXAMPLES > >> -------- > >> > >> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > >> index 73c2ba7e3076..69c83a5beb71 100644 > >> --- a/tools/perf/builtin-stat.c > >> +++ b/tools/perf/builtin-stat.c > >> @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, > >> return 0; > >> } > >> > >> +static int parse_pmu_filter(const struct option *opt, > >> + const char *str, > >> + int unset __maybe_unused) > >> +{ > >> + struct evlist *evlist = *(struct evlist **)opt->value; > >> + > >> + if (!list_empty(&evlist->core.entries)) { > >> + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); > >> + return -1; > >> + } > >> + > >> + parse_events_option_args.pmu_filter = str; > >> + return 0; > >> +} > >> + > >> static int parse_cache_level(const struct option *opt, > >> const char *str, > >> int unset __maybe_unused) > >> @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) > >> "Only enable events on applying cpu with this type " > >> "for hybrid platform (e.g. core or atom)", > >> parse_cputype), > >> + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", > >> + "Only enable events on applying pmu with specified " > >> + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", > >> + parse_pmu_filter), > >> #ifdef HAVE_LIBPFM > >> OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", > >> "libpfm4 event selector. use 'perf list' to list available events", > >> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > >> index 46bf4dfeebc8..89b83ca38483 100644 > >> --- a/tools/perf/util/metricgroup.c > >> +++ b/tools/perf/util/metricgroup.c > >> @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p > >> const char *metric_or_groups) > >> { > >> const char *pm_pmu = pm->pmu ?: "cpu"; > >> + struct perf_pmu *perf_pmu = NULL; > >> > >> - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) > >> + if (pm->pmu) > >> + perf_pmu = perf_pmus__find(pm->pmu); > >> + > >> + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && > >> + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) > >> return false; > >> > >> return match_metric_or_groups(pm->metric_group, metric_or_groups) || > >> @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, > >> static int parse_ids(bool metric_no_merge, bool fake_pmu, > >> struct expr_parse_ctx *ids, const char *modifier, > >> bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], > >> - struct evlist **out_evlist) > >> + struct evlist **out_evlist, > >> + const char *filter_pmu) > >> { > >> struct parse_events_error parse_error; > >> struct evlist *parsed_evlist; > >> @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, > >> } > >> pr_debug("Parsing metric events '%s'\n", events.buf); > >> parse_events_error__init(&parse_error); > >> - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, > >> + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, > >> &parse_error, fake_pmu, /*warn_if_reordered=*/false, > >> /*fake_tp=*/false); > >> if (ret) { > >> @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, > >> /*modifier=*/NULL, > >> /*group_events=*/false, > >> tool_events, > >> - &combined_evlist); > >> + &combined_evlist, > >> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > >> } > >> if (combined) > >> expr__ctx_free(combined); > >> @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, > >> } > >> if (!metric_evlist) { > >> ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, > >> - m->group_events, tool_events, &m->evlist); > >> + m->group_events, tool_events, &m->evlist, > >> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > >> if (ret) > >> goto out; > >> > >> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > >> index b9efb296bba5..789ff4d15e47 100644 > >> --- a/tools/perf/util/parse-events.c > >> +++ b/tools/perf/util/parse-events.c > >> @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, > >> if (parse_state->pmu_filter == NULL) > >> return false; > >> > >> - return strcmp(parse_state->pmu_filter, pmu->name) != 0; > >> + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; > >> } > >> > >> static int parse_events_add_pmu(struct parse_events_state *parse_state, > >> -- > >> 2.33.0 > >> > > > > Gentle ping. > -- > Thanks, > Qinxin > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-20 22:56 ` Ian Rogers @ 2026-03-27 6:40 ` Qinxin Xia 2026-03-27 6:52 ` Ian Rogers 0 siblings, 1 reply; 8+ messages in thread From: Qinxin Xia @ 2026-03-27 6:40 UTC (permalink / raw) To: Namhyung Kim Cc: Ian Rogers, peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On 2026/3/21 06:56:07, Ian Rogers <irogers@google.com> wrote: > On Thu, Mar 19, 2026 at 3:23 AM Qinxin Xia <xiaqinxin@huawei.com> wrote: >> >> >> On 2026/3/13 02:07:17, Namhyung Kim <namhyung@kernel.org> wrote: >>> On Tue, Mar 10, 2026 at 12:06:07PM +0800, Qinxin Xia wrote: >>>> This patch adds a new --pmu-filter option to perf-stat command to allow >>>> filtering events on specific PMUs. This is useful when there are >>>> multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). >>>> >>>> [root@localhost tmp]# perf stat -M cpa_p0_avg_bw >>>> Performance counter stats for 'system wide': >>>> >>>> 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >>>> 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ >>>> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ >>>> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ >>>> 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >>>> 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ >>>> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ >>>> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ >>>> 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw >>>> 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ >>>> 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ >>>> 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ >>>> 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw >>>> 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ >>>> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ >>>> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ >>>> >>>> 19.417734480 seconds time elapsed >>>> >>>> [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw >>>> Performance counter stats for 'system wide': >>>> >>>> 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw >>>> 50,548,465 cpa_p0_wr_dat >>>> 7,552,182 cpa_p0_rd_dat_64b >>>> 0 cpa_p0_rd_dat_32b >>>> >>>> 6.234139320 seconds time elapsed >>> >>> Ian, can you please take a look at this? >>> >>> Thanks, >>> Namhyung >>> >>>> >>>> Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> > > Sorry for the delay. > > Reviewed-by: Ian Rogers <irogers@google.com> > > Thanks, > Ian > Hi Namhyung! Ian has already provided Reviewed-by. Could you please apply this patch if everything looks good to you? :-) -- Thanks, Qinxin >>>> --- >>>> tools/perf/Documentation/perf-stat.txt | 4 ++++ >>>> tools/perf/builtin-stat.c | 19 +++++++++++++++++++ >>>> tools/perf/util/metricgroup.c | 18 +++++++++++++----- >>>> tools/perf/util/parse-events.c | 2 +- >>>> 4 files changed, 37 insertions(+), 6 deletions(-) >>>> >>>> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt >>>> index 7cccc3a847d1..b72a29c9223c 100644 >>>> --- a/tools/perf/Documentation/perf-stat.txt >>>> +++ b/tools/perf/Documentation/perf-stat.txt >>>> @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true >>>> Only enable events on applying cpu with this type for hybrid platform >>>> (e.g. core or atom)" >>>> >>>> +--pmu-filter:: >>>> +Only enable events on applying pmu with specified for multiple >>>> +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) >>>> + >>>> EXAMPLES >>>> -------- >>>> >>>> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c >>>> index 73c2ba7e3076..69c83a5beb71 100644 >>>> --- a/tools/perf/builtin-stat.c >>>> +++ b/tools/perf/builtin-stat.c >>>> @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, >>>> return 0; >>>> } >>>> >>>> +static int parse_pmu_filter(const struct option *opt, >>>> + const char *str, >>>> + int unset __maybe_unused) >>>> +{ >>>> + struct evlist *evlist = *(struct evlist **)opt->value; >>>> + >>>> + if (!list_empty(&evlist->core.entries)) { >>>> + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); >>>> + return -1; >>>> + } >>>> + >>>> + parse_events_option_args.pmu_filter = str; >>>> + return 0; >>>> +} >>>> + >>>> static int parse_cache_level(const struct option *opt, >>>> const char *str, >>>> int unset __maybe_unused) >>>> @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) >>>> "Only enable events on applying cpu with this type " >>>> "for hybrid platform (e.g. core or atom)", >>>> parse_cputype), >>>> + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", >>>> + "Only enable events on applying pmu with specified " >>>> + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", >>>> + parse_pmu_filter), >>>> #ifdef HAVE_LIBPFM >>>> OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", >>>> "libpfm4 event selector. use 'perf list' to list available events", >>>> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c >>>> index 46bf4dfeebc8..89b83ca38483 100644 >>>> --- a/tools/perf/util/metricgroup.c >>>> +++ b/tools/perf/util/metricgroup.c >>>> @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p >>>> const char *metric_or_groups) >>>> { >>>> const char *pm_pmu = pm->pmu ?: "cpu"; >>>> + struct perf_pmu *perf_pmu = NULL; >>>> >>>> - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) >>>> + if (pm->pmu) >>>> + perf_pmu = perf_pmus__find(pm->pmu); >>>> + >>>> + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && >>>> + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) >>>> return false; >>>> >>>> return match_metric_or_groups(pm->metric_group, metric_or_groups) || >>>> @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, >>>> static int parse_ids(bool metric_no_merge, bool fake_pmu, >>>> struct expr_parse_ctx *ids, const char *modifier, >>>> bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], >>>> - struct evlist **out_evlist) >>>> + struct evlist **out_evlist, >>>> + const char *filter_pmu) >>>> { >>>> struct parse_events_error parse_error; >>>> struct evlist *parsed_evlist; >>>> @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, >>>> } >>>> pr_debug("Parsing metric events '%s'\n", events.buf); >>>> parse_events_error__init(&parse_error); >>>> - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, >>>> + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, >>>> &parse_error, fake_pmu, /*warn_if_reordered=*/false, >>>> /*fake_tp=*/false); >>>> if (ret) { >>>> @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, >>>> /*modifier=*/NULL, >>>> /*group_events=*/false, >>>> tool_events, >>>> - &combined_evlist); >>>> + &combined_evlist, >>>> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); >>>> } >>>> if (combined) >>>> expr__ctx_free(combined); >>>> @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, >>>> } >>>> if (!metric_evlist) { >>>> ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, >>>> - m->group_events, tool_events, &m->evlist); >>>> + m->group_events, tool_events, &m->evlist, >>>> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); >>>> if (ret) >>>> goto out; >>>> >>>> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c >>>> index b9efb296bba5..789ff4d15e47 100644 >>>> --- a/tools/perf/util/parse-events.c >>>> +++ b/tools/perf/util/parse-events.c >>>> @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, >>>> if (parse_state->pmu_filter == NULL) >>>> return false; >>>> >>>> - return strcmp(parse_state->pmu_filter, pmu->name) != 0; >>>> + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; >>>> } >>>> >>>> static int parse_events_add_pmu(struct parse_events_state *parse_state, >>>> -- >>>> 2.33.0 >>>> >>> >> >> Gentle ping. >> -- >> Thanks, >> Qinxin >> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 1/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-27 6:40 ` Qinxin Xia @ 2026-03-27 6:52 ` Ian Rogers 0 siblings, 0 replies; 8+ messages in thread From: Ian Rogers @ 2026-03-27 6:52 UTC (permalink / raw) To: Qinxin Xia Cc: Namhyung Kim, peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On Thu, Mar 26, 2026 at 11:41 PM Qinxin Xia <xiaqinxin@huawei.com> wrote: > > > > On 2026/3/21 06:56:07, Ian Rogers <irogers@google.com> wrote: > > On Thu, Mar 19, 2026 at 3:23 AM Qinxin Xia <xiaqinxin@huawei.com> wrote: > >> > >> > >> On 2026/3/13 02:07:17, Namhyung Kim <namhyung@kernel.org> wrote: > >>> On Tue, Mar 10, 2026 at 12:06:07PM +0800, Qinxin Xia wrote: > >>>> This patch adds a new --pmu-filter option to perf-stat command to allow > >>>> filtering events on specific PMUs. This is useful when there are > >>>> multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). > >>>> > >>>> [root@localhost tmp]# perf stat -M cpa_p0_avg_bw > >>>> Performance counter stats for 'system wide': > >>>> > >>>> 19,417,779,115 hisi_sicl0_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >>>> 0 hisi_sicl0_cpa0/cpa_p0_wr_dat/ > >>>> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_64b/ > >>>> 0 hisi_sicl0_cpa0/cpa_p0_rd_dat_32b/ > >>>> 19,417,751,103 hisi_sicl10_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >>>> 0 hisi_sicl10_cpa0/cpa_p0_wr_dat/ > >>>> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_64b/ > >>>> 0 hisi_sicl10_cpa0/cpa_p0_rd_dat_32b/ > >>>> 19,417,730,679 hisi_sicl2_cpa0/cpa_cycles/ # 0.31 cpa_p0_avg_bw > >>>> 75,635,749 hisi_sicl2_cpa0/cpa_p0_wr_dat/ > >>>> 18,520,640 hisi_sicl2_cpa0/cpa_p0_rd_dat_64b/ > >>>> 0 hisi_sicl2_cpa0/cpa_p0_rd_dat_32b/ > >>>> 19,417,674,227 hisi_sicl8_cpa0/cpa_cycles/ # 0.00 cpa_p0_avg_bw > >>>> 0 hisi_sicl8_cpa0/cpa_p0_wr_dat/ > >>>> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_64b/ > >>>> 0 hisi_sicl8_cpa0/cpa_p0_rd_dat_32b/ > >>>> > >>>> 19.417734480 seconds time elapsed > >>>> > >>>> [root@localhost tmp]# perf stat --pmu-filter hisi_sicl2_cpa0 -M cpa_p0_avg_bw > >>>> Performance counter stats for 'system wide': > >>>> > >>>> 6,234,093,559 cpa_cycles # 0.60 cpa_p0_avg_bw > >>>> 50,548,465 cpa_p0_wr_dat > >>>> 7,552,182 cpa_p0_rd_dat_64b > >>>> 0 cpa_p0_rd_dat_32b > >>>> > >>>> 6.234139320 seconds time elapsed > >>> > >>> Ian, can you please take a look at this? > >>> > >>> Thanks, > >>> Namhyung > >>> > >>>> > >>>> Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com> > > > > Sorry for the delay. > > > > Reviewed-by: Ian Rogers <irogers@google.com> > > > > Thanks, > > Ian > > > > Hi Namhyung! > > Ian has already provided Reviewed-by. Could you please apply this > patch if everything looks good to you? :-) > > -- > Thanks, > Qinxin Hi Qinxin, I see it queued up on tmp.perf-tools-next: https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/log/?h=tmp.perf-tools-next which is where patches are tested prior to landing in perf-tools-next :-) Thanks, Ian > >>>> --- > >>>> tools/perf/Documentation/perf-stat.txt | 4 ++++ > >>>> tools/perf/builtin-stat.c | 19 +++++++++++++++++++ > >>>> tools/perf/util/metricgroup.c | 18 +++++++++++++----- > >>>> tools/perf/util/parse-events.c | 2 +- > >>>> 4 files changed, 37 insertions(+), 6 deletions(-) > >>>> > >>>> diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt > >>>> index 7cccc3a847d1..b72a29c9223c 100644 > >>>> --- a/tools/perf/Documentation/perf-stat.txt > >>>> +++ b/tools/perf/Documentation/perf-stat.txt > >>>> @@ -578,6 +578,10 @@ $ perf config stat.no-csv-summary=true > >>>> Only enable events on applying cpu with this type for hybrid platform > >>>> (e.g. core or atom)" > >>>> > >>>> +--pmu-filter:: > >>>> +Only enable events on applying pmu with specified for multiple > >>>> +pmus with same type (e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0) > >>>> + > >>>> EXAMPLES > >>>> -------- > >>>> > >>>> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > >>>> index 73c2ba7e3076..69c83a5beb71 100644 > >>>> --- a/tools/perf/builtin-stat.c > >>>> +++ b/tools/perf/builtin-stat.c > >>>> @@ -1214,6 +1214,21 @@ static int parse_cputype(const struct option *opt, > >>>> return 0; > >>>> } > >>>> > >>>> +static int parse_pmu_filter(const struct option *opt, > >>>> + const char *str, > >>>> + int unset __maybe_unused) > >>>> +{ > >>>> + struct evlist *evlist = *(struct evlist **)opt->value; > >>>> + > >>>> + if (!list_empty(&evlist->core.entries)) { > >>>> + fprintf(stderr, "Must define pmu-filter before events/metrics\n"); > >>>> + return -1; > >>>> + } > >>>> + > >>>> + parse_events_option_args.pmu_filter = str; > >>>> + return 0; > >>>> +} > >>>> + > >>>> static int parse_cache_level(const struct option *opt, > >>>> const char *str, > >>>> int unset __maybe_unused) > >>>> @@ -2561,6 +2576,10 @@ int cmd_stat(int argc, const char **argv) > >>>> "Only enable events on applying cpu with this type " > >>>> "for hybrid platform (e.g. core or atom)", > >>>> parse_cputype), > >>>> + OPT_CALLBACK(0, "pmu-filter", &evsel_list, "pmu", > >>>> + "Only enable events on applying pmu with specified " > >>>> + "for multiple pmus with same type(e.g. hisi_sicl2_cpa0 or hisi_sicl0_cpa0)", > >>>> + parse_pmu_filter), > >>>> #ifdef HAVE_LIBPFM > >>>> OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", > >>>> "libpfm4 event selector. use 'perf list' to list available events", > >>>> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > >>>> index 46bf4dfeebc8..89b83ca38483 100644 > >>>> --- a/tools/perf/util/metricgroup.c > >>>> +++ b/tools/perf/util/metricgroup.c > >>>> @@ -387,8 +387,13 @@ static bool match_pm_metric_or_groups(const struct pmu_metric *pm, const char *p > >>>> const char *metric_or_groups) > >>>> { > >>>> const char *pm_pmu = pm->pmu ?: "cpu"; > >>>> + struct perf_pmu *perf_pmu = NULL; > >>>> > >>>> - if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu)) > >>>> + if (pm->pmu) > >>>> + perf_pmu = perf_pmus__find(pm->pmu); > >>>> + > >>>> + if (strcmp(pmu, "all") && strcmp(pm_pmu, pmu) && > >>>> + (perf_pmu && !perf_pmu__name_wildcard_match(perf_pmu, pmu))) > >>>> return false; > >>>> > >>>> return match_metric_or_groups(pm->metric_group, metric_or_groups) || > >>>> @@ -1259,7 +1264,8 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, > >>>> static int parse_ids(bool metric_no_merge, bool fake_pmu, > >>>> struct expr_parse_ctx *ids, const char *modifier, > >>>> bool group_events, const bool tool_events[TOOL_PMU__EVENT_MAX], > >>>> - struct evlist **out_evlist) > >>>> + struct evlist **out_evlist, > >>>> + const char *filter_pmu) > >>>> { > >>>> struct parse_events_error parse_error; > >>>> struct evlist *parsed_evlist; > >>>> @@ -1313,7 +1319,7 @@ static int parse_ids(bool metric_no_merge, bool fake_pmu, > >>>> } > >>>> pr_debug("Parsing metric events '%s'\n", events.buf); > >>>> parse_events_error__init(&parse_error); > >>>> - ret = __parse_events(parsed_evlist, events.buf, /*pmu_filter=*/NULL, > >>>> + ret = __parse_events(parsed_evlist, events.buf, filter_pmu, > >>>> &parse_error, fake_pmu, /*warn_if_reordered=*/false, > >>>> /*fake_tp=*/false); > >>>> if (ret) { > >>>> @@ -1416,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, > >>>> /*modifier=*/NULL, > >>>> /*group_events=*/false, > >>>> tool_events, > >>>> - &combined_evlist); > >>>> + &combined_evlist, > >>>> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > >>>> } > >>>> if (combined) > >>>> expr__ctx_free(combined); > >>>> @@ -1471,7 +1478,8 @@ static int parse_groups(struct evlist *perf_evlist, > >>>> } > >>>> if (!metric_evlist) { > >>>> ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, > >>>> - m->group_events, tool_events, &m->evlist); > >>>> + m->group_events, tool_events, &m->evlist, > >>>> + (pmu && strcmp(pmu, "all") == 0) ? NULL : pmu); > >>>> if (ret) > >>>> goto out; > >>>> > >>>> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c > >>>> index b9efb296bba5..789ff4d15e47 100644 > >>>> --- a/tools/perf/util/parse-events.c > >>>> +++ b/tools/perf/util/parse-events.c > >>>> @@ -429,7 +429,7 @@ bool parse_events__filter_pmu(const struct parse_events_state *parse_state, > >>>> if (parse_state->pmu_filter == NULL) > >>>> return false; > >>>> > >>>> - return strcmp(parse_state->pmu_filter, pmu->name) != 0; > >>>> + return perf_pmu__wildcard_match(pmu, parse_state->pmu_filter) == 0; > >>>> } > >>>> > >>>> static int parse_events_add_pmu(struct parse_events_state *parse_state, > >>>> -- > >>>> 2.33.0 > >>>> > >>> > >> > >> Gentle ping. > >> -- > >> Thanks, > >> Qinxin > >> ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/1] perf: Add --pmu-filter option for filtering PMUs 2026-03-10 4:06 [PATCH v2 0/1] perf: Add --pmu-filter option for filtering PMUs Qinxin Xia 2026-03-10 4:06 ` [PATCH v2 1/1] " Qinxin Xia @ 2026-03-27 21:01 ` Namhyung Kim 1 sibling, 0 replies; 8+ messages in thread From: Namhyung Kim @ 2026-03-27 21:01 UTC (permalink / raw) To: irogers, peterz, mingo, acme, wangyushan12, hejunhao3, jonathan.cameron, Qinxin Xia Cc: linux-perf-users, linux-kernel, mark.rutland, alexander.shishkin, jolsa, adrian.hunter, james.clark, linuxarm On Tue, 10 Mar 2026 12:06:06 +0800, Qinxin Xia wrote: > This patch adds a new --pmu-filter option to perf-stat command to allow > filtering events on specific PMUs. This is useful when there are > multiple PMUs with same type (e.g. hisi_sicl2_cpa0 and hisi_sicl0_cpa0). > > [root@localhost tmp]# perf stat -M cpa_p0_avg_bw > Performance counter stats for 'system wide': > > [...] Applied to perf-tools-next, thanks! Best regards, Namhyung ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-03-27 21:01 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-10 4:06 [PATCH v2 0/1] perf: Add --pmu-filter option for filtering PMUs Qinxin Xia 2026-03-10 4:06 ` [PATCH v2 1/1] " Qinxin Xia 2026-03-12 18:07 ` Namhyung Kim 2026-03-19 10:23 ` Qinxin Xia 2026-03-20 22:56 ` Ian Rogers 2026-03-27 6:40 ` Qinxin Xia 2026-03-27 6:52 ` Ian Rogers 2026-03-27 21:01 ` [PATCH v2 0/1] " Namhyung Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox