Re: [PATCH v1 02/10] perf parse-events filter: Use evsel__find_pmu

From: Ian Rogers
Date: Wed Feb 12 2025 - 11:11:34 EST


On Wed, Feb 12, 2025 at 6:51 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> On Sat, Jan 11, 2025 at 11:01:35AM -0800, Ian Rogers wrote:
> > Rather than manually scanning PMUs, use evsel__find_pmu that can use
> > the PMU set during event parsing.
>
> Right, and then evsel__find_pmu() also does some extra checks to call
> pmu_read_sysfs() more selectively, right?

Right, but the pmu should already be initialized by parse_events so no
scanning should be necessary:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmus.c?h=perf-tools-next#n759
You are right that the fall back to perf_pmus__find_by_type is more
selective in what it scans:
https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmus.c?h=perf-tools-next#n302
First seeing if the PMU is already loaded then just loading the PMUs
relevant to the type number.

Thanks,
Ian

> - Arnaldo
>
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > tools/perf/util/parse-events.c | 14 ++++----------
> > 1 file changed, 4 insertions(+), 10 deletions(-)
> >
> > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> > index 1e23faa364b1..f147e13a7017 100644
> > --- a/tools/perf/util/parse-events.c
> > +++ b/tools/perf/util/parse-events.c
> > @@ -2406,9 +2406,8 @@ foreach_evsel_in_last_glob(struct evlist *evlist,
> > static int set_filter(struct evsel *evsel, const void *arg)
> > {
> > const char *str = arg;
> > - bool found = false;
> > int nr_addr_filters = 0;
> > - struct perf_pmu *pmu = NULL;
> > + struct perf_pmu *pmu;
> >
> > if (evsel == NULL) {
> > fprintf(stderr,
> > @@ -2426,16 +2425,11 @@ static int set_filter(struct evsel *evsel, const void *arg)
> > return 0;
> > }
> >
> > - while ((pmu = perf_pmus__scan(pmu)) != NULL)
> > - if (pmu->type == evsel->core.attr.type) {
> > - found = true;
> > - break;
> > - }
> > -
> > - if (found)
> > + pmu = evsel__find_pmu(evsel);
> > + if (pmu) {
> > perf_pmu__scan_file(pmu, "nr_addr_filters",
> > "%d", &nr_addr_filters);
> > -
> > + }
> > if (!nr_addr_filters)
> > return perf_bpf_filter__parse(&evsel->bpf_filters, str);
> >
> > --
> > 2.47.1.613.gc27f4b7a9f-goog