Re: [PATCH v2 sched_ext/for-7.1] sched_ext: Invalidate dispatch decisions on CPU affinity changes
From: Tejun Heo
Date: Tue May 05 2026 - 04:31:33 EST
Hello, Kuba.
On Tue, May 05, 2026 at 08:01:58AM +0000, Kuba Piecuch wrote:
> Could you elaborate a bit on what you mean by "properly synchronized" here?
If ops.dequeue() synchronizes with the dispatch path so that the task being
dequeued is either dequeued or dispatched, there's nothing else to protect.
If ops.dequeue() wins, the task won't be dispatched. If ops.dequeue() loses,
the task should already be in either the dispatch buffer or local DSQ and
the kernel dequeue code will shoot them down. In the former case, at the
dispatch buffer flush time, the task would either be already dequeued or
re-enqueued with a different qseq and ignored. In the latter,
dispatch_dequeue() would remove it from the local DSQ.
> To me, introducing cookies is primarily about adding flexibility around
> managing the "dispatch window" between the qseq being probed and the actual
> dispatch attempt in finish_dispatch(). For example, a CPU can get a cookie and
> pass it to another CPU to perform the dispatch, which is not possible with
> the current interface.
So, this is mostly for schedulers that don't want to or for some reason
can't implement proper synchronization between dequeue and dispatch paths. A
convenient thing to make life a bit easier.
> On another, slightly related note: I'm considering making scx_bpf_dsq_insert()
> and other dispatch-related kfuncs that manipulate only CPU-local state
> callable while holding BPF spinlocks. This is something that the comment above
> scx_bpf_dsq_insert() explicitly mentions:
>
> This function doesn't have any locking restrictions and may be called under
> BPF locks (in the future when BPF introduces more flexible locking).
>
> I'm not sure what "more flexible locking" means here, but this can be
> accomplished by simply adding the kfuncs to the list of kfuncs callable under
> spinlocks in the BPF verifier.
>
> Are you aware of any previous work on this? Any pushback from BPF folks?
That comment was written before bpf_spinlock was introduced. Please feel
free to allow thoes functions under bpf spinlocks. BTW, there's also arena
spinlock that is implemented in BPF proper, which is already used by
multiple schedulers and likely to be the default option in the future:
https://github.com/sched-ext/scx/blob/main/scheds/include/bpf_arena_spin_lock.h
Thanks.
--
tejun