[PATCH v14 02/39] sched/deadline: Replenish a throttled task boosted while asleep
From: Mathieu Desnoyers
Date: Thu Dec 03 2026 - 09:59:45 EST
A deadline task can be throttled as it blocks, with an rt_mutex held.
Its replenishment timer is then armed. A deadline waiter can boost the
task while it sleeps.
Commit feff2e65efd8 ("sched/deadline: Unthrottle PI boosted threads
while enqueuing") lets a boost override the throttle. enqueue_task_dl()
lifts the throttle of a boosted task, and dl_task_timer() ignores a
boosted task. This covers a task that is enqueued while boosted. But a
boost of a sleeping task does not enqueue it.
T is a SCHED_DEADLINE task that holds the rt_mutex L. W is a
SCHED_DEADLINE task with an earlier deadline:
T W T's timer
uses up its runtime, sleeps
dl_throttled = 1
start_dl_timer()
pthread_mutex_timedlock(L)
rt_mutex_setprio(T, W)
T sleeps: no enqueue
dl_task_timer()
T is boosted: returns
times out
rt_mutex_setprio(T, NULL)
wakes up
enqueue_dl_entity()
dl_throttled: waits for the timer
The timer has already fired. T would never run again, not even to die
of SIGKILL. Every later waiter on L would hang too. This was found by
reading.
Fix this by returning early in dl_task_timer() only for a boosted task
that is queued. A boosted task that sleeps then takes the existing path
for a throttled task that is not queued: it is replenished.
The timer refills the task from the parameters of its donor. After the
deboost, the task keeps the runtime and the deadline of that refill.
Its wakeup then checks them against its own parameters, as any wakeup
does. On v7.4-rc2, a queued boosted task also keeps the values of its
donor after the deboost. The priority inheritance series gives the
task its own values back.
The refill relies on two earlier patches:
- "sched/deadline: Hold a reference on the deadline donor of a boosted
task" is earlier in this series. It keeps the donor from being freed
while the task points to it. A chain walk that has not reached the
task yet leaves it on an old donor. The refill then uses the
parameters of that old donor, as for a queued boosted task.
- "sched/deadline: Do not replenish a boost from cleared parameters" is
in the first series. It keeps the refill from looping on the
parameters of a donor that left the class.
The Sashiko AI review of this series found this.
Fixes: feff2e65efd8 ("sched/deadline: Unthrottle PI boosted threads while enqueuing")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Reviewed-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index ac96885796bd..e137eb7efa1f 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1364,10 +1364,13 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
}
/*
- * The task might have been boosted by someone else and might be in the
- * boosting/deboosting path, its not throttled.
+ * A boost overrides the throttle. enqueue_task_dl() lifts it when the
+ * boost enqueues the task, or when the task wakes up boosted. So a
+ * queued task needs nothing here. A boost of a sleeping task does not
+ * enqueue it, and it can end before the wakeup. Nothing would lift the
+ * throttle then. So let a sleeping task reach the !queued case below.
*/
- if (is_dl_boosted(dl_se))
+ if (is_dl_boosted(dl_se) && task_on_rq_queued(p))
goto unlock;
/*
--
2.47.3