[PATCH v11 40/43] sched/deadline: Reschedule a running task throttled at its enqueue

From: Mathieu Desnoyers

Date: Wed Nov 25 2026 - 20:11:26 EST


A task with a constrained deadline (dl_deadline < dl_period) can wake up
after its deadline but before its next period.
Commit df8eac8cafce ("sched/deadline: Throttle a constrained deadline
task activated after the deadline") throttles it then until that period.
A refill would let it run for dl_runtime every dl_deadline, more than
its reservation.

enqueue_dl_entity() makes this check at every enqueue, not only at a
wakeup. These changes to a running task also dequeue and enqueue it:
- sched_setattr() and sched_setaffinity();
- a cgroup move;
- a deboost in rt_mutex_setprio().

A task can run past its deadline with runtime left, for example after
tasks with earlier deadlines delayed it. The check then throttles it and
leaves it off the dl_rq. But nothing reschedules: prio_changed_dl() sees
the same deadline and returns.

The task keeps the CPU. update_curr_dl() skips a task that is off the
dl_rq, so the tick neither charges it nor preempts it. It runs until it
blocks, until a task with an earlier deadline wakes up, or until its
next period. That is up to dl_period - dl_deadline of CPU time outside
its reservation. The Sashiko AI review of this series found this.

Fix this by rescheduling when the check throttles the current task, as
a throttle in update_curr_dl_se() does.

The task stopped this way can own an rt_mutex. Its deadline waiters
then wait for its next period, unless they boost it. So this patch comes
after "sched/deadline: Boost an owner that cannot run on its own
reservation" and "sched/deadline: Boost an owner throttled after its
waiter blocked".

The constrained_gap_change_running case of deadline_bw_test changes a
running task with sched_setattr(). "sched/deadline: Keep the debt of a
task across a change of parameters", earlier in this series, already
reschedules a task that sched_setattr() throttles. So the case passes
without this patch too. sched_setaffinity(), a cgroup move and a
deboost have no test case. Their effect was found by reading.

Fixes: df8eac8cafce ("sched/deadline: Throttle a constrained deadline task activated after the deadline")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 7a1beec2d95e..52095e24638c 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2465,6 +2465,13 @@ static inline void dl_check_constrained_dl(struct sched_dl_entity *dl_se)
/* A deadline waiter on an rt_mutex may boost it now. */
if (!dl_server(dl_se))
dl_request_owner_boost(dl_task_of(dl_se));
+ /*
+ * A running task is now off the dl_rq: the tick no longer
+ * charges it or preempts it. Reschedule, as a throttle in
+ * update_curr_dl_se() does.
+ */
+ if (!dl_server(dl_se) && task_current_donor(rq, dl_task_of(dl_se)))
+ resched_curr(rq);
}
}

--
2.47.3