[PATCH v11 35/43] sched/deadline: Cap the runtime left of a constrained task at dl_runtime
From: Mathieu Desnoyers
Date: Wed Nov 25 2026 - 20:12:09 EST
After sched_setattr() shortens the dl_deadline of a constrained
SCHED_DEADLINE task, its next wakeup can leave it more runtime than its
new dl_runtime.
sched_setattr() keeps the runtime and the absolute deadline of the
task: the new parameters take effect at the next period. At the next
wakeup, update_dl_entity() checks the runtime left against the new
parameters. For a constrained task, that check uses the density,
dl_runtime / dl_deadline:
- Commit 2317d5f1c349 ("sched/deadline: Use deadline instead of period
when calculating overflow") made dl_entity_overflow() compare with
it: "We care about if the runtime can make its deadline, not its
period."
- Commit 3effcb4247e7 ("sched/deadline: Use the revised wakeup rule for
suspending constrained dl tasks") cut the runtime of a constrained
task that overflows to density * laxity.
Both bound the runtime by dl_runtime only while the deadline is at
most dl_deadline ahead. After a change to a shorter dl_deadline, the
old deadline can be farther ahead. The check then keeps more runtime
than the new dl_runtime, or computes more.
For example, take a task of 50ms every 100ms, with 49ms left and its
deadline 99ms ahead. Changed to 8ms in 20ms every 100ms, it would wake
with 0.4 * 99ms = 39.6ms. Admission control already counts the new,
smaller bandwidth. So other deadline tasks could miss their deadlines.
An implicit task is not affected. Its check compares with its
bandwidth, which bounds the runtime for any deadline.
Fix this by keeping no more than dl_runtime before the check, for a
constrained task. A boosted task runs on the parameters of its donor,
and is left alone. The runtime is signed and can be negative there, so
compare it as signed.
The cases change_constrained_new_params and wake_constrained_new_params,
added to deadline_bw_test later in this series, test this. The first
changes a running task, the second a sleeping one.
wake_constrained_new_params fails without this patch, and passes with
it. change_constrained_new_params also needs "sched/deadline: Keep the
debt of a task across a change of parameters".
The Sashiko AI review of this series found this.
Fixes: 2317d5f1c349 ("sched/deadline: Use deadline instead of period when calculating overflow")
Fixes: 3effcb4247e7 ("sched/deadline: Use the revised wakeup rule for suspending constrained dl tasks")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 828923a77107..6e4edadddf24 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1648,6 +1648,19 @@ static void update_dl_entity(struct sched_dl_entity *dl_se)
{
struct rq *rq = rq_of_dl_se(dl_se);
+ /*
+ * The checks below let a constrained task keep up to its density
+ * times the time left to its deadline. After a change to a shorter
+ * dl_deadline, the deadline can be more than dl_deadline ahead, and
+ * that allows more than dl_runtime. So cap the runtime at dl_runtime
+ * first. An implicit task is checked against its bandwidth, which
+ * keeps it within its reservation for any deadline. A boosted task
+ * runs on the parameters of its donor.
+ */
+ if (!dl_is_implicit(dl_se) && !is_dl_boosted(dl_se) &&
+ dl_se->runtime > (s64)dl_se->dl_runtime)
+ dl_se->runtime = dl_se->dl_runtime;
+
if (dl_time_before(dl_se->deadline, rq_clock(rq)) ||
dl_entity_overflow(dl_se, rq_clock(rq))) {
--
2.47.3