Re: [PATCH v2 1/2] perf: Generic hotplug/cpumask for system PMUs

From: Robin Murphy

Date: Tue Jul 28 2026 - 08:13:49 EST


On 24/07/2026 6:48 pm, Robin Murphy wrote:
[...]
@@ -12918,6 +12943,17 @@ int perf_pmu_register(struct pmu *_pmu, const char *name, int type)
INIT_LIST_HEAD(&pmu->events);
spin_lock_init(&pmu->events_lock);
+ /*
+ * Finally, if appropriate give the PMU a chance to pick an initial CPU
+ * affinity for its cpumask, or initialise any general per-CPU state.
+ * Note that we're serialised against perf_event_{init,exit}_cpu()
+ * themselves here by virtue of pmus_lock.
+ */
+ if (pmu->init_cpu) {
+ for_each_online_cpu(cpu)

Having thought about it, while the drivers I want to convert should all be fine with a potential double-init, I guess it is true that an outgoing CPU in between CPUHP_AP_PERF_ONLINE and CPUHP_TEARDOWN_CPU would still be in cpu_online_mask with interrupts enabled, and thus potentially able to be picked by the driver callback, and thus end up inaccessible unless and until that CPU comes back again. So indeed for true race elimination this probably should use perf_online_mask. I'll save spamming a v3 until I get some feedback that the overall idea is worth pursuing at all, though.

(But I shall continue to ignore the rest of the twaddle from word-salad models which apparently can't differentiate "initialise" from "allocate"...)

Thanks,
Robin.

+ smp_call_function_single(cpu, perf_scope_init_cpu, pmu, 1);
+ }
+
/*
* Now that the PMU is complete, make it visible to perf_try_init_event().
*/