From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org
Cc: 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,
tommaso.cucinotta@gmail.com, 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,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev,
oleg@redhat.com, brauner@kernel.org, stable@vger.kernel.org
Subject: [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back
Date: Tue, 1 Dec 2026 12:44:26 -0500 [thread overview]
Message-ID: <3d7f00e9dbb04f7337da5c038b3e32be017b98f6.1796146461.git.mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <cover.1796146461.git.mathieu.desnoyers@efficios.com>
A task that leaves SCHED_DEADLINE before its 0-lag time is a departed
task. Its root domain keeps its bandwidth until then, and the task waits
on dl_departed_list. A rebuild of the root domains' accounting puts this
bandwidth back in the root domain of the CPU recorded with it. If that
CPU is no longer active, the rebuild drops the bandwidth. A CPU that
goes offline is in the default root domain by then, so the root domain
that counted the task cannot be found. dl_bw_gen then keeps the release
of the task from removing anything.
But priority inheritance can bring such a task back into the class.
Here a partition root has CPUs X and Y:
1. A deadline task T holds an rt_mutex, and sleeps on X. X is the CPU
recorded with its bandwidth.
2. sched_setattr() makes T a SCHED_OTHER task, before its 0-lag time.
T goes on the departed list.
3. T wakes up on Y, then sleeps there. The record stays X.
4. X goes offline. The rebuild that follows drops the bandwidth of T.
5. A deadline task blocks on the rt_mutex. It boosts T back into the
class, before the 0-lag time of T.
switched_to_dl() takes T off the departed list. this_bw of Y counts T
again, but no root domain counts it in total_bw. Until the deboost,
sched_setattr() can admit tasks beyond the capacity of the root domain.
Fix this in dl_task_undepart(). If a rebuild dropped the bandwidth,
count it again in the root domain of the CPU of the task. A migration
does the same for a task that a rebuild left out (dl_task_move_bw()).
dl_task_undepart() leaves the task to the walk of the task list after
a rebuild, if the walk has not reached it yet (dl_bw_move_blocked()).
But the walk counts only the tasks in the class, so it can pass a
departed task. The walk marks in dl_bw_skip_gen the tasks it leaves
out, and dl_bw_move_blocked() lets them through. Mark in the same way
the departed tasks that dl_clear_root_domains() and dl_task_depart()
leave out.
This was found by reading the code. pi_departed_offline_boost, a test
case that a later patch of this series adds, shows it. Without this
fix, it failed in 33 of 33 runs. With it, it passed in 25 of 25.
Fixes: f9a25f776d78 ("cpusets: Rebuild root domain deadline accounting information")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: stable@vger.kernel.org
---
include/linux/sched.h | 8 ++++----
kernel/sched/deadline.c | 44 ++++++++++++++++++++++++++++++-----------
2 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4d2bf4de524d..17aa9a97c1ef 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -771,10 +771,10 @@ struct sched_dl_entity {
* @dl_bw_gen is the value of dl_bw_gen when the bandwidth was last
* counted. If a rebuild dropped it since, there is nothing to remove.
*
- * @dl_bw_skip_gen is the value of dl_bw_gen when the walk of the
- * task list after a rebuild left the task out: no CPU of it was
- * active. A move of the task then counts the bandwidth, even before
- * the walk ends.
+ * @dl_bw_skip_gen is the value of dl_bw_gen when a rebuild of the
+ * accounting left the task out. Before the walk of the task list
+ * ends, a move of the task can then count the bandwidth. So can a
+ * boost of a departed task back into the class.
*
* @dl_bw_resv_cpu is a CPU of the root domain where a cpuset attach
* in progress reserved room for the bandwidth, or -1.
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index ef97b07c0aa2..d84a459e7a64 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -247,7 +247,7 @@ __dl_overflow(struct dl_bw *dl_b, unsigned long cap, u64 old_bw, u64 new_bw)
* it back.
* - Older: an earlier rebuild dropped it. A task on the departed list
* stays out, and its release removes nothing. A task that is in the
- * class is counted again.
+ * class, or that a boost brings back into it, is counted again.
*
* Only equalities are compared, so the wrap of the counter is
* harmless.
@@ -303,8 +303,8 @@ static inline bool dl_bw_rebuilding(void)
* Return true if the bandwidth of @p must not move now. Either the sched
* domains are rebuilt, or the walk of the task list that follows has not
* reached @p yet. The walk then counts @p. A move must not count it
- * first. A task the walk left out, with no active CPU, can move: no one
- * else counts it.
+ * first. A task that the rebuild left out can move, or come back into
+ * the class by a boost. No one else counts it. dl_bw_skip_gen marks it.
*
* The answer is exact under dl_departed_lock. Without it, the answer is a
* hint: dl_task_move_bw() tests again under the lock.
@@ -436,16 +436,25 @@ static void dl_task_depart(struct task_struct *p)
cpu = cpumask_first_and(cpu_active_mask, &p->cpus_mask);
if (cpu < nr_cpu_ids)
dl_task_count_bw(p, cpu);
+ else
+ WRITE_ONCE(dl_se->dl_bw_skip_gen, dl_bw_gen);
}
list_add(&dl_se->dl_departed_node, &dl_departed_list);
}
/*
* Take @p off dl_departed_list. @p comes back to the deadline class, and
- * its bandwidth is that of a deadline task again. The caller holds the rq
- * lock of @p.
+ * its bandwidth is that of a deadline task again. @cpu is the CPU of @p.
+ * The caller holds the rq lock of @p.
+ *
+ * A rebuild may have dropped the bandwidth while @p was departed. No
+ * root domain counts it then, but this_bw of @cpu does again once @p is
+ * back. Count it in the root domain of @cpu, as a move of @p would. If
+ * the walk of the task list after a rebuild has not reached @p yet,
+ * leave @p to the walk. If @cpu is not active, leave @p to its move to
+ * an active CPU.
*/
-static void dl_task_undepart(struct task_struct *p)
+static void dl_task_undepart(struct task_struct *p, int cpu)
{
struct sched_dl_entity *dl_se = &p->dl;
@@ -454,6 +463,9 @@ static void dl_task_undepart(struct task_struct *p)
return;
guard(raw_spinlock)(&dl_departed_lock);
list_del_init(&dl_se->dl_departed_node);
+ if (dl_se->dl_bw_gen != dl_bw_gen && !dl_bw_move_blocked(p) &&
+ cpu_active(cpu))
+ dl_task_count_bw(p, cpu);
}
/*
@@ -4787,21 +4799,30 @@ void dl_clear_root_domains(void)
* (dl_task_release_bw()).
*/
if (dl_se->dl_bw_gen != dl_bw_gen - 1)
- continue;
+ goto left_out;
/*
* Drop the bandwidth of a task whose CPU is inactive. A CPU
* that goes offline is in the default root domain by then.
* The root domain that counted the task cannot be found
* from the recorded number. The release then removes
- * nothing, and no later rebuild restores it.
+ * nothing. A boost of the task back into the class counts
+ * it again (dl_task_undepart()).
*/
if (cpu < 0 || !cpu_active(cpu))
- continue;
+ goto left_out;
dl_b = dl_bw_of(cpu);
raw_spin_lock(&dl_b->lock);
__dl_add(dl_b, dl_se->dl_bw, dl_bw_cpus(cpu));
raw_spin_unlock(&dl_b->lock);
dl_se->dl_bw_gen = dl_bw_gen;
+ continue;
+left_out:
+ /*
+ * The walk counts only the tasks in the class. It can pass
+ * this task before a boost brings it back. Mark the task, so
+ * that dl_bw_move_blocked() lets the boost count it at once.
+ */
+ WRITE_ONCE(dl_se->dl_bw_skip_gen, dl_bw_gen);
}
}
@@ -4900,9 +4921,10 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
* meanwhile, its next wakeup or migration there first moves the
* bandwidth and the record, as for any deadline task. A rebuild while
* it is boosted counts it like any deadline task, and records the CPU
- * it picks.
+ * it picks. If a rebuild dropped the bandwidth meanwhile, count it
+ * again where the task is.
*/
- dl_task_undepart(p);
+ dl_task_undepart(p, cpu_of(rq));
/* If p is not queued we will update its parameters at next wakeup. */
if (!task_on_rq_queued(p)) {
--
2.47.3
next prev parent reply other threads:[~2026-12-01 17:44 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:43 [PATCH v13 00/36] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 02/36] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 03/36] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 04/36] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-12-01 18:17 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 06/36] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 18:20 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 07/36] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 08/36] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 09/36] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 10/36] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 11/36] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 12/36] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 13/36] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 14/36] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 15/36] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 16/36] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 17/36] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 18/36] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-01 19:11 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 19/36] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 20/36] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-01 19:02 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 21/36] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-01 19:29 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 23/36] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 24/36] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 25/36] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 26/36] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 27/36] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 28/36] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 29/36] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 30/36] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-01 19:34 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-01 19:41 ` sashiko-bot
2026-12-01 17:44 ` Mathieu Desnoyers [this message]
2026-12-01 19:47 ` [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back sashiko-bot
2026-12-01 17:44 ` [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild Mathieu Desnoyers
2026-12-01 19:57 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 34/36] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 35/36] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-01 19:51 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 36/36] selftests/sched: Share the helpers of the deadline tests 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=3d7f00e9dbb04f7337da5c038b3e32be017b98f6.1796146461.git.mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=brauner@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=oleg@redhat.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=tommaso.cucinotta@gmail.com \
--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®