[PATCH v6 32/37] sched/deadline: Check the runtime of a task that comes back runnable
From: Mathieu Desnoyers
Date: Mon Nov 16 2026 - 14:07:37 EST
Commit a649f237db18 ("sched,dl: Fix sched class hopping CBS hole")
keeps the runtime and the deadline of a task that leaves
SCHED_DEADLINE. A task that comes back before its deadline goes on with
them. So leaving the class and coming back gives no new runtime.
But the task can come back with new parameters. If it is asleep, its
wakeup checks the runtime left against them, with dl_entity_overflow().
If it is runnable, enqueue_dl_entity() starts a new period only if the
deadline has passed. The runtime left is not checked.
So a task can come back with a smaller runtime, and still run on the
old one. Admission control counts only the new one. Juri Lelli found
this case. On v7.4-rc1, a task of 50ms every 100ms came back through
SCHED_OTHER with 10ms every 100ms. It ran 39ms of the next 100ms.
Fix this by applying the wakeup rule to a task that enters the class
runnable, with update_dl_entity(). It starts a new period, or reduces
the runtime of a constrained task, if the runtime left does not fit the
new parameters. The task gets no more than a wakeup would give it.
The return_running_new_params case of deadline_bw_test, added later in
this series, tests this. It fails on v7.4-rc1 and passes with this
patch. The return_asleep_new_params case tests the wakeup, and passes
on both.
Fixes: a649f237db18 ("sched,dl: Fix sched class hopping CBS hole")
Reported-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/avHvPjz4dL0zNyGb@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
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 ffa8b946e804..b47c13c8714d 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -2723,6 +2723,14 @@ enqueue_dl_entity(struct sched_dl_entity *dl_se, int flags)
update_dl_entity(dl_se);
} else if (flags & ENQUEUE_REPLENISH) {
replenish_dl_entity(dl_se);
+ } else if ((flags & ENQUEUE_CLASS) && !is_dl_boosted(dl_se)) {
+ /*
+ * The task enters the class runnable. It may come back before
+ * its deadline, with the runtime left from older parameters.
+ * Check that runtime against the new parameters, as a wakeup
+ * does.
+ */
+ update_dl_entity(dl_se);
} else if ((flags & ENQUEUE_MOVE) &&
!is_dl_boosted(dl_se) &&
dl_time_before(dl_se->deadline, rq_clock(rq_of_dl_se(dl_se)))) {
--
2.47.3