From: Juri Lelli <juri.lelli@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org, 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: Re: [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its next period
Date: Wed, 2 Dec 2026 15:55:48 +0100 [thread overview]
Message-ID: <axAxdNEE1Q2OuxNQ@jlelli-thinkpadt14gen4.remote.csb> (raw)
In-Reply-To: <835511935d961be832cbaf24e902762d1926e611.1796146461.git.mathieu.desnoyers@efficios.com>
Hello,
On 01/12/26 12:43, Mathieu Desnoyers wrote:
...
> Fix this by keeping the bandwidth and the deadline of a constrained
> task that leaves the class until its next period. task_non_contending()
> and inactive_task_timer() wait for the later of the 0-lag time and the
> next period.
I went through the patch and I don't seem to have a correctness
complaint about the code. But I find the patch somewhat hard to digest:
about 100 lines, half of them comments, and a 120 line changelog :).
While thinking about it I ended up with two fixes we seem to need
anyway, and a question about the approach.
The fixes first; neither is new with this series.
1. check_dl_overrun() clears dl_overrun with a plain store, without the
rq lock. On x86 that is a load and store of the whole DL bitfield word,
so it can write back stale dl_throttled, dl_non_contending, dl_bw_oncpu,
... values. On !RT the window is a few instructions against another CPU
holding the task's rq lock (sched_setattr(), rt_mutex_setprio()). On
PREEMPT_RT the task work runs with interrupts on under an rtmutex
siglock, so the task can be preempted between load and store and the
stale value can stay in a register for a long time. Clearing it under
task_rq_lock() should do (siglock -> pi_lock -> rq lock is already a
valid order, from signal_wake_up_state()).
Fixes: 34be39305a77 ("sched/deadline: Implement "runtime overrun signal" support")
This is also the reason dl_inactive_pending is a bool at the end of the
struct (8 bytes more per task at this point of the series)? With
dl_overrun fixed, it can be a bit like the others.
2. sched_dl_overflow() admits a task coming back to SCHED_DEADLINE
before its 0-lag time with old_bw = 0:
if (dl_policy(policy) && !task_has_dl_policy(p) &&
!__dl_overflow(dl_b, cap, 0, new_bw)) {
if (hrtimer_active(&p->dl.inactive_timer))
__dl_sub(dl_b, p->dl.dl_bw, cpus);
so the new bandwidth has to fit on top of the old one it still holds,
and a round trip with the same parameters can fail with -EBUSY in a full
root domain. The in-class branch just below does discount p->dl.dl_bw.
Discounting it when the timer is active (and, after your patch 6, when
the recorded root domain is this dl_b) would make the two consistent,
and would also close the window where patch 6 counts both.
Fixes: 387e31300b57 ("sched/deadline: Fix the update of the total -deadline utilization")
Could you add these two as separate patches ahead of this one (or I can
send them, if you prefer)?
Now the approach. IIUC, the only thing a returning constrained task
needs is its deadline. A constrained task that sleeps in the class and
wakes after its 0-lag time never gets a new period before its next one:
before its deadline update_dl_revised_wakeup() keeps the deadline and
scales the runtime down, and between the deadline and the next period
dl_check_constrained_dl() throttles it. The 0-lag time only drops
running_bw. A departed task loses this only because, with patches 9 and
11 of the first series, the release at the 0-lag time also clears the
deadline.
So, what about keeping the release at the 0-lag time as it is now, and,
for constrained tasks only, clearing the runtime but keeping the
deadline when we release? Something like:
/* in the two release paths, instead of __dl_clear_params() */
u64 deadline = dl_se->deadline;
bool constrained = !dl_is_implicit(dl_se);
__dl_clear_params(dl_se);
if (constrained)
dl_se->deadline = deadline; /* runtime stays 0 */
A task coming back then goes through the in-class rules:
- after the next period: new period, as now;
- between the deadline and the next period: dl_check_constrained_dl()
throttles it until the next period, for a wakeup and for a runnable
return (it runs before the ENQUEUE_MOVE/setup_new_dl_entity() path);
- between the 0-lag time and the deadline: runtime 0, so nothing left
to spend from the period it gave back.
The bandwidth goes back at the 0-lag time as today, so admission of the
returning task is a normal check (plus fix 2 for an earlier return).
Implicit tasks are unchanged: for them a new period after the 0-lag
time is what CBS does in the class too, so clearing the deadline is
right.
If this works, the timer restart and dl_inactive_pending shouldn't be
needed, departed tasks wouldn't stay around longer than today (one less
thing for patch 6 and the rebuild to deal with), and the change looks
like a handful of lines.
What do you think? If you see something that breaks with it, I'd still
suggest splitting the current version: the bail in inactive_task_timer()
for a task back in the class looks like a standalone fix (exit race,
already on v7.4-rc2), then dl_inactive_pending on its own, then the
rule. Reading the state once in task_non_contending() (it is read up to
four times now) would also help.
Thanks,
Juri
next prev parent reply other threads:[~2026-12-02 14:55 UTC|newest]
Thread overview: 59+ 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-02 9:43 ` Juri Lelli
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-02 14:54 ` Mathieu Desnoyers
2026-12-02 14:55 ` Juri Lelli [this message]
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-01 19:47 ` sashiko-bot
2026-12-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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-02 14:54 ` Mathieu Desnoyers
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=axAxdNEE1Q2OuxNQ@jlelli-thinkpadt14gen4.remote.csb \
--to=juri.lelli@redhat.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=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.desnoyers@efficios.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®