From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
tglx@kernel.org, anna-maria@linutronix.de, frederic@kernel.org,
will@kernel.org, boqun@kernel.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, kprateek.nayak@amd.com,
luca.abeni@santannapisa.it, tommaso.cucinotta@gmail.com,
mathieu.poirier@linaro.org, longman@redhat.com,
ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org,
mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de,
clrkwllms@kernel.org, parri.andrea@gmail.com,
m.szyprowski@samsung.com, kayracizmeci@gmail.com,
weihengqiuu@gmail.com, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-rt-devel@lists.linux.dev, oleg@redhat.com,
brauner@kernel.org, stable@vger.kernel.org
Subject: [PATCH v14 31/39] sched/deadline: Record the start of the period
Date: Thu, 3 Dec 2026 09:58:45 -0500 [thread overview]
Message-ID: <6b1869882be16d6d09413804a673ebb3d97aaddb.1796296313.git.mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <cover.1796296313.git.mathieu.desnoyers@efficios.com>
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. It also
makes dl_next_period() count from that start.
Add the field period_start. Set it wherever a period starts. Clear it
with the deadline. dl_release_params() keeps the deadline of a
constrained task: keep period_start there too. Nothing reads it yet:
no functional change.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: stable@vger.kernel.org
---
include/linux/sched.h | 1 +
kernel/sched/deadline.c | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 69a9a9e5cc80..32ae977a2821 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 58fc1c6c4117..820e71ee7fdf 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1121,7 +1121,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;
/*
@@ -1220,6 +1221,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)
@@ -1241,7 +1243,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;
}
@@ -1256,6 +1259,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;
}
@@ -2398,6 +2402,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);
@@ -4675,6 +4680,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;
}
@@ -5196,6 +5202,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;
@@ -5224,12 +5231,16 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
*/
static void dl_release_params(struct sched_dl_entity *dl_se)
{
+ u64 period_start = dl_se->period_start;
u64 deadline = dl_se->deadline;
bool constrained = !dl_is_implicit(dl_se);
__dl_clear_params(dl_se);
- if (constrained)
+ if (constrained) {
+ /* Keep the start of the period with its deadline. */
+ dl_se->period_start = period_start;
dl_se->deadline = deadline;
+ }
}
void init_dl_entity(struct sched_dl_entity *dl_se)
--
2.47.3
next prev parent reply other threads:[~2026-12-03 14:59 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 14:58 [PATCH v14 00/39] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 01/39] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-03 15:44 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 02/39] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-03 15:29 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 03/39] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 04/39] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 06/39] sched/deadline: Admit a returning task without the bandwidth it holds Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 07/39] sched/deadline: Leave an active task alone in the inactive timer Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task Mathieu Desnoyers
2026-12-03 15:45 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 09/39] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 15:49 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 10/39] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-03 15:57 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 11/39] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 12/39] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-03 16:20 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 13/39] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-03 16:10 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 14/39] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-03 16:10 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 15/39] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 16/39] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-03 16:22 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 17/39] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 18/39] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 19/39] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 20/39] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 21/39] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 22/39] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 23/39] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 24/39] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 25/39] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 26/39] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:25 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 27/39] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-03 17:39 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 29/39] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 30/39] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-03 14:58 ` Mathieu Desnoyers [this message]
2026-12-03 17:42 ` [PATCH v14 31/39] sched/deadline: Record the start of the period sashiko-bot
2026-12-03 14:58 ` [PATCH v14 32/39] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 33/39] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-03 17:56 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 34/39] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-03 14:58 ` [PATCH v14 35/39] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-03 18:01 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-03 18:14 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 37/39] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-03 18:05 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 38/39] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-03 18:07 ` sashiko-bot
2026-12-03 14:58 ` [PATCH v14 39/39] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b1869882be16d6d09413804a673ebb3d97aaddb.1796296313.git.mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=anna-maria@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kayracizmeci@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=luca.abeni@santannapisa.it \
--cc=m.szyprowski@samsung.com \
--cc=mathieu.poirier@linaro.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=tommaso.cucinotta@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=weihengqiuu@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®