Re: [PATCH v2 sched_ext/for-7.1] sched_ext: Invalidate dispatch decisions on CPU affinity changes

From: Kuba Piecuch

Date: Tue May 05 2026 - 05:16:33 EST


On Tue May 5, 2026 at 8:31 AM UTC, Tejun Heo wrote:
> 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.

I see, makes sense. Thanks!

>> 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

Ah, interesting, I didn't know there's a pure-BPF implementation of spinlocks!
I haven't really had the chance to play around with arenas yet, looks like I'm
missing out ;-)

Thanks,
Kuba