From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Leo Yan <leo.yan@arm.com>,
Thomas Falcon <thomas.falcon@intel.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf metricgroup: Avoid scanning unnecessary PMUs for identifier match
Date: Tue, 31 Mar 2026 20:51:35 -0700 [thread overview]
Message-ID: <acyWR2GAWIY7TKyD@google.com> (raw)
In-Reply-To: <CAP-5=fVOtY8NYQnhwgyexyjDN+W4Vf2Yo+_Tm6chZSfYFx-OMQ@mail.gmail.com>
On Tue, Mar 31, 2026 at 07:05:58AM -0700, Ian Rogers wrote:
> On Mon, Mar 30, 2026 at 11:30 PM Namhyung Kim <namhyung@kernel.org> wrote:
> >
> > On Mon, Mar 30, 2026 at 03:44:21PM +0100, James Clark wrote:
> > >
> > >
> > > On 26/03/2026 10:44 pm, Ian Rogers wrote:
> > > > 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.
> > > >
> > > > Signed-off-by: Ian Rogers <irogers@google.com>
> > >
> > > Reviewed-by: James Clark <james.clark@linaro.org>
> > >
> > > > ---
> > > > tools/perf/util/metricgroup.c | 8 ++------
> > > > tools/perf/util/pmus.c | 18 +++++++++++++++++-
> > > > tools/perf/util/pmus.h | 1 +
> > > > 3 files changed, 20 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> > > > index 7e39d469111b..769b38400832 100644
> > > > --- a/tools/perf/util/metricgroup.c
> > > > +++ b/tools/perf/util/metricgroup.c
> > > > @@ -410,13 +410,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;
> > > > -
> > > > + while ((pmu = perf_pmus__scan_for_uncore_id(pmu, pm->compat)))
> > > > return d->fn(pm, table, d->data);
> >
> > Sashiko review: it's natural to convert it to 'if'.
>
> Yeah, I saw and disagreed. The pattern with the "while ((pmu =
> perf_pmus__scan...(pmu)))" functions is for them to be a while loop.
> With an "if" it would read:
> ```
> pmu = perf_pmus__scan...(pmu);
> if (pmu)
> return ...
> ```
> and we lose the consistency of having while loops in the code.
I understand it's a pattern to scan PMUs but having an unused
variable assignment in a while loop with a return statement seems
unnatural and maybe someone would send a patch for it later.
At least we can add a comment saying it's intended?
Thanks,
Namhyung
next prev parent reply other threads:[~2026-04-01 3:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 22:44 [PATCH v1] perf metricgroup: Avoid scanning unnecessary PMUs for identifier match Ian Rogers
2026-03-30 14:44 ` James Clark
2026-03-31 6:30 ` Namhyung Kim
2026-03-31 14:05 ` Ian Rogers
2026-04-01 3:51 ` Namhyung Kim [this message]
2026-04-30 16:17 ` [PATCH v2] " Ian Rogers
2026-05-05 21:24 ` Ian Rogers
2026-05-06 9:12 ` James Clark
2026-05-14 17:39 ` Ian Rogers
2026-05-14 23:58 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=acyWR2GAWIY7TKyD@google.com \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=thomas.falcon@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.