Re: [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its next period
From: Mathieu Desnoyers
Date: Wed Dec 02 2026 - 13:02:25 EST
Hi Juri,
On 2026-12-02 15:55, Juri Lelli wrote:
[...]
> The fixes first; neither is new with this series.
>
> 1. check_dl_overrun() clears dl_overrun with a plain store, without the
> rq lock.
[...]
> Clearing it under
> task_rq_lock() should do (siglock -> pi_lock -> rq lock is already a
> valid order, from signal_wake_up_state()).
Agreed. The planned next version will have it as a new patch, right
after patch 4. check_dl_overrun() will call a new helper,
dl_task_clear_overrun(), which clears the flag under task_rq_lock().
> 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.
Yes, that was the reason. With your approach below, the planned next
version will not need dl_inactive_pending at all.
> 2. sched_dl_overflow() admits a task coming back to SCHED_DEADLINE
> before its 0-lag time with old_bw = 0:
[...]
> 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.
Agreed. It will be the second new patch. A new case of patch 30,
params_return_full, tests it. In a partition with no room for two tasks
of 60%, a task of 60% leaves the class and comes back before its 0-lag
time. Without the fix, the return gets EBUSY.
>From patch 6 on, a departed task records the CPU whose root domain
counts its old bandwidth. The old bandwidth will be discounted only if
the task comes back in that root domain. sched_dl_overflow() will then
swap the old and the new bandwidth in one lock section. If the task
comes back in another root domain, the old bandwidth is still removed
in a second lock section. The cover letter will list that as a known
limit.
> Could you add these two as separate patches ahead of this one (or I can
> send them, if you prefer)?
I will add them, with your Reported-by.
> Now the approach. IIUC, the only thing a returning constrained task
> needs is its 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?
Yes, this works, and the planned next version will do this. The rule
will be a new helper, dl_release_params(), called in the two release
paths. The timer restart and dl_inactive_pending will be gone. The
patch will add about 30 lines, more than half of them a comment.
reenter_asleep_late_in_gap runs the example of the changelog of this
patch. The task wakes up at 155ms, after its deadline and before its
next period. If dl_release_params() also clears the deadline, the case
fails in 3 of 3 runs: the task runs right after its wakeup. With the
deadline kept, it passes in 3 of 3 runs.
Two details:
- "Record the start of the period" (patch 28) adds a field,
period_start. Patch 29 computes the next period from it. So
dl_release_params() will keep period_start with the deadline.
- Your sketch leaves a runtime of 0. A task that comes back before its
deadline with no runtime left is not throttled at once. It runs
until the next tick, and pays that back at its next replenishment.
"Keep the debt of a task across a change of parameters" (patch 29)
makes enqueue_dl_entity() throttle it at once.
There are two costs, which the cover letter will list:
- A constrained task that leaves with much runtime left can reach its
0-lag time before its deadline. If it comes back between the two, it
has no runtime left until its next period. Had it stayed in the
class, it could have used that runtime until its deadline.
- A priority inheritance boost of a departed task replaces the deadline
it kept, and the deboost clears it. If the task then comes back
before its next period, it starts a new period at once. The priority
inheritance series will handle this case.
One question. The inactive timer can be armed in one period. Its
handler can then wait for the rq lock while the task runs a new period.
If the task leaves the class then, task_non_contending() releases the
bandwidth at once, as on v7.4-rc2. This is before the 0-lag time of the
new period. The root domain can then admit another task into that
bandwidth too early. The task itself keeps its deadline, so it gains no
runtime. v13 closed this window with the timer restart. Is this window
fine with you, or should the planned next version close it?
> 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.
The bail will be a patch of its own, after the two fixes above. As you
say, it fixes a race of v7.4-rc2. A task can wake up and die while the
handler waits for the rq lock. Its last dequeue then leaves its
bandwidth in running_bw and this_bw. The changelog will have the
sequence as a diagram.
With the rework, task_non_contending() reads the task state twice, as
on v7.4-rc2. Patch 6 adds a third read, for a dying task.
The full test suite passes on the reworked series.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com