[PATCH v14 07/39] sched/deadline: Leave an active task alone in the inactive timer

From: Mathieu Desnoyers

Date: Thu Dec 03 2026 - 10:00:05 EST


inactive_task_timer() runs at the 0-lag time of a deadline task that
blocked. A wakeup cannot cancel the timer once its handler runs. So
task_contending() clears dl_non_contending. The comment there says that
the handler then sees the flag clear, and leaves the active utilization
alone.

But the handler first checks whether the task left the class or is
dying. It checks dl_non_contending after that. For a dying task, this
first branch releases total_bw and clears the parameters, even if the
task woke up in between. switched_to_dl() cannot cancel a running
handler either, so a task that comes back into the class and then dies
takes the same branch.

T is a SCHED_DEADLINE task on CPU 1. It blocked before its 0-lag time,
so dl_non_contending is set and its inactive timer is armed. The timer
fires on CPU 0. CPU 0 is then delayed, for example by a preempted vCPU,
and gets the rq lock of T only after T has exited:

CPU 0 CPU 1
inactive_task_timer() runs
task_rq_lock(T) waits
T wakes up
task_contending():
dl_non_contending = 0
cannot cancel the timer
T exits
do_task_dead():
T->__state = TASK_DEAD
gets the lock
T is TASK_DEAD:
releases total_bw
__dl_clear_params()
__schedule()
dequeue_task_dl(T)
task_non_contending():
dl_runtime == 0, returns

The last dequeue of T then leaves its bandwidth in running_bw and in
this_bw of CPU 1. schedutil reads running_bw, so CPU 1 would keep a
raised minimum frequency. GRUB would also reclaim less runtime there.

Fix this by leaving the task alone when it is in the class and
dl_non_contending is clear. Its last dequeue then removes its
bandwidth, as for any task that dies.

The Sashiko AI review of this series found this case by reading. It was
not reproduced.

Fixes: 209a0cbda7a0 ("sched/deadline: Improve the tracking of active utilization")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 26b02ae8683a..c88cac6bc5fe 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2321,6 +2321,14 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer)
if (dl_server(dl_se))
goto no_task;

+ /*
+ * The task woke up, or came back into the class, while this handler
+ * waited for the rq lock. Leave it alone, even if it is dying: its
+ * last dequeue needs its parameters to remove its bandwidth.
+ */
+ if (dl_task(p) && !dl_se->dl_non_contending)
+ goto unlock;
+
if (!dl_task(p) || READ_ONCE(p->__state) == TASK_DEAD) {
struct dl_bw *dl_b = dl_bw_of(task_cpu(p));

--
2.47.3