From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>
Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v11 28/43] sched/deadline: Restore the owner's period at a deboost in the class
Date: Thu, 26 Nov 2026 01:57:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-234597@kernel.org> (raw)
In-Reply-To: <221d9b8a8508cdf0e5f3763606ca4c1faff6ee46.1795646914.git.mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] sched/deadline: missing dl_note_donor_refill() in
replenish_dl_entity()
- [Medium] sched/deadline: dl_note_donor_refill() holds boost when
deadline is 0
- [Medium] sched/deadline: running_bw under-accounting in dl_deboost()
for blocked task
- [Medium] sched/deadline: dl_deboost() starts or arms period for
sleeping task
--
commit 9f6872fae6d8bfd66c95f630e6a2c4067df9ded7
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Restore the owner's period at a deboost in the class
This commit saves a boosted task's own deadline and remaining runtime on
its first donor replenishment and restores or restarts its own period when
it is deboosted while staying in the deadline class.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 172fb2811d4a0..100cb4b5fdb6d 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -83,6 +83,53 @@ static inline int on_dl_rq(struct sched_dl_entity *dl_se)
> return !RB_EMPTY_NODE(&dl_se->rb_node);
> }
>
> +/*
> + * Start a period of the reservation of @dl_se now. The caller holds the rq
> + * lock and has updated the rq clock.
> + */
> +static inline void dl_start_own_period(struct sched_dl_entity *dl_se)
> +{
> + dl_se->deadline = rq_clock(rq_of_dl_se(dl_se)) + dl_se->dl_deadline;
> + dl_se->runtime = dl_se->dl_runtime;
> +}
> +
> +/*
> + * Put back the deadline and runtime saved when the boost was held, by
> + * dl_hold_refilled_boost(). If the task's own next period has started
> + * since, start a period of its own instead. Return true if the boost was
> + * held. The caller holds the rq lock and has updated the rq clock.
> + */
> +static inline bool dl_end_held_boost(struct sched_dl_entity *dl_se)
> +{
> + u64 now = rq_clock(rq_of_dl_se(dl_se));
> + u64 next = dl_se->own_deadline - dl_se->dl_deadline + dl_se->dl_period;
> +
> + if (!dl_se->dl_boost_held)
> + return false;
> + if (dl_time_before(now, next)) {
> + dl_se->deadline = dl_se->own_deadline;
> + dl_se->runtime = dl_se->own_runtime;
> + /*
> + * Past its own deadline, the task is in its constrained gap:
> + * it waits for its own next period. Give back no runtime, so
> + * that dl_deboost() throttles it. Before its deadline,
> + * dl_hold_refilled_boost() can keep runtime left, from a
> + * wakeup refill. Cap it at what the task's own density allows
> + * until its deadline, as update_dl_revised_wakeup() does.
> + */
> + if (!dl_time_before(now, dl_se->deadline))
> + dl_se->runtime = 0;
> + else if (dl_se->runtime > 0)
> + dl_se->runtime = min_t(s64, dl_se->runtime,
> + (dl_se->dl_density *
> + (dl_se->deadline - now)) >> BW_SHIFT);
> + } else {
> + dl_start_own_period(dl_se);
> + }
> + dl_se->dl_donor_refill = 0;
> + return true;
> +}
> +
> #ifdef CONFIG_RT_MUTEXES
> static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
> {
> @@ -93,12 +140,104 @@ static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
> {
> return pi_of(dl_se) != dl_se;
> }
> +
> +static void dl_hold_refilled_boost(struct sched_dl_entity *dl_se);
> +
> +/*
> + * Record that a replenishment changes the runtime of @dl_se while it is
> + * boosted. At the first refill, dl_hold_refilled_boost() saves the
> + * task's own deadline and runtime. Call this before the replenishment
> + * adds runtime or moves the deadline. A task with no parameters of its
> + * own at the first refill has no period to save. Later refills of the
> + * same boost save nothing, even if the task gets parameters meanwhile.
> + */
> +static inline void dl_note_donor_refill(struct sched_dl_entity *dl_se)
> +{
> + bool first;
> +
> + if (!is_dl_boosted(dl_se))
> + return;
> + first = !dl_se->dl_donor_refill;
> + dl_se->dl_donor_refill = 1;
> + if (first && dl_se->dl_runtime && !dl_se->dl_boost_held)
> + dl_hold_refilled_boost(dl_se);
> +}
[Severity: Medium]
Can dl_note_donor_refill() call dl_hold_refilled_boost() when
dl_se->deadline is still 0?
If an rt_mutex owner is boosted while sleeping on a non-PI waitqueue and is
given SCHED_DEADLINE parameters via sched_setattr() before waking up,
__setparam_dl() sets dl_se->dl_runtime > 0 while leaving dl_se->deadline at
0 because the task is not queued. When the task wakes up while still
boosted, update_dl_entity() -> replenish_dl_new_period() ->
dl_note_donor_refill() sees dl_se->dl_runtime != 0 and calls
dl_hold_refilled_boost(), saving own_deadline = 0 and own_runtime = 0 with
dl_boost_held = 1 even though the task has never started a period of its
own.
At deboost, if dl_time_before(now, next) holds in dl_end_held_boost(), it
restores dl_se->deadline = 0 and dl_se->runtime = 0 and throttles the task
instead of starting its first own period. With commit "sched/deadline:
Keep the debt of a task across a change of parameters" later in this
series, a subsequent sched_setattr() while running in this held boost sees
own_runtime == 0 and starts the task's own period while it is still
boosted, consuming its own deadline window while running for the donor.
Also, prior to commit "sched/deadline: Boost an owner that cannot run on
its own reservation" later in this series, another rt_mutex_setprio() on
the sleeping task evaluates dl_time_before(pi_task->dl.deadline, 0) as
false and deboosts it.
Checking dl_se->deadline != 0 before calling dl_hold_refilled_boost() would
leave only dl_donor_refill = 1 set so deboost starts a fresh own period.
> +
> +static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task);
> +static int start_dl_timer(struct sched_dl_entity *dl_se);
> +
> +/*
> + * End the boost of @dl_se, whose task stays in the class. Then bring the
> + * runtime and the deadline of the task back to its own parameters:
> + * - After a held boost, dl_end_held_boost() puts back the values that
> + * dl_hold_refilled_boost() saved. The time the task ran on the
> + * donor's refills is not charged to its own runtime. If that runtime
> + * is used up, throttle the task again until its own next period, or
> + * start that period if it has started.
> + * - After a refill of a task that had no parameters of its own at the
> + * refill, start a new period now.
> + * - Without a refill, the task keeps the runtime and the deadline of its
> + * own reservation.
> + * Do it now: the next enqueue is too late for a task blocked on another
> + * rt_mutex. The chain walk copies its deadline into its waiter node first.
> + *
> + * The caller holds the rq lock and the pi_lock of the task, and has
> + * updated the rq clock.
> + */
> +void dl_deboost(struct sched_dl_entity *dl_se)
> +{
> + struct task_struct *p = dl_task_of(dl_se);
> + bool held = dl_end_held_boost(dl_se);
> + bool own = held;
> +
> + if (dl_se->dl_donor_refill) {
> + dl_start_own_period(dl_se);
> + own = true;
> + }
> + /*
> + * If the task blocked while boosted, its inactive timer can be armed
> + * from the runtime and deadline of the donor's refills. Cancel it, and
> + * work out the 0-lag time again from the runtime and deadline the task
> + * gets back.
> + * If the timer handler is already running, it releases the
> + * bandwidth.
> + */
> + if (own && dl_se->dl_non_contending &&
> + hrtimer_try_to_cancel(&dl_se->inactive_timer) == 1) {
> + dl_se->dl_non_contending = 0;
> + put_task_struct(p);
> + task_non_contending(dl_se, true);
> + }
[Severity: Medium]
Can this leave rq->dl.running_bw under-accounted when a task blocks after a
donor refill and is deboosted while still blocked?
When a boosted deadline task blocks after a donor refill (with
dl_boost_held set), dequeue_dl_entity() calls task_non_contending() ->
dl_time_to_zerolag(), which compares the donor's refilled dl_se->runtime
against the task's own dl_runtime and dl_period:
kernel/sched/deadline.c:dl_time_to_zerolag() {
...
if (dl_se->runtime > mul_u64_u64_div_u64(left, dl_se->dl_runtime,
dl_se->dl_period)) {
return -1;
}
...
}
If the donor's remaining runtime exceeds what the task's own bandwidth
could leave, dl_time_to_zerolag() returns -1 (or an early 0-lag time whose
inactive_timer expires before the task's own 0-lag time), so
task_non_contending() calls sub_running_bw() immediately and leaves
dl_se->dl_non_contending == 0. When dl_deboost() later restores the task's
exhausted own_runtime and own_deadline while the task is still blocked,
dl_se->dl_non_contending is 0, so the task's dl_bw is not added back to
rq->dl.running_bw and inactive_timer is not armed for its true 0-lag time,
allowing GRUB tasks on the runqueue to reclaim bandwidth the task already
used in its period.
> + dl_drop_boost(dl_se);
> +
> + /*
> + * A held boost can end before the task's own next period, with its
> + * own runtime used up. Throttle the task until that period. If
> + * start_dl_timer() finds that the period has already started, start
> + * it now.
> + */
> + if (held && dl_se->runtime <= 0) {
> + struct rq *rq = task_rq(p);
> +
> + dl_se->dl_throttled = 1;
> + if (!start_dl_timer(dl_se)) {
> + dl_se->dl_throttled = 0;
> + dl_start_own_period(dl_se);
> + } else if (task_current_donor(rq, p)) {
> + resched_curr(rq);
> + }
> + }
> +}
[Severity: Medium]
Does dl_deboost() start a new period (or arm dl_timer to replenish one)
while a constrained-deadline task is sleeping on a non-PI waitqueue?
If a constrained-deadline task (dl_deadline < dl_period) holding an
rt_mutex is deboosted while sleeping (!task_on_rq_queued(p) &&
!p->pi_blocked_on), dl_end_held_boost() and dl_deboost() either call
dl_start_own_period() immediately or arm dl_timer via start_dl_timer(),
which replenishes and starts a period in dl_task_timer() while the task
remains asleep. Because that period ticks while the task is sleeping,
waking up before the deadline causes update_dl_revised_wakeup() to trim its
runtime for the time spent asleep, and waking up in the constrained gap
between the deadline and the next period causes dl_check_constrained_dl()
to throttle the task until the following period even though it never ran.
Commit "sched/deadline: Keep the debt of a task across a change of
parameters" later in this series avoids starting a period or arming
dl_timer for an asleep constrained-deadline task in dl_setattr_place() so
that wakeup either throttles it until next or starts a fresh period on
wakeup.
[ ... ]
> @@ -1231,8 +1373,10 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> dl_se->deadline = rq_clock(rq);
> dl_se->runtime = 0;
> }
> - if (dl_se->runtime < 0 || dl_se->dl_yielded)
> + if (dl_se->runtime < 0 || dl_se->dl_yielded) {
> dl_se->runtime = 0;
> + dl_note_donor_refill(dl_se);
> + }
> dl_se->dl_yielded = 0;
> dl_se->dl_throttled = 0;
> return;
[Severity: Medium]
When a boosted task with !dl_se->dl_deadline is replenished after its
donor's parameters were cleared (!runtime || !deadline || !period), does
this miss calling dl_note_donor_refill(dl_se)?
The !dl_se->dl_deadline block sets dl_se->deadline = rq_clock(rq) and
dl_se->runtime = 0 without calling dl_note_donor_refill(dl_se), and zeroing
dl_se->runtime prevents the following dl_se->runtime < 0 check from calling
it either. If sched_setattr() then gives the task SCHED_DEADLINE
parameters during the boost, dl_deboost() sees both dl_boost_held == 0 and
dl_donor_refill == 0 and leaves the task with runtime == 0 and the stale
rq_clock(rq) deadline instead of starting its own period (or a subsequent
donor refill sees first == true and saves that artificial deadline and 0
runtime as own_deadline and own_runtime).
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795646914.git.mathieu.desnoyers@efficios.com?part=28
next prev parent reply other threads:[~2026-11-26 1:57 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 1:07 [PATCH v11 00/43] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 01/43] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 02/43] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 03/43] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 04/43] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 05/43] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 06/43] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 07/43] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 08/43] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 09/43] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 10/43] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 11/43] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 12/43] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 13/43] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 14/43] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 15/43] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-26 1:38 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 16/43] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-26 1:35 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 17/43] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-26 1:41 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 18/43] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 19/43] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 20/43] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 21/43] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-26 1:32 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 22/43] rtmutex: Do not stop the chain walk at an owner whose top waiter changed Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 23/43] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 24/43] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 25/43] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-11-26 1:35 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 26/43] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-11-26 1:44 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 27/43] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 28/43] sched/deadline: Restore the owner's period at a deboost in the class Mathieu Desnoyers
2026-11-26 1:57 ` sashiko-bot [this message]
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 29/43] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 30/43] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-26 1:53 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 31/43] sched/deadline: Restore the owner's period at a deboost out of the class Mathieu Desnoyers
2026-11-26 1:50 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 32/43] sched/deadline: Start a period for a task requeued onto an rt_mutex Mathieu Desnoyers
2026-11-26 1:57 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 33/43] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 34/43] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-26 1:45 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 35/43] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 36/43] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 37/43] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-11-26 2:16 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 38/43] sched/deadline: Boost an owner that cannot run on its own reservation Mathieu Desnoyers
2026-11-26 2:17 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 39/43] sched/deadline: Boost an owner throttled after its waiter blocked Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 40/43] sched/deadline: Reschedule a running task throttled at its enqueue Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 41/43] sched/deadline: Run a boost held at its first refill on a donor period Mathieu Desnoyers
2026-11-26 2:02 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 42/43] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-11-26 2:01 ` sashiko-bot
2026-11-27 13:48 ` Mathieu Desnoyers
2026-11-26 1:08 ` [PATCH v11 43/43] 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=sashiko-outbox-234597@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.