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 03/16] perf pmu: Add perf_pmu__probe() for basic open, counting, and sampling
Date: Fri, 20 Nov 2026 22:39:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-226286@kernel.org> (raw)
In-Reply-To: <20261120222615.2291168-4-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf pmu: try_open_attr_variants() closes tracepoint fd before
  keepalive
--

commit 000f6d2820c05383b074beef8f5d9879e6d9d78a
Author: Ian Rogers <irogers@google.com>

perf pmu: Add perf_pmu__probe() for basic open, counting, and sampling

This commit adds perf_pmu__probe() and struct perf_pmu::probed to probe a
live PMU via perf_event_open() and record whether opening, counting, and
sampling are supported.

> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 1d3cfa0823475..b43afb8b155b3 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
[ ... ]
> @@ -2850,9 +2866,570 @@ void perf_pmu__delete(struct perf_pmu *pmu)
[ ... ]
> +static bool try_open_attr_variants(struct perf_event_attr *attr,
> +				   bool is_uncore, int pmu_cpu,
> +				   unsigned long flags,
> +				   pid_t *out_pid, int *out_cpu,
> +				   int *last_err)
> +{
[ ... ]
> +				fd = sys_perf_event_open(&try_attr, pid, pmu_cpu, -1, flags);
> +				if (fd >= 0) {
> +					close(fd);
> +					*attr = try_attr;
> +					*out_pid = pid;
> +					*out_cpu = pmu_cpu;
> +					return true;
> +				}
[ ... ]
> +static void __perf_pmu__probe(struct perf_pmu *pmu, int pmu_cpu)
> +{
[ ... ]
> +	/*
> +	 * For tracepoint events, closing the last fd for a tracepoint triggers
> +	 * tracepoint_synchronize_unregister() (an RCU grace period) in the
> +	 * kernel. Hold one disabled fd open across the probe sequence so
> +	 * tp_event->perf_refcount stays >= 1 and each probe open/close is
> +	 * instantaneous.
> +	 */
> +	if (pmu->type == PERF_TYPE_TRACEPOINT) {
> +		struct perf_event_attr ka_attr = base_attr;
> +
> +		ka_attr.disabled = 1;
> +		keepalive_fd = sys_perf_event_open(&ka_attr, pid, cpu, -1, flags);
> +	}

[Severity: Low]
Does closing fd inside try_open_attr_variants() defeat the tracepoint
keepalive optimization?

When try_open_attr_variants() closes the initial tracepoint fd before
keepalive_fd is opened, tp_event->perf_refcount drops to 0 in
perf_trace_event_unreg(), paying the tracepoint_synchronize_unregister()
RCU grace period and freeing the per-CPU tracepoint buffers before
__perf_pmu__probe() re-opens the same disabled attr as keepalive_fd.
Returning the open fd from try_open_attr_variants() to use as
keepalive_fd (or closing it when pmu->type != PERF_TYPE_TRACEPOINT) would
avoid the extra RCU grace period and redundant perf_event_open() call.

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

  reply	other threads:[~2026-11-20 22:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 22:25 [PATCH v3 00/16] perf sysinfo: Add subcommand to probe and summarize PMU capabilities Ian Rogers
2026-11-20 22:26 ` [PATCH v3 01/16] perf pmus: Expose duplicate uncore PMU scanning helpers Ian Rogers
2026-11-20 22:26 ` [PATCH v3 02/16] perf mem-events: Expose PMU init and name formatting helpers Ian Rogers
2026-11-20 22:26 ` [PATCH v3 03/16] perf pmu: Add perf_pmu__probe() for basic open, counting, and sampling Ian Rogers
2026-11-20 22:39   ` sashiko-bot [this message]
2026-11-20 22:26 ` [PATCH v3 04/16] perf pmu: Probe supported sample_type flags Ian Rogers
2026-11-20 22:26 ` [PATCH v3 05/16] perf pmu: Probe precise_ip levels Ian Rogers
2026-11-20 22:26 ` [PATCH v3 06/16] perf pmu: Probe privilege exclusion modifiers Ian Rogers
2026-11-20 22:26 ` [PATCH v3 07/16] perf pmu: Probe execution and AUX area features Ian Rogers
2026-11-20 22:26 ` [PATCH v3 08/16] perf pmu: Probe event group size limits Ian Rogers
2026-11-20 22:26 ` [PATCH v3 09/16] perf pmu: Probe user and interrupt sample register masks Ian Rogers
2026-11-20 22:26 ` [PATCH v3 10/16] perf pmu: Probe interrupt registers that require precise sampling Ian Rogers
2026-11-20 22:26 ` [PATCH v3 11/16] perf pmu: Probe memory profiling events and sample formats Ian Rogers
2026-11-20 22:26 ` [PATCH v3 12/16] perf pmu: Probe user-space mmap capabilities Ian Rogers
2026-11-20 22:26 ` [PATCH v3 13/16] perf pmu: Probe branch instruction skid Ian Rogers
2026-11-20 22:26 ` [PATCH v3 14/16] perf sysinfo: Add sysinfo subcommand Ian Rogers
2026-11-20 22:26 ` [PATCH v3 15/16] perf docs: Add perf-sysinfo man page Ian Rogers
2026-11-20 22:26 ` [PATCH v3 16/16] perf test: Add perf sysinfo shell test Ian Rogers

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-226286@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.