From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org
Cc: linux-kernel@vger.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
tglx@kernel.org, will@kernel.org, boqun@kernel.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, luca.abeni@santannapisa.it,
mathieu.poirier@linaro.org, longman@redhat.com,
ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org,
mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de,
clrkwllms@kernel.org, parri.andrea@gmail.com,
m.szyprowski@samsung.com, kayracizmeci@gmail.com,
weihengqiuu@gmail.com, cgroups@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev,
stable@vger.kernel.org
Subject: [PATCH 10/16] sched/deadline: Release the bandwidth of a task that leaves the class asleep
Date: Wed, 18 Nov 2026 15:06:35 -0500 [thread overview]
Message-ID: <413baa5f50669ae464f504dbafeb504dd9b6ef6c.1795031605.git.mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <cover.1795031605.git.mathieu.desnoyers@efficios.com>
A task that leaves SCHED_DEADLINE while it is not queued can keep its
bandwidth in total_bw until the next rebuild of the root domains.
Repeated, this fills total_bw up to the admission limit. Then
sched_setattr(SCHED_DEADLINE) and CPU offlining fail with EBUSY.
A task that leaves the class keeps its bandwidth until its 0-lag time.
Releasing it earlier would allow temporary overloads. For a queued task,
switched_from_dl() calls task_non_contending(). It releases the
bandwidth if the 0-lag time is past. Otherwise it arms the inactive
timer, which releases it then. For a task that is not queued,
switched_from_dl() relies on the timer armed when the task blocked.
But the timer is not always pending when the task leaves the class:
- The task blocked after its 0-lag time. The timer was not armed.
- The timer fired while the task was still in the class. It only
removed running_bw.
- The task was woken up on another CPU and is not enqueued there yet.
The wakeup cancelled the timer.
- The task came back to the class asleep. switched_to_dl() cancelled
the timer.
Then nothing releases total_bw.
Fix this in switched_from_dl(). For a task that is not queued and has
no timer pending, call task_non_contending(), as for a queued task. It
arms the timer if the 0-lag time is ahead. Otherwise it releases the
bandwidth now and clears the parameters, as inactive_task_timer() does.
Clearing the parameters keeps later paths from releasing the bandwidth
again:
- A timer handler that already started finds a dl_bw of 0.
- The deboost of a later priority inheritance boost finds no
parameters.
An owner that the task boosts as a waiter can find the parameters
cleared too. "sched/deadline: Do not replenish a boost from cleared
parameters" handles this, so a backport needs it first. Without it, the
owner's CPU can lock up as soon as the waiter leaves the class.
Juri Lelli's first fix, since dropped from tip, released the bandwidth
here without clearing dl_bw. The bandwidth of a boosted task was then
released twice.
Juri Lelli suggested the call to task_non_contending() in review.
The Sashiko AI review of this series found the two cases with the 0-lag
time ahead. deadline_switch_test, added later in this series, tests
the release in asleep_round_trip.
Fixes: 209a0cbda7a0 ("sched/deadline: Improve the tracking of active utilization")
Reported-by: Tejun Heo <tj@kernel.org>
Closes: https://lore.kernel.org/all/2b5fb3f22bca6aa383be8f4781923392@kernel.org/
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Juri Lelli <juri.lelli@redhat.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20261103-b4-sched-dl-bw-fixes-v1-2-dd761fe005b4@redhat.com/
---
kernel/sched/deadline.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index d6d2657dcddd..f0e03f97fd82 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3595,6 +3595,14 @@ 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);
+ /*
+ * Without an armed timer, nothing releases total_bw. Do as for
+ * a queued task: arm the timer if the 0-lag time is ahead, or
+ * release the bandwidth and clear the parameters now. Call
+ * task_non_contending() after sub_rq_bw(), which needs dl_bw.
+ */
+ if (!p->dl.dl_non_contending)
+ task_non_contending(&p->dl, false);
}
/*
--
2.47.3
next prev parent reply other threads:[~2026-11-18 20:06 UTC|newest]
Thread overview: 23+ 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 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 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
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 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 20:06 ` Mathieu Desnoyers [this message]
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 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
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=413baa5f50669ae464f504dbafeb504dd9b6ef6c.1795031605.git.mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kayracizmeci@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=luca.abeni@santannapisa.it \
--cc=m.szyprowski@samsung.com \
--cc=mathieu.poirier@linaro.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=weihengqiuu@gmail.com \
--cc=will@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
all inboxes | Powered by JetHome®