From: Robin Murphy <robin.murphy@arm.com>
To: Peter Zijlstra <peterz@infradead.org>,
Haris Okanovic <harisokn@amazon.com>
Cc: Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] perf/core: Add PERF_PMU_SCOPE_DEVICE
Date: Wed, 14 Oct 2026 15:26:10 +0100 [thread overview]
Message-ID: <e9d01b93-3658-4ba3-a15c-e6b4122b5c08@arm.com> (raw)
In-Reply-To: <20261014102700.GC4121339@noisy.programming.kicks-ass.net>
On 2026-10-14 11:27 am, Peter Zijlstra wrote:
> On Tue, Oct 13, 2026 at 01:56:01PM -0500, Haris Okanovic wrote:
>> Add a "device" pmu::scope for PMUs counted on a single CPU drawn
>> from a driver-supplied set instead of a fixed topology.
>>
>> This mechanism is implemented by new callbacks: filter_allowed_cpus()
>> is invoked to constrain the running CPU set to an allowed set for a
>> particular device; migrate_cpu() is used to perform any device specific
>> migration steps. Both are optional, e.g. for devices that can run on
>> any CPU or have no additional migration steps.
>>
>> Placement initially happens in perf_pmu_register() before the PMU
>> becomes visible, and is subsequently re-evaluated on hotplug events.
>> A new CPU selection is made by cpumask_any_distribute() to spread out
>> load from multiple devices, but only when the previous CPU selection is
>> offline or no longer allowed by filter_allowed_cpus().
>>
>> PMU events of these devices follow the chosen CPU. They are initially
>> bound to a CPU in perf_try_init_event() then reassigned by
>> perf_pmu_migrate_context() when a new CPU is selected.
>
>>
>> The initial CPU assignment can race with migration, leaving a stranded
>> event. A sequence counter is added to close this gap without additional
>> locks. A count in struct pmu increments on each migration and is copied
>> to struct perf_event on init. The copied count is checked again before
>> the event is installed, under the same context mutex, which causes
>> perf_event_open() and perf_event_create_kernel_counter() to return -EBUSY
>> during migration periods.
>
> I'm not entirely sure on this. How is this race different from changing
> CPU on hotplug?
Not much, other than that hotplug is at least already serialised against
perf_event_open on the perf core side via perf_online_mask. This is also
where I was heading with my generic hotplug proposal[1] - once perf core
can be in charge of that, it should then be viable to also migrate PMUs
for reasons other than hotplug, and it would all look the same to the
drivers.
(Yes, as-is my patch still preserves the status quo of drivers picking
their own target CPU to keep things simple, but that was one of the
points I was hoping to generate some discussion on...)
Thanks,
Robin.
[1]
https://lore.kernel.org/linux-arm-kernel/cover.1784911757.git.robin.murphy@arm.com/
next prev parent reply other threads:[~2026-10-14 14:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 18:55 [PATCH 0/4] perf: Manage single-CPU PMU affinity in perf core Haris Okanovic
2026-10-13 18:56 ` [PATCH 1/4] perf/core: Fix perf_pmu_migrate_context() leaving events behind Haris Okanovic
2026-10-13 19:06 ` sashiko-bot
2026-10-13 18:56 ` [PATCH 2/4] perf/core: Add PERF_PMU_SCOPE_DEVICE Haris Okanovic
2026-10-13 19:11 ` sashiko-bot
2026-10-14 10:27 ` Peter Zijlstra
2026-10-14 14:26 ` Robin Murphy [this message]
2026-10-13 18:56 ` [PATCH 3/4] perf/core: Allow userspace to select a device PMU's CPU Haris Okanovic
2026-10-13 19:08 ` sashiko-bot
2026-10-13 18:56 ` [PATCH 4/4] perf/arm-cmn: Convert to PERF_PMU_SCOPE_DEVICE Haris Okanovic
2026-10-13 19:06 ` 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=e9d01b93-3658-4ba3-a15c-e6b4122b5c08@arm.com \
--to=robin.murphy@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=harisokn@amazon.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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