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

From: Ravi Bangoria
Date: Tue May 02 2023 - 06:52:30 EST


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.


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