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

From: Cheng-Yang Chou

Date: Tue May 05 2026 - 12:06:00 EST


Hi Tejun, Kuba, Andrea,

On Mon, May 04, 2026 at 10:31:28PM -1000, Tejun Heo 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.

I think we are on the same page! I'd like to take ownership of the
cookie implementation.

Andrea, as we discussed offline, please feel free to send the deferred
SCX bandwidth implementation, since you're already working on that. I
want to focus on the cookie implementation first, since the design has
been discussed for a while and I want to move it forward.

Here's the API I'm planning to propose:

- u64 scx_bpf_task_get_cookie(struct task_struct *p)

Returns an opaque cookie representing @p's current qseq. The caller
can store this in a BPF map and pass it to another CPU.

- bool scx_bpf_dsq_insert_with_cookie(struct task_struct *p, u64 dsq_id,
u64 enq_flags, u64 cookie)

Like scx_bpf_dsq_insert() with slice=0, but uses @cookie's qseq
instead of re-reading ops_state at insert time. A stale cookie causes
finish_dispatch() to silently discard the dispatch, which is safe.

Will send a follow-up patch soon, thanks!

--
Cheers,
Cheng-Yang