From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796348306; b=roZRGMYvJdh6H6laeDkLVNZn1KHAcWgBg6RyJu8MmB5wIJYwSnpqfmzUaoSF7iggmACR 15STodWzyyN/EQlm7wAWbva04swL9VrHOFOi/XVF3b0w7nqINivRkoc4qstteTZ8wthTr djA56G/53r8gdzm04zMRpdGOl5bnFhONpv8//voqdufugAF6vY0qXaEkxckAv1Tholunm sMrC9KdSlkv+6zcU3JD7uEYSiGaCKx7tJo5pIs4zmSqMKn5yJh5WYhefc4Zdz8Jl+5ONm 0ccXBfzuErByrc/Lnkm0bENHE4Ukj//aRroZPuqH8a2rsYBy7TedmLkoy6pnC0hpEKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796348306; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=JFlG1Z2I9HA/2WbrEJ4KMukLG3bHYtNB008yBb7dLrw=; b=So4iu1EtzSeCIKNwSqtlPmZKOaAA+g6/RCllBL/oy2mMfuMMbYT0od7xwMq2ZBQk0JEu fFRsCUdpCCCChvSsQdkZTIqDYwXQ6Zm6v/SIICcOItfQ+TSD0h4vJVLMKKSNgxhQlOM/3 fh2kWiWHkIXS4OOyWQGRvEuGkLn9AjslOcD3XGqwzPTTJ7ImEiD0XH//aRwiUfHzyfbwD oHHbv7GN9gyLl0YyxpXLD5pbfGyku2Z8Yl1AH2UdABNwqNBAikL4bEvf4BLAmPHS9T4/F VpLJEH9pTBJ/Pa7g7/YXblNjsfLnjeLWCVP9nNcFXCQ3aiVfSYuLrQHG7wbWK9yTXFg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CrUEehec; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 448D3606A322 for ; Fri, 4 Dec 2026 01:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CrUEehec Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE0BE1F000C2; Fri, 4 Dec 2026 01:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796348305; bh=JFlG1Z2I9HA/2WbrEJ4KMukLG3bHYtNB008yBb7dLrw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CrUEehecbHGnamqxiUsMuLN9oPufhac0SGaOp+cBp1s4tcHUYX6aoeWa/k7wIHA8K aUn9s1O5yIKEMrg/6TEszEeq+EC4ACgf+ZYddMxwqTCYbb40LdJZ0UFpSvEVMnhpAh 8qfyXNR/JhmzQoTSl78kKOZ5WpXZDwLFT5W+jDNYiUaqEOz6Ceygpr6WAIJ0qJisdW 0KpdwaMYWxn3kmpl0iqfPPIHjl1XnN60hBz99NfSMHs1Yo4g6u7iPdbGkT40pzR5RC MpQHQEWpVRdMgfAQ69JS53c/HJnK9w4iiL4Q1spHumxOiizstQ8bVu9M6Xz72WRHKs O4IUaPDyQo8rA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 06/11] perf pmu: Switch alias resolution and enumeration to layered PMU stack Reply-To: sashiko-reviews@lists.linux.dev To: "Ian Rogers" Cc: linux-perf-users@vger.kernel.org In-Reply-To: <20261204011029.1946921-7-irogers@google.com> References: <20261204011029.1946921-1-irogers@google.com> <20261204011029.1946921-7-irogers@google.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 01:38:25 +0000 X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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=3Dfalse branch in perf_pmu__find_alias() and unused param -- commit 4fcc943d510650551034017b72721eec84e21272 Author: Ian Rogers 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 =3D NULL; [ ... ] > + if (!pmu || !name) > return NULL; > =20 > + 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=3Dtrue, 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 =3D pmu_find_alias_name(pmu, dirfd); > pmu->events_table =3D perf_pmu__find_events_table(pmu); > pmu->metrics_table =3D 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, c= onst 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=3D*/ true) !=3D 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, NU= LL) =3D=3D 0) > - return true; > - return pmu->is_core && > - pmu_events_table__find_event(perf_pmu__default_core_events_table(), > - pmu, name, NULL, NULL) =3D=3D 0; > + return perf_pmu__find_alias(pmu, name, /*load=3D*/true) !=3D 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); > =20 > - 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 !=3D NULL and alias->resolved =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204011029.1946= 921-1-irogers@google.com?part=3D6