Re: [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its next period

From: Juri Lelli

Date: Wed Dec 02 2026 - 09:56:02 EST


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