The Linux Kernel Mailing List
 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 07/16] sched/deadline: Do not lose a throttled task switched out and back
Date: Wed, 18 Nov 2026 20:31:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-221937@kernel.org> (raw)
In-Reply-To: <e58738e763010632a024a6874a97f1d980b90ce3.1795031605.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] sched/deadline: stale dl_timer and deadline after
  __dl_clear_params() [1]
--

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

sched/deadline: Do not lose a throttled task switched out and back

This commit replenishes a throttled SCHED_DEADLINE task in dl_task_timer()
if the task has switched to another scheduling policy, so that it can be
enqueued if it switches back to SCHED_DEADLINE before its 0-lag time.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index b614d5fc1a1ac..e4d7cbf4861de 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1233,9 +1233,18 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
>  	/*
>  	 * The task might have changed its scheduling policy to something
>  	 * different than SCHED_DEADLINE (through switched_from_dl()).
> +	 * It keeps its parameters until its 0-lag time. If it comes back
> +	 * before then, nothing else would lift its throttle. So replenish
> +	 * it now, as the !queued case below does. Its return enqueues it.
>  	 */
> -	if (!dl_task(p))
> +	if (!dl_task(p)) {
> +		if (dl_se->dl_throttled && !is_dl_boosted(dl_se)) {
> +			sched_clock_tick();
> +			update_rq_clock(rq);
> +			replenish_dl_entity(dl_se);
> +		}
>  		goto unlock;
> +	}

[Severity: High]
This problem wasn't introduced by this patch, but in the opposite order
where the 0-lag time elapses before dl_se->dl_timer fires [1], does
__dl_clear_params() leave a stale dl_se->dl_timer armed along with stale
dl_se->deadline and dl_se->runtime values?

When a task calls sched_yield() with remaining runtime (or a
constrained-deadline task overruns slightly), its 0-lag time is earlier
than dl_next_period(dl_se).  If the task then switches out of
SCHED_DEADLINE, task_non_contending() or inactive_task_timer() calls
__dl_clear_params(), which clears dl_se->dl_throttled without cancelling
dl_se->dl_timer or resetting dl_se->deadline and dl_se->runtime:

kernel/sched/deadline.c:__dl_clear_params() {
	dl_se->dl_runtime		= 0;
	dl_se->dl_deadline		= 0;
	dl_se->dl_period		= 0;
	dl_se->flags			= 0;
	dl_se->dl_bw			= 0;
	dl_se->dl_density		= 0;

	dl_se->dl_throttled		= 0;
	dl_se->dl_yielded		= 0;
    ...
}

If the task switches back to SCHED_DEADLINE before the old period ends,
enqueue_dl_entity() with ENQUEUE_MOVE sees dl_se->deadline still in the
future and skips setup_new_dl_entity(), running the task with stale
runtime and deadline values.  If the task then throttles under its new
reservation while the old dl_se->dl_timer is still queued,
start_dl_timer() sees hrtimer_is_queued(&dl_se->dl_timer) and skips
reprogramming it, delaying replenishment until the old timer expires.

[1] https://sashiko.dev/#/bug/linux-5f16aeeb-544a-4da3-a8a9-3a7be85e8892

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

  reply	other threads:[~2026-11-18 20:31 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:06 [PATCH 00/16] sched/deadline: first bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 01/16] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 02/16] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 03/16] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 04/16] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-18 20:23   ` sashiko-bot
2026-11-18 21:08     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 05/16] sched/deadline: Refuse dl_server debugfs writes while the rq is offline Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 06/16] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-18 20:17   ` sashiko-bot
2026-11-18 21:09     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 07/16] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-18 20:31   ` sashiko-bot [this message]
2026-11-18 21:09     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 08/16] sched/deadline: Do not replenish a boost from cleared parameters Mathieu Desnoyers
2026-11-18 20:35   ` sashiko-bot
2026-11-18 21:10     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 09/16] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-18 20:38   ` sashiko-bot
2026-11-18 21:10     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 10/16] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 11/16] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 12/16] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-18 20:46   ` sashiko-bot
2026-11-18 21:11     ` Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 13/16] sched/deadline: Check SCHED_DEADLINE affinity under the rq lock Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 14/16] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 15/16] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-18 20:06 ` [PATCH 16/16] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers
2026-11-18 21:04   ` sashiko-bot
2026-11-18 21:12     ` 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-221937@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