Re: [PATCH v2 0/5] Introduce QPW for per-cpu operations (v2)

Frederic Weisbecker
2026-03-10T21:34:28Z

Le Thu, Mar 05, 2026 at 10:47:00PM -0300, Marcelo Tosatti a écrit :
> On Thu, Mar 05, 2026 at 05:55:12PM +0100, Frederic Weisbecker wrote:
> > So let me summarize what are the possible design solutions, on top of our discussions,
> > so we can compare:
>
> I find this summary difficult to comprehend. The way i see it is:
>
> A certain class of data structures can be manipulated only by each individual CPU (the
> per-CPU caches), since they lack proper locks for such data to be
> manipulated by remote CPUs.
>
> There are certain operations which require such data to be manipulated,
> therefore work is queued to execute on the owner CPUs.

Right.

> >
> > 1) Never queue remotely but always queue locally and execute on userspace
>
> When you say "queue locally", do you mean to queue the data structure
> manipulation to happen on return to userspace of the owner CPU ?

Yes.

>
> What if it does not return to userspace ? (or takes a long time to return
> to userspace?).

Indeed it's a bet that syscalls eventually return "soon enough" for correctness
to be maintained and that the CPU is not stuck on some kthread. But on isolation
workloads, those assumptions are usually true.

>
> > return via task work.
> >
> > Pros:
> > - Simple and easy to maintain.
> >
> > Cons:
> > - Need a case by case handling.
> >
> > - Might be suitable for full userspace applications but not for
> > some HPC usecases. In the best world MPI is fully implemented in
> > userspace but that doesn't appear to be the case.
> >
> > 2) Queue locally the workqueue right away or do it remotely (if it's
> > really necessary) if the isolated CPU is in userspace, otherwise queue
> > it for execution on return to kernel. The work will be handled by preemption
> > to a worker or by a workqueue flush on return to userspace.
> >
> > Pros:
> > - The local queue handling is simple.
> >
> > Cons:
> > - The remote queue must synchronize with return to userspace and
> > eventually postpone to return to kernel if the target is in userspace.
> > Also it may need to differentiate IRQs and syscalls.
> >
> > - Therefore still involve some case by case handling eventually.
> >
> > - Flushing the global workqueues to avoid deadlocks is unadvised as shown
> > in the comment above flush_scheduled_work(). It even triggers a
> > warning. Significant efforts have been put to convert all the existing
> > users. It's not impossible to sell in our case because we shouldn't
> > hold a lock upon return to userspace. But that will restore a new
> > dangerous API.
> >
> > - Queueing the workqueue / flushing involves a context switch which
> > induce more noise (eg: tick restart)
> >
> > - As above, probably not suitable for HPC.
> >
> > 3) QPW: Handle the work remotely
> >
> > Pros:
> > - Works on all cases, without any surprise.
> >
> > Cons:
> > - Introduce new locking scheme to maintain and debug.
> >
> > - Needs case by case handling.
> >
> > Thoughts?
> >
> > --
> > Frederic Weisbecker
> > SUSE Labs
>
> Its hard for me to parse your concise summary (perhaps it could be more
> verbose).
>
> Anyway, one thought is to use some sort of SRCU type protection on the
> per-CPU caches.
> But that adds cost as well (compared to non-SRCU), which then seems to
> have cost similar to adding per-CPU spinlocks.

Well, there is SRCU-fast now. Though do we care about housekeeping performance
to be optimized on isolated workloads to the point we complicate things with a
weaker and and trickier synchronization mechanism? Probably not. If we choose to
pick up your solution, I'm fine with spinlocks.

Thanks.

--
Frederic Weisbecker
SUSE Labs