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 v6 10/37] sched/deadline: Reset the donor's runtime at a deboost in the class
Date: Mon, 16 Nov 2026 19:38:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-217586@kernel.org> (raw)
In-Reply-To: <20261116190549.230119-11-mathieu.desnoyers@efficios.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] sched/deadline: implicit declaration of
dl_note_donor_refill()
- [Medium] sched/deadline: rt_mutex_setprio() skips dl_deboost() on
donor change
- [Medium] sched/deadline: donor runtime kept when leaving
dl_sched_class
- [Medium] sched/deadline: missing dl_note_donor_refill() on cleared
donor
- [Low] sched/deadline: __dl_clear_params() fails to clear
dl_donor_refill
--
commit 25ef3546a7248ed2f828d8c39dc34ecf7474dcc4
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
sched/deadline: Reset the donor's runtime at a deboost in the class
This commit adds a dl_donor_refill flag to struct sched_dl_entity to track
when a priority-inherited SCHED_DEADLINE task has been replenished from its
donor's reservation, resetting its period on in-class deboost.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 5ed660f099a55..a22df8b43a1a7 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7834,16 +7834,26 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
> p->dl.pi_se = pi_task->dl.pi_se;
> scope->flags |= ENQUEUE_REPLENISH;
> } else {
> - p->dl.pi_se = &p->dl;
> + dl_deboost(&p->dl);
> + /*
> + * dl_deboost() can start a new period. Its
> + * deadline can then be after the top waiter's.
> + * Boost the task again then.
> + */
> + if (pi_task && dl_prio(pi_task->prio) &&
> + dl_entity_preempt(&pi_task->dl, &p->dl)) {
> + p->dl.pi_se = pi_task->dl.pi_se;
> + scope->flags |= ENQUEUE_REPLENISH;
> + }
> }
[Severity: Medium]
When a SCHED_DEADLINE task was refilled from an earlier donor and now switches
to a new top waiter pi_task, doesn't the outer dl_entity_preempt(&pi_task->dl,
&p->dl) check compare pi_task against the old donor's postponed deadline
before dl_deboost() can reset p->dl to its own reservation?
If the first donor's refill pushed p->dl.deadline past pi_task->dl.deadline,
rt_mutex_setprio() takes the first branch and skips dl_deboost(). Because
p->dl.dl_deadline is non-zero and p->dl.runtime > 0, replenish_dl_entity()
leaves the first donor's remaining runtime and postponed deadline in place
after the unlock. Calling dl_deboost(&p->dl) unconditionally when
dl_prio(p->normal_prio) before testing dl_entity_preempt(&pi_task->dl, &p->dl)
would reset the period first and then boost from the new waiter if needed.
> } else if (rt_prio(prio)) {
> if (dl_prio(oldprio))
> - p->dl.pi_se = &p->dl;
> + dl_drop_boost(&p->dl);
> if (oldprio < prio)
> scope->flags |= ENQUEUE_HEAD;
> } else {
> if (dl_prio(oldprio))
> - p->dl.pi_se = &p->dl;
> + dl_drop_boost(&p->dl);
> if (rt_prio(oldprio))
> p->rt.timeout = 0;
> }
[Severity: Medium]
What happens if a task with its own deadline parameters (p->dl.dl_runtime != 0)
is refilled from a donor and then leaves dl_sched_class at deboost, for
instance after changing its policy via sched_setattr() while boosted (or being
boosted again before its 0-lag timer fires)?
sched_change_begin() runs switched_from_dl() before dl_drop_boost() clears
dl_donor_refill, and switched_from_dl() only resets deadline and runtime when
!p->dl.dl_runtime:
kernel/sched/deadline.c:switched_from_dl() {
if (task_on_rq_queued(p) && p->dl.dl_runtime)
task_non_contending(&p->dl, false);
...
if (!p->dl.dl_runtime) {
p->dl.deadline = 0;
p->dl.runtime = 0;
}
}
task_non_contending() then computes zerolag_time from the donor's refilled
deadline and runtime combined with p's own dl_period and dl_runtime. If the
donor's remaining runtime makes zerolag_time negative, task_non_contending()
immediately clears p's parameters even though p already exhausted its own
budget in this period; otherwise p keeps the donor's runtime and deadline
with dl_donor_refill cleared if it returns to SCHED_DEADLINE before the
inactive timer fires.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index dd48f74412b87..1f3da0e0a698c 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -93,6 +93,38 @@ static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
> {
> return pi_of(dl_se) != dl_se;
> }
> +
> +/*
> + * Record that @dl_se had its runtime refilled from the parameters of its
> + * donor, if it is boosted.
> + */
> +static inline void dl_note_donor_refill(struct sched_dl_entity *dl_se)
> +{
> + if (is_dl_boosted(dl_se))
> + dl_se->dl_donor_refill = 1;
> +}
> +
> +/*
> + * End the boost of @dl_se, whose task stays in the class. If the boost
> + * refilled its runtime from the donor's parameters, start a new period
> + * 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. Without a refill, the task keeps the runtime and the deadline
> + * of its own reservation.
> + *
> + * 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 rq *rq = rq_of_dl_se(dl_se);
> +
> + if (dl_se->dl_donor_refill) {
> + dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline;
> + dl_se->runtime = dl_se->dl_runtime;
> + }
> + dl_drop_boost(dl_se);
> +}
> #else /* !CONFIG_RT_MUTEXES: */
> static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
> {
[Severity: Medium]
Does this break the build when CONFIG_RT_MUTEXES is disabled?
dl_note_donor_refill() is defined inside #ifdef CONFIG_RT_MUTEXES with no
stub in the #else branch, but replenish_dl_new_period() and
replenish_dl_entity() call it unconditionally.
[ ... ]
> @@ -842,11 +875,15 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> (dl_se->dl_defer_armed && dl_entity_overflow(dl_se, rq_clock(rq)))) {
> dl_se->deadline = rq_clock(rq) + deadline;
> dl_se->runtime = runtime;
> + dl_note_donor_refill(dl_se);
> }
>
> if (dl_se->dl_yielded && dl_se->runtime > 0)
> dl_se->runtime = 0;
>
> + if (dl_se->runtime <= 0)
> + dl_note_donor_refill(dl_se);
> +
[Severity: Medium]
Should the early return when !runtime earlier in replenish_dl_entity() also
call dl_note_donor_refill(dl_se)?
kernel/sched/deadline.c:replenish_dl_entity() {
if (unlikely(!runtime)) {
WARN_ON_ONCE(!is_dl_boosted(dl_se));
dl_se->dl_yielded = 0;
dl_se->dl_throttled = 0;
return;
}
}
When a donor leaves the class and its parameters are cleared before the lock
owner is deboosted, this path keeps the owner runnable after it exhausted its
runtime, and update_curr_dl_se() continues driving dl_se->runtime negative.
Without dl_donor_refill set, dl_deboost() will not start a new period and the
boosted execution is charged against the owner's own reservation (or leaves
deadline at 0 if the owner entered SCHED_DEADLINE while boosted).
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 92134ce326a49..d87296abec4c2 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -356,6 +356,16 @@ extern int sched_dl_global_validate(void);
> extern void sched_dl_do_global(void);
> extern int sched_dl_overflow(struct task_struct *p, int policy, const struct sched_attr *attr);
> extern void __setparam_dl(struct task_struct *p, const struct sched_attr *attr);
> +#ifdef CONFIG_RT_MUTEXES
> +extern void dl_deboost(struct sched_dl_entity *dl_se);
> +
> +/* End the boost of @dl_se. The caller holds the rq lock of its task. */
> +static inline void dl_drop_boost(struct sched_dl_entity *dl_se)
> +{
> + dl_se->pi_se = dl_se;
> + dl_se->dl_donor_refill = 0;
> +}
> +#endif
[Severity: Low]
Should __dl_clear_params() also clear dl_donor_refill (or call
dl_drop_boost()) instead of only setting dl_se->pi_se = dl_se?
kernel/sched/deadline.c:__dl_clear_params() {
...
dl_se->dl_defer_running = 0;
dl_se->dl_defer_armed = 0;
#ifdef CONFIG_RT_MUTEXES
dl_se->pi_se = dl_se;
#endif
}
If a task forks while boosted and refilled by a donor, dup_task_struct()
copies dl_donor_refill = 1 into the child and __sched_fork() ->
init_dl_entity() -> __dl_clear_params() leaves it set, which would cause an
unintended period reset if the child later becomes SCHED_DEADLINE and passes
through dl_deboost().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@efficios.com?part=10
next prev parent reply other threads:[~2026-11-16 19:38 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 19:05 [PATCH v6 00/37] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 01/37] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 02/37] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 03/37] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 04/37] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 05/37] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-16 19:30 ` sashiko-bot
2026-11-17 14:14 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 06/37] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 07/37] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 08/37] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-16 19:42 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 09/37] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 10/37] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-16 19:38 ` sashiko-bot [this message]
2026-11-17 14:15 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 11/37] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 12/37] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 13/37] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 14/37] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 15/37] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 16/37] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-16 19:44 ` sashiko-bot
2026-11-17 14:15 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 17/37] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 18/37] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 19/37] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 20/37] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 21/37] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-16 19:31 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 22/37] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 23/37] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-16 19:56 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 24/37] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-16 20:01 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 25/37] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-16 19:47 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 26/37] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-16 19:50 ` sashiko-bot
2026-11-17 14:16 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 27/37] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-16 19:51 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 28/37] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-16 20:08 ` sashiko-bot
2026-11-17 14:17 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 29/37] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 30/37] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 31/37] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-16 20:12 ` sashiko-bot
2026-11-17 14:18 ` Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 32/37] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-16 20:08 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 33/37] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-16 20:04 ` sashiko-bot
2026-11-16 19:05 ` [PATCH v6 34/37] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 35/37] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 36/37] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-16 19:05 ` [PATCH v6 37/37] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers
2026-11-16 19:49 ` sashiko-bot
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-217586@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.