Re: [PATCH 1/2] smpboot: Allow restricting per-CPU threads to a CPU mask
From: Thomas Gleixner
Date: Thu Nov 12 2026 - 12:44:38 EST
On Tue, Nov 03 2026 at 00:09, Daniel Lezcano wrote:
> smpboot_register_percpu_thread() creates a thread for every online CPU
> and registers the descriptor for subsequent CPU hotplug operations.
> There is currently no way to restrict these threads to a subset of
> CPUs, even when the user only needs work performed on that subset.
>
> For example, an idle injection device targets a specific CPU mask.
> Creating threads outside that mask consumes resources unnecessarily.
> Supporting multiple such devices also requires each descriptor to
> manage only the threads associated with its own CPUs.
>
> Add an optional CPU mask to struct smp_hotplug_thread and apply it
> throughout the thread lifecycle. Registration creates threads only for
> online CPUs in the mask. CPU bring-up creates threads for selected
> CPUs that were offline at registration, while parking and unparking
> are restricted to the same mask.
>
> Apply the restriction to thread destruction as well, both during
> unregistration and registration failure cleanup. This is necessary
> when descriptors with disjoint masks share the same per-CPU task
> storage: tearing down one descriptor must not stop or clear threads
> owned by another descriptor.
>
> The caller must keep the mask valid and unchanged until the descriptor
> is unregistered. Callers sharing per-CPU task storage must ensure their
> masks do not overlap and serialize ownership changes themselves.
This really wants a built-in check which prevents overlapping
registrations for the same thread storage. It's easy enough to do:
smpboot_register_percpu_thread()
if (!pt->cpumask)
pt->cpu_mask = cpu_possible_mask;
guard(cpus_read_lock)();
guard(mutex)(&smpboot_threads_lock);
list_for_each_entry(ht, &hotplug_threads, list) {
if (ht->store != pt->store)
continue;
if (WARN_ON_ONCE(cpumask_intersects(ht->cpumask, pt->cpumask)))
return -EBUSY;
}
Hmm?
Thanks,
tglx