Linux real-time development
 help / color / mirror / Atom feed
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 v9 27/33] sched/deadline: Start a period at a deboost out of the class
Date: Fri, 20 Nov 2026 14:27:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-225366@kernel.org> (raw)
In-Reply-To: <b0c0b935fc2c40dbd924975c77e3a0132def0abf.1795181240.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: uncanceled inactive_timer on asleep deboost
  in dl_deboost()
--

commit 7130bcba22c9d38507c258ff46870cd5112cbc8d
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

sched/deadline: Start a period at a deboost out of the class

This commit starts a new period of the task's own reservation in
switched_from_dl() and cancels any armed inactive timer when a task that
was refilled from a donor during a boost leaves SCHED_DEADLINE.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index c57bbc7a9536a..4c46a7aa27096 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -83,6 +83,16 @@ 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;
> +}
> +
>  #ifdef CONFIG_RT_MUTEXES
>  static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
>  {
> @@ -117,12 +127,8 @@ static inline void dl_note_donor_refill(struct sched_dl_entity *dl_se)
>   */
>  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;
> -	}
> +	if (dl_se->dl_donor_refill)
> +		dl_start_own_period(dl_se);
>  	dl_drop_boost(dl_se);
>  }

[ ... ]

> @@ -4629,6 +4637,19 @@ void dl_clear_root_domains(void)
>  
>  static void switched_from_dl(struct rq *rq, struct task_struct *p)
>  {
> +	bool own_period = p->dl.dl_runtime && p->dl.dl_donor_refill;
> +
> +	/*
> +	 * The boost of a task with parameters of its own ends, and the task
> +	 * leaves the class. If the boost refilled its runtime from the
> +	 * donor's parameters, its runtime and deadline are not those of its
> +	 * reservation. task_non_contending() would mix them with its own
> +	 * dl_runtime and dl_period. Start a period of its own instead, as
> +	 * dl_deboost() does. Its 0-lag time is then now, or has passed.
> +	 */
> +	if (own_period)
> +		dl_start_own_period(&p->dl);
> +
>  	/*
>  	 * task_non_contending() can start the "inactive timer" (if the 0-lag
>  	 * time is in the future). If the task switches back to dl before
> @@ -4660,6 +4681,18 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
>  		if (p->dl.dl_non_contending)
>  			sub_running_bw(&p->dl, &rq->dl);
>  		sub_rq_bw(&p->dl, &rq->dl);
> +		/*
> +		 * The task blocked while boosted, after a refill from the
> +		 * donor. The timer armed then mixes the donor's runtime and
> +		 * deadline with the task's own parameters. Cancel it, and
> +		 * work out the 0-lag time of the period just started below.
> +		 * If the handler runs already, it releases the bandwidth.
> +		 */
> +		if (own_period && p->dl.dl_non_contending &&
> +		    hrtimer_try_to_cancel(&p->dl.inactive_timer) == 1) {
> +			p->dl.dl_non_contending = 0;
> +			put_task_struct(p);
> +		}

[Severity: Medium]
Should dl_deboost() also cancel inactive_timer and subtract running_bw
when a donor-refilled task is deboosted while asleep in SCHED_DEADLINE?

When a boosted SCHED_DEADLINE task blocks after a donor refill,
dequeue_dl_entity() -> task_non_contending() arms inactive_timer from the
mix of the donor's runtime/deadline and the task's own parameters, and
sets dl_non_contending = 1.  If the boost ends while the task is still
asleep and remaining in SCHED_DEADLINE (for example, when the donor waiter
times out on the rt_mutex), rt_mutex_setprio() calls dl_deboost().
dl_deboost() starts a fresh period of the task's own reservation (whose
0-lag time is now) and clears dl_donor_refill via dl_drop_boost(), but
leaves the donor-mixed inactive_timer armed and dl_non_contending set.

This keeps rq->dl.running_bw inflated by the sleeping task's dl_bw until
the donor-mixed timer expires.  Furthermore, if the sleeping task later
leaves SCHED_DEADLINE before that timer fires, switched_from_dl() sees
dl_donor_refill == 0 (own_period == false) and dl_non_contending == 1, so
it neither cancels inactive_timer nor calls task_non_contending() to
release the task's bandwidth from the root domain's total_bw.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795181240.git.mathieu.desnoyers@efficios.com?part=27

  reply	other threads:[~2026-11-20 14:27 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:55 [PATCH v9 00/33] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 01/33] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 02/33] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 03/33] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 04/33] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 05/33] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 06/33] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 07/33] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 08/33] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 09/33] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 10/33] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 11/33] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 12/33] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 13/33] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 14/33] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 15/33] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-11-20 14:12   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 16/33] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-11-20 14:31   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 17/33] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-11-20 14:32   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 18/33] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 19/33] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 20/33] rtmutex: Continue the chain walk when a waiter's deadline donor changes Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 21/33] rtmutex: Continue the walk when the owner's top waiter changes lock Mathieu Desnoyers
2026-11-20 14:20   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 22/33] selftests/sched: Test the rtmutex chain walk in deadline_bw_test Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 23/33] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 24/33] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 25/33] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 26/33] sched/deadline: Start a period for a task that enters the class blocked Mathieu Desnoyers
2026-11-20 14:39   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 27/33] sched/deadline: Start a period at a deboost out of the class Mathieu Desnoyers
2026-11-20 14:27   ` sashiko-bot [this message]
2026-11-20 13:55 ` [PATCH v9 28/33] selftests/sched: Test deadline boosts in deadline_bw_test Mathieu Desnoyers
2026-11-20 14:26   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 29/33] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 30/33] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 31/33] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-11-20 13:55 ` [PATCH v9 32/33] sched/deadline: Check the runtime of a task whose parameters change Mathieu Desnoyers
2026-11-20 14:58   ` sashiko-bot
2026-11-20 13:55 ` [PATCH v9 33/33] selftests/sched: Test parameter changes in deadline_bw_test 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-225366@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox