]> Gentwo Git Trees - linux/.git/commit
sched_ext: Add lockless peek operation for DSQs
authorRyan Newton <newton@meta.com>
Wed, 15 Oct 2025 15:50:35 +0000 (11:50 -0400)
committerTejun Heo <tj@kernel.org>
Wed, 15 Oct 2025 16:46:25 +0000 (06:46 -1000)
commit44f5c8ec5b9ad8ed4ade08d727f803b2bb07f1c3
tree23226ea58376f17c0ae7e357a75e32f5796f04ff
parent347ed2d566dabb06c7970fff01129c4f59995ed6
sched_ext: Add lockless peek operation for DSQs

The builtin DSQ queue data structures are meant to be used by a wide
range of different sched_ext schedulers with different demands on these
data structures. They might be per-cpu with low-contention, or
high-contention shared queues. Unfortunately, DSQs have a coarse-grained
lock around the whole data structure. Without going all the way to a
lock-free, more scalable implementation, a small step we can take to
reduce lock contention is to allow a lockless, small-fixed-cost peek at
the head of the queue.

This change allows certain custom SCX schedulers to cheaply peek at
queues, e.g. during load balancing, before locking them. But it
represents a few extra memory operations to update the pointer each
time the DSQ is modified, including a memory barrier on ARM so the write
appears correctly ordered.

This commit adds a first_task pointer field which is updated
atomically when the DSQ is modified, and allows any thread to peek at
the head of the queue without holding the lock.

Signed-off-by: Ryan Newton <newton@meta.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/sched/ext.h
kernel/sched/ext.c
tools/sched_ext/include/scx/common.bpf.h
tools/sched_ext/include/scx/compat.bpf.h