Linux Perf Users
 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 06/11] perf pmu: Switch alias resolution and enumeration to layered PMU stack
Date: Fri, 04 Dec 2026 01:38:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-248904@kernel.org> (raw)
In-Reply-To: <20261204011029.1946921-7-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] perf pmu: ignored pmu_layer__load_events() errors leave
  unresolved aliases
- [Medium] perf: repeated full linear sys event scans on lookup misses
  in pmu_layer__find_event()
- [Medium] perf pmu: perf_pmu__have_event() amplifies pmu-events.dir
  syscalls per PMU
- [Low] perf pmu: dead load=false branch in perf_pmu__find_alias() and
  unused param
--

commit 4fcc943d510650551034017b72721eec84e21272
Author: Ian Rogers <irogers@google.com>

perf pmu: Switch alias resolution and enumeration to layered PMU stack

This commit switches PMU alias lookup, existence checks, and event
enumeration in tools/perf/util/pmu.c over to pmu_layer__find_event() and
pmu_layer__load_events(), removing the old sysfs and JSON alias loading
helpers.

> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 9cb6fcb8b5f24..3c1c24f1804b9 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c

[ ... ]

> @@ -536,393 +403,22 @@ static void perf_pmu__del_metricgroups(struct perf_pmu *pmu)

[ ... ]

>  static struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu,
>  						   const char *name,
>  						   bool load)
>  {
>  	struct perf_pmu_alias *alias = NULL;

[ ... ]

> +	if (!pmu || !name)
>  		return NULL;
>  
> +	if (!load) {
> +		if (hashmap__find(pmu->aliases, name, &alias))
> +			return alias->terms ? alias : NULL;
>  		return NULL;
>  	}

[ ... ]

> +	return pmu_layer__find_event(pmu, name);
>  }

[Severity: Low]
Can perf_pmu__find_alias() be dropped in favor of calling
pmu_layer__find_event() directly?  Its only two remaining callers,
pmu_find_alias() and perf_pmu__have_event(), unconditionally pass
load=true, leaving the load parameter and the if (!load) branch dead code.

Similarly, static check_info_data() has only one caller in
perf_pmu__check_alias(), so its unused pmu parameter can be removed
instead of marked __maybe_unused.

[ ... ]

> @@ -1475,21 +911,12 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
>  	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);
> -	/*
> -	 * Load the sys json events/aliases when loading the PMU as each event
> -	 * may have a different compat regular expression. We therefore can't
> -	 * know the number of sys json events/aliases without computing the
> -	 * regular expressions for them all.
> -	 */
> -	pmu_add_sys_aliases(pmu);
>  	list_add_tail(&pmu->list, pmus);

[Severity: Medium]
Does removing pmu_add_sys_aliases() here introduce a lookup scaling
regression on systems with uncore PMU identifier files?

Because pmu_layer__find_event() does not cache negative lookups, every
miss on a PMU with pmu->id enters builtin_cpu_find_event() and runs
pmu_for_each_sys_event(), linearly scanning and decompressing all
compiled-in system event tables (and recompiling compat regexes on
name/PMU matches).  When parse_events_multi_pmu_add() probes
perf_pmu__have_event() across every PMU for each bare event name, that
full scan repeats per (event, PMU) miss instead of once per PMU at
lookup time.

[ ... ]

> @@ -2320,20 +1730,13 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name)
>  		return hwmon_pmu__have_event(pmu, name);
>  	if (perf_pmu__is_drm(pmu))
>  		return drm_pmu__have_event(pmu, name);
> -	if (perf_pmu__find_alias(pmu, name, /*load=*/ true) != NULL)
> -		return true;
> -	if (pmu->cpu_aliases_added || (!pmu->events_table && !pmu->is_core))
> -		return false;
> -	if (pmu_events_table__find_event(pmu->events_table, pmu, name, NULL, NULL) == 0)
> -		return true;
> -	return pmu->is_core &&
> -		pmu_events_table__find_event(perf_pmu__default_core_events_table(),
> -					     pmu, name, NULL, NULL) == 0;
> +	return perf_pmu__find_alias(pmu, name, /*load=*/true) != NULL;
>  }

[Severity: Medium]
Can routing perf_pmu__have_event() through pmu_layer__find_event() cause
heavy openat() and getdents64() syscall amplification when pmu-events.dir
is configured?

parse_events_multi_pmu_add() calls perf_pmu__have_event() across every
PMU for each bare event name, and pmu_layer__find_event() does not cache
misses.  On every miss, dir_for_each_pmu_subdir() unconditionally calls
dup() and io_dir__readdir() on each matched scope directory for every
uncore PMU, and dir_probe_user_event_base() probes all 15 event and
sidecar suffixes across 2 to 3 case variants (30 to 45 openat() calls per
matching PMU subdir and scope) even though aliases without alias->terms
are discarded.

On servers with 100+ PMUs and a metric group of 20 to 30 bare events,
this produces over 100,000 syscalls per invocation, which is especially
noticeable if pmu-events.dir resides on a network or FUSE filesystem.

[ ... ]

> @@ -2478,12 +1873,13 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
>  	if (perf_pmu__is_drm(pmu))
>  		return drm_pmu__for_each_event(pmu, state, cb);
>  
> -	pmu_aliases_parse(pmu);
> -	pmu_add_cpu_aliases(pmu);
> +	pmu_layer__load_events(pmu);
>  	hashmap__for_each_entry(pmu->aliases, entry, bkt) {

[Severity: Medium]
Should perf_pmu__for_each_event() (as well as perf_pmu__num_events(),
perf_pmu__name_from_config(), and perf_pmu__lookup()) handle errors
returned by pmu_layer__load_events() and pmu_layer__load_events_at()?

If a lower layer fails (for example -ENOMEM or -EMFILE from dup() in
dir_scan_events_fd()), pmu_layer__load_events_at() calls
pmu_layer_finalize_aliases(pmu, false) and returns the error with
pmu->aliases_loaded and pmu->eager_sysfs_loaded still false.  That leaves
higher-layer entries with alias->terms != NULL and alias->resolved ==
false cached in pmu->aliases.

Ignoring the error lets perf_pmu__for_each_event() silently return a
truncated event list, and later pmu_layer__find_event() calls return
those cached entries without checking alias->resolved, permanently
omitting sysfs sidecars and builtin_common legacy_terms.  In
perf_pmu__lookup() with eager_load, it also leaves eager_sysfs_loaded
false after the caller closes dirfd, allowing later lookups on a test PMU
to probe host sysfs.

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

  reply	other threads:[~2026-12-04  1:38 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
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 [this message]
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-248904@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox