Re: [PATCH v3 32/46] perf stat: Make cputype filter generic

From: Ian Rogers
Date: Tue May 02 2023 - 16:09:58 EST


On Tue, May 2, 2023 at 3:52 AM Ravi Bangoria <ravi.bangoria@xxxxxxx> wrote:
>
> On 29-Apr-23 11:04 AM, Ian Rogers wrote:
> > Rather than limit the --cputype argument for "perf list" and "perf
> > stat" to hybrid PMUs of just cpu_atom and cpu_core, allow any PMU.
>
> I've couple of doubts:
>
> 1. Can you please explain intention to do this esp for perf list. Since, IIUC,
> `perf list --unit` option provide the same functionality.

I agree with you. The option already exists and I think we should just
move this option to being deprecated/hidden:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/subcmd/parse-options.h#n46

> 2. Since we are already specifying pmu name for non-standerd/arch-specific
> events like `pmu/attributes/`, I'm not sure where `perf stat --cputype=pmu`
> is useful. Can you please explain perf stat usability aspect for non-hybrid
> pmus.

Completely agreed. This patch series is trying to remove the
duplicated code introduced by the hybrid changes. In this case I
didn't want to remove an option, and potentially break users of that
option, as part of fixing things up. A lot of what you are saying here
I added as comments to the original patch series.

> 3. What am I missing here:
>
> $ sudo ./perf stat --cputype=amd_df -e amd_l3/event=0x4,umask=0xff/ -C 0 -- sleep 1
> Performance counter stats for 'CPU(s) 0':
>
> 108,267 amd_l3/event=0x4,umask=0xff/
>
> 1.061290167 seconds time elapsed

The cputype applies to wildcard-ed events. So on hybrid:
$ perf stat -e cycles true
will open cycles on cpu_atom and cpu_core, the
parse_events__filter_pmu function is used skip PMUs based on cputype.

> 3. Also, IMHO, using --cputype option to specify _pmu name_ is bit odd.

Right, when the "feature" was added I would have preferred it as PMU
rather than CPU.

> >
> > Note, that if cpu_atom isn't mounted but a filter of cpu_atom is
> > requested, then this will now fail. As such a filter would never
> > succeed, no events can come from that unmounted PMU, then this
> > behavior could never have been useful and failing is clearer.
>
> I'm hitting a segfault if I use non-existing pmu:
>
> $ sudo ./perf list --cputype=random
> WARNING: cputype is not supported!
> Segmentation fault

Will fix in v4. The warning should be fatal/exit rather than try to
read the PMU's name.

Thanks,
Ian

> > @@ -443,8 +443,8 @@ int cmd_list(int argc, const char **argv)
> > "Print information on the perf event names and expressions used internally by events."),
> > OPT_BOOLEAN(0, "deprecated", &default_ps.deprecated,
> > "Print deprecated events."),
> > - OPT_STRING(0, "cputype", &hybrid_name, "hybrid cpu type",
> > - "Limit PMU or metric printing to the given hybrid PMU (e.g. core or atom)."),
> > + OPT_STRING(0, "cputype", &cputype, "cpu type",
> > + "Limit PMU or metric printing to the given PMU (e.g. cpu, core or atom)."),
>
> man perf-list does not describe --cputype. I think we should add it as part
> of this patch?
>
> Similarly, man perf-stat also needs to be updated.
>
>
> > +const struct perf_pmu *perf_pmus__pmu_for_pmu_filter(const char *str)
> > +{
> > + struct perf_pmu *pmu = NULL;
> > +
> > + while ((pmu = perf_pmu__scan(pmu)) != NULL) {
> > + if (!strcmp(pmu->name, str))
> > + return pmu;
> > + /* Ignore "uncore_" prefix. */
> > + if (!strncmp(pmu->name, "uncore_", 7)) {
> > + if (!strcmp(pmu->name + 7, str))
> > + return pmu;
>
> Any specific reason to ignore "uncore_"? IMHO, ignoring prefix of some
> pmus and not of others is bit confusing for naive user.