Re: [PATCH v11 28/43] sched/deadline: Restore the owner's period at a deboost in the class
From: sashiko-bot
Date: Wed Nov 25 2026 - 20:57:24 EST
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@xxxxxxxxxxxx>
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@xxxxxxxxxxxx?part=28