All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 02/11] perf pmu: Add metric and metricgroup storage on struct perf_pmu
Date: Fri, 04 Dec 2026 01:26:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-248892@kernel.org> (raw)
In-Reply-To: <20261204011029.1946921-3-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] perf pmu: uncached per-PMU regex scan in
  perf_pmu__lookup_metrics_table()
- [Medium] perf pmu: wrong-core metrics fallback in
  perf_pmu__lookup_metrics_table()
- [Medium] perf pmu: placeholder core PMU attaches JSON events without
  sysfs formats
--

commit 5a14155933e78303fc11c12ec836f00df5969bd3
Author: Ian Rogers <irogers@google.com>

perf pmu: Add metric and metricgroup storage on struct perf_pmu

This commit adds metric and metricgroup hashmaps and a metrics_table
pointer to struct perf_pmu, populates them during PMU initialization and
lookup, and frees them in perf_pmu__delete().

> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index c5ab6c6881990..261eaf75b01fe 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c

[ ... ]

> @@ -1354,6 +1562,33 @@ static bool aliases__equal(long key1, long key2, void *ctx __maybe_unused)

[ ... ]

> +static const struct pmu_metrics_table *perf_pmu__lookup_metrics_table(struct perf_pmu *pmu)
> +{
> +	const struct pmu_metrics_table *table = NULL;
> +	const char *arch = perf_env__arch(NULL);
> +	struct perf_cpu cpu = pmu ? perf_cpu_map__min(pmu->cpus) : (struct perf_cpu){ -1 };
> +	char *cpuid = get_cpuid_allow_env_override(cpu);
> +
> +	if (cpuid) {
> +		if (arch)
> +			table = find_core_metrics_table(arch, cpuid);
> +		free(cpuid);
> +	}
> +	if (!table)
> +		table = pmu_metrics_table__find();
> +	return table;
> +}

[Severity: Medium]
Can the fallback to pmu_metrics_table__find() attach the wrong CPU's
metrics table to an unrecognized heterogeneous core PMU?

When find_core_metrics_table() returns NULL for a valid per-PMU CPUID,
pmu_metrics_table__find() calls map_for_cpu() with cpu = -1.  On arm64,
get_cpuid() then returns CPU 0's MIDR, so an unrecognized core PMU
inherits CPU 0's metrics table instead of NULL.

[ ... ]

> @@ -1443,6 +1692,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
>  	pmu->max_precise = pmu_max_precise(dirfd, pmu);
>  	pmu->alias_name = pmu_find_alias_name(pmu, dirfd);
>  	pmu->events_table = perf_pmu__find_events_table(pmu);
> +	pmu->metrics_table = perf_pmu__lookup_metrics_table(pmu);

[Severity: Medium]
Does calling perf_pmu__lookup_metrics_table() here regress PMU scan
startup time?

Unlike perf_pmu__find_events_table(), which uses map_for_pmu() and
map_for_cpu()'s static caches, perf_pmu__lookup_metrics_table()
re-fetches the CPUID and linearly scans pmu_events_map[] for every sysfs
PMU in pmu_read_sysfs().

On x86, find_core_metrics_table() runs regcomp()/regexec() via
strcmp_cpuid_str() per entry, adding thousands of regex compilations on
large systems.  A symmetric perf_pmu__find_metrics_table() helper backed
by map_for_pmu() would reuse the cache.

[ ... ]

> @@ -1468,19 +1720,16 @@ struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pm
>  	pmu->is_core = true;
> -	pmu->type = PERF_TYPE_RAW;
>  	pmu->cpus = cpu_map__online();
> +	pmu->events_table = perf_pmu__find_events_table(pmu);
> +	pmu->metrics_table = perf_pmu__lookup_metrics_table(pmu);

[Severity: Medium]
Should the placeholder core PMU populate pmu->events_table when
pmu->format is empty?

In environments without a sysfs core PMU (such as VMs), attaching the
CPU JSON events table causes perf list to advertise non-legacy events on
the placeholder cpu PMU, yet parsing any of them fails with -EINVAL in
pmu_config_term() because pmu->format has no format terms.

This also changes existing behavior without mentioning it in the commit
message.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204011029.1946921-1-irogers@google.com?part=2

  reply	other threads:[~2026-12-04  1:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:10 [PATCH v3 00/11] perf pmu: Layered sysfs-style PMU event and metric directories Ian Rogers
2026-12-04  1:10 ` [PATCH v3 01/11] perf pmu: Generalize pmu_alias_info_file() and lazy single-event sysfs loading Ian Rogers
2026-12-04  1:32   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 02/11] perf pmu: Add metric and metricgroup storage on struct perf_pmu Ian Rogers
2026-12-04  1:26   ` sashiko-bot [this message]
2026-12-04  1:10 ` [PATCH v3 03/11] perf pmu-layer: Introduce stateless struct pmu_layer abstraction and builtin adapter Ian Rogers
2026-12-04  1:35   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 04/11] perf pmu-layer: Add openat-based directory layer with literal CPUID/symlink lookup Ian Rogers
2026-12-04  1:35   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 05/11] perf config: Add pmu-events.dir configuration option Ian Rogers
2026-12-04  1:27   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 06/11] perf pmu: Switch alias resolution and enumeration to layered PMU stack Ian Rogers
2026-12-04  1:38   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 07/11] perf metricgroup: Route metric and metricgroup lookups through struct perf_pmu Ian Rogers
2026-12-04  1:40   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 08/11] perf list, jevents: Add --export-dir and --output-dir sysfs-style exporters Ian Rogers
2026-12-04  1:36   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 09/11] perf jevents: Add compiled-in model and sys table iterators Ian Rogers
2026-12-04  1:10 ` [PATCH v3 10/11] perf list: Add --export-cpuid to export compiled-in CPU models Ian Rogers
2026-12-04  1:44   ` sashiko-bot
2026-12-04  1:10 ` [PATCH v3 11/11] perf tests: Add round-trip export, CPUID symlink, and pmu-events.dir overlay tests Ian Rogers
2026-12-04  1:49   ` sashiko-bot
2026-12-04  1:49 ` [PATCH v3 00/11] perf pmu: Layered sysfs-style PMU event and metric directories sashiko-bot

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=sashiko-outbox-248892@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.