summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorRyan Newton <newton@meta.com>2025-10-15 18:50:35 +0300
committerTejun Heo <tj@kernel.org>2025-10-15 19:46:25 +0300
commit44f5c8ec5b9ad8ed4ade08d727f803b2bb07f1c3 (patch)
tree23226ea58376f17c0ae7e357a75e32f5796f04ff /include/linux
parent347ed2d566dabb06c7970fff01129c4f59995ed6 (diff)
downloadlinux-44f5c8ec5b9ad8ed4ade08d727f803b2bb07f1c3.tar.xz
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>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/sched/ext.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
index 9848aeab2786..4713f374acc0 100644
--- a/include/linux/sched/ext.h
+++ b/include/linux/sched/ext.h
@@ -58,6 +58,7 @@ enum scx_dsq_id_flags {
*/
struct scx_dispatch_q {
raw_spinlock_t lock;
+ struct task_struct __rcu *first_task; /* lockless peek at head */
struct list_head list; /* tasks in dispatch order */
struct rb_root priq; /* used to order by p->scx.dsq_vtime */
u32 nr;