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

From: Ian Rogers
Date: Tue May 02 2023 - 16:17:08 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.
>
> 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.
>
> 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
>
> 3. Also, IMHO, using --cputype option to specify _pmu name_ is bit odd.
>
> >
> > 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
>
>
> > @@ -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.

Ok, these changes are just keeping existing functionality. I don't
disagree with making these changes but I think we can follow up with
them. Or probably just deprecate the option.

> > +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.

It is trying to be consistent with the event parser:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/parse-events.y#n326
where uncore is consumed. Fun fact, as numbers are consumed after a
PMU name and the underscore is optional, i915 as a PMU can be matched
in parsing with a PMU name of just "i".

Thanks,
Ian