summaryrefslogtreecommitdiff
path: root/include/linux/sched
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2026-07-13 22:18:43 -1000
committerTejun Heo <tj@kernel.org>2026-07-13 22:18:43 -1000
commit46a85ae6fe5b468107baa9f21f073a940208d9ff (patch)
tree58a5e34379e2d016ed51ee331c93e4037595a321 /include/linux/sched
parentd5b8f4cdd17dc42fd51048785fef1e2a7dd1117f (diff)
sched_ext: Tie cpu occupancy to SCX_CAP_BASE through the task slice
A task's slice grants it cpu occupancy - how long it holds its cpu. In a sub-scheduler hierarchy cpu access is delegated through revocable capabilities, so a task's occupancy must follow them. Only its own scheduler sets its slice, and extending the slice is allowed only while that scheduler holds baseline cpu access (SCX_CAP_BASE) on the cpu. Otherwise a scheduler could keep occupying a cpu it has been denied simply by handing out long slices. The cap check reads effective caps, which are coherent only under the task's rq lock, and the kernel decrements the slice under that lock as the task runs, so a running task's slice can be changed only there while a queued task's can be set directly. Make scx_bpf_task_set_slice() apply the slice under the rq lock. Synchronously when the caller already holds it, otherwise by stashing it in the new p->scx.slice_oob, tagged with the scheduler's id so a request that outlived a reassignment is dropped. Whether the caller holds @p's current rq lock is tested with p->scx.runnable_cpu. Revocation is enforced through the same grant. When a cpu's effective caps lose SCX_CAP_BASE, the cap-revoke reenq scan also checks the running task and zeroes its slice to evict it. The scan runs as a balance callback after the pick, so this catches both the task that was running when the revoke landed and a capless task the pick just promoted off the local DSQ. The paths that keep a task on its cpu - holding on to the last runnable task in balance, the ENQ_LAST reinsertion and the slice refill on pick - skip tasks lacking baseline access. A migration-disabled task is exempt, mirroring its capless admission on insert. v4: Test rq ownership with p->scx.runnable_cpu, closing a remote-wakeup TOCTOU. (sashiko AI) v3: Keep a pending out-of-band slice request across refill and preserve. (sashiko AI) v2: Only write slice directly when @p is queued on the held rq. (sashiko AI) Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Andrea Righi <arighi@nvidia.com>
Diffstat (limited to 'include/linux/sched')
-rw-r--r--include/linux/sched/ext.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h
index 853f03b63133..803da0f1e509 100644
--- a/include/linux/sched/ext.h
+++ b/include/linux/sched/ext.h
@@ -223,10 +223,11 @@ struct sched_ext_entity {
/* BPF scheduler modifiable fields */
/*
- * Runtime budget in nsecs. This is usually set through
- * scx_bpf_dsq_insert() but can also be modified directly by the BPF
- * scheduler. Automatically decreased by SCX as the task executes. On
- * depletion, a scheduling event is triggered.
+ * Runtime budget in nsecs - how long the task may hold its cpu. Owned
+ * by the task's scheduler. Set it when enqueuing via
+ * scx_bpf_dsq_insert(), or otherwise via scx_bpf_task_set_slice().
+ * Automatically decreased as the task executes. On depletion a
+ * scheduling event is triggered.
*
* This value is cleared to zero if the task is preempted by
* %SCX_KICK_PREEMPT and shouldn't be used to determine how long the
@@ -244,6 +245,14 @@ struct sched_ext_entity {
u64 dsq_vtime;
/*
+ * Out-of-band slice request from scx_bpf_task_set_slice() when the
+ * caller does not hold the rq lock, applied under the rq lock at the
+ * next slice consideration. One atomic64 packs the pending flag, the
+ * issuing sch's id, and the requested slice. See scx_slice_oob_consts.
+ */
+ atomic64_t slice_oob;
+
+ /*
* Sub-sched cap rejected reenq context, valid only while
* %SCX_TASK_REENQ_CAP is set. @reenq_reason_caps is the SCX_CAP_* bits
* that were needed but missing. @reenq_reason_cid is the target cid.