[PATCH v13 28/36] sched/deadline: Record the start of the period

From: Mathieu Desnoyers

Date: Tue Dec 01 2026 - 12:46:54 EST


dl_next_period() computes the next period from the deadline:
deadline - dl_deadline + dl_period. After sched_setattr() changes
dl_deadline, this subtracts the new dl_deadline from a deadline set
with the old one. The result is a wrong next period.

The next patch fits the period in progress to new parameters at
sched_setattr(). To do that, it needs the start of the period.

Add the field period_start. Set it wherever a period starts, and clear
it with the deadline. Nothing reads it yet: no functional change.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
include/linux/sched.h | 1 +
kernel/sched/deadline.c | 11 +++++++++--
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 689952d7fd15..ccd972ca44e4 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -661,6 +661,7 @@ struct sched_dl_entity {
*/
s64 runtime; /* Remaining runtime for this instance */
u64 deadline; /* Absolute deadline for this instance */
+ u64 period_start; /* Absolute start of this instance */
unsigned int flags; /* Specifying the scheduler behaviour */

/*
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 9754b72af895..5cc4f36c5146 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1169,7 +1169,8 @@ static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se,
struct rq *rq)
{
/* for non-boosted task, pi_of(dl_se) == dl_se */
- dl_se->deadline = rq_clock(rq) + pi_of(dl_se)->dl_deadline;
+ dl_se->period_start = rq_clock(rq);
+ dl_se->deadline = dl_se->period_start + pi_of(dl_se)->dl_deadline;
dl_se->runtime = pi_of(dl_se)->dl_runtime;

/*
@@ -1268,6 +1269,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
WARN_ON_ONCE(!is_dl_boosted(dl_se));
if (!dl_se->dl_deadline) {
dl_se->deadline = rq_clock(rq);
+ dl_se->period_start = dl_se->deadline;
dl_se->runtime = 0;
}
if (dl_se->runtime < 0 || dl_se->dl_yielded)
@@ -1289,7 +1291,8 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
*/
if (dl_se->dl_deadline == 0 ||
(dl_se->dl_defer_armed && dl_entity_overflow(dl_se, rq_clock(rq)))) {
- dl_se->deadline = rq_clock(rq) + deadline;
+ dl_se->period_start = rq_clock(rq);
+ dl_se->deadline = dl_se->period_start + deadline;
dl_se->runtime = runtime;
}

@@ -1304,6 +1307,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
*/
while (dl_se->runtime <= 0) {
dl_se->deadline += period;
+ dl_se->period_start += period;
dl_se->runtime += runtime;
}

@@ -2446,6 +2450,7 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio

dl_se->runtime = 0;
dl_se->deadline = 0;
+ dl_se->period_start = 0;

dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime);
dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime);
@@ -4707,6 +4712,7 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
*/
if (!p->dl.dl_runtime) {
p->dl.deadline = 0;
+ p->dl.period_start = 0;
p->dl.runtime = 0;
}

@@ -5206,6 +5212,7 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
dl_se->dl_density = 0;

dl_se->deadline = 0;
+ dl_se->period_start = 0;
dl_se->runtime = 0;

dl_se->dl_throttled = 0;
--
2.47.3