Re: [PATCH v12 00/43] sched/deadline: bandwidth accounting fixes and selftests

From: Mathieu Desnoyers

Date: Tue Dec 01 2026 - 10:06:42 EST


On 2026-11-30 12:15, Juri Lelli wrote:
> To set expectations: I have roughly a week's worth of work left before
> the holiday break :)), and I'll probably spend it on what looks highest
> priority, the crash and hang fixes (23, 27, and 20 with them) plus 25
> and 26 for the first series.

Thanks, that helps. v13 starts with the five patches of your list. They
come in your order: 23, 27, 20, 25 and 26. They apply on the first
series alone.

> The rtmutex/PI part makes me a bit nervous. Beyond the memory safety and
> hang fixes, it grows DEADLINE PI quite a bit (held boosts, donor
> periods, an irq_work calling rt_mutex_setprio() from hard irq context),
> while proxy execution is meant to replace this code. I'd rather keep
> changes there to what is needed for correctness and weigh the rest
> against that, and it will need Peter's and Thomas' eyes anyway.

Understood. The rtmutex and PI changes move out of v13, into a new PI
series for Peter and Thomas. I will post it next, on top of v13. 40
moves with them, since it must come after 38 and 39. One test case of
the PI series also needs 22, which goes to my rtmutex series (see
below). Of the PI changes, v13 keeps only 23 and 27, the memory safety
and hang fixes.

Each fix that moves out fixes a bug. Its message names the test case,
reproducer, model or reading that shows it. The bugs are of these
kinds:
- A task runs on more than its reservation. Other deadline tasks can
then miss their deadlines (28, the part of 37 for a boosted task, 40
and 41).
- A deadline waiter waits for the next period of an owner that cannot
run, and can miss its deadline (38 and 39).
- A waiter with a deadline of 0, or one that has passed, takes the lock
before waiters with earlier deadlines (30 and 32).
- this_bw or total_bw counts a boosted task wrongly. A warning fires,
or sched_setattr() refuses a task that fits (29 and 31).
- In a lock cycle, rt_mutex_setprio() can make a task with no deadline
policy its own donor. The task would then not run again until its
priority changes (part of 38).
- A chain walk stops too early. The owner at the end of the chain keeps
an old donor, with a later deadline, while a deadline task waits for
it (21).
The held boosts and the donor periods are what the fixes of 28 and 38
need. The irq_work is what 39 needs. The code that throttles the owner
holds the rq lock. rt_mutex_setprio() needs the owner's pi_lock,
which nests outside the rq lock. If you or Peter would rather leave
some of these bugs to proxy execution, I will drop those patches.

> 22 also
> looks like an old RT priority bug that might be worth sending out
> separately?

Yes. It does not need deadline tasks. With SCHED_FIFO waiters, an owner
further down the chain keeps the old RT priority. I will move it to my
series "locking/rtmutex: priority inheritance fixes and tests", with a
SCHED_FIFO test case.

> On the accounting side, I've been playing with a different approach:
> keep the bandwidth of each task in a per-CPU sum (on the CPU recorded
> with it), so that a rebuild only sums the CPUs of each root domain.
[...]
> It's
> still WIP; I'll try to post it as an RFC, most likely in January, so
> that we can compare, if you are up for it?

Yes, I am. The test cases of deadline_bw_test and
deadline_rebuild_test should help to compare the two.

v13 adds three fixes that are more cases to compare. They are in the
departed list and the rebuild:
- v13 patch 31: a task leaves the class while a rebuild walks the task
list.
- v13 patch 32: a boost brings a departed task back into the class,
after a rebuild dropped its bandwidth.
- v13 patch 33: a task is reaped before its last schedule.
In each case, total_bw would miss the bandwidth of the task for a
while. Admission control could then accept too much. Reading the code
and a Spin model of the accounting found them. v13 patch 35 adds test
cases for the first two.

> > Ingo, Juri, a question on patches 25 and 26. Would you rather have
> > them in the first series, after its patch 10?
>
> Either way works for me, as long as they come right after it: as I said
> on 25, at the top of the next version (with 23 and 27) is fine too. I
> think 26 first needs a fix for the race Sashiko reported (its first two
> findings on 26 look right to me).

I agree, and v13 fixes both, in its patch 5. In both, the handler of
the inactive timer is running, so the timer cannot be canceled:
- The first finding: the new flag dl_inactive_pending tells whether the
handler will still release the bandwidth or restart the timer. If it
will, task_non_contending() leaves the task to the handler.
- The second finding: the restarted timer can fire after the task came
back to the class. The next task_non_contending() cancels it, as in
v12. If the timer fires before that, the handler now leaves the task
alone, since dl_non_contending is clear. This also fixes the third
finding, the bandwidth left in running_bw and this_bw at exit.

26 no longer calls dl_task_depart(), so it needs none of 1 to 19. With
the fix of the first finding, 26 leaves some departing tasks to the
timer handler. 1 adds the departed list. It now comes after 26, as v13
patch 6, and puts these tasks on the list.

> > Peter, Juri, a question on patch 37. Would you take a follow-up for
> > tasks with an implicit deadline?
>
> I think so, it's what the XXX in sched_dl_overflow() asks for.

Thanks. v13 does not include it.

> > Peter, Juri, a question on patch 37. It is large: it adds about 600
> > lines. [...] Would you like it split?
>
> I'd find it easier to review split, yes. The period_start /
> dl_next_period() part, for instance, looks like it could stand alone.

OK, v13 splits it, as patches 28 and 29. But dl_next_period() cannot
count from period_start in the first patch. That change alone makes
three cases of deadline_bw_test fail: wake_after_deadline_shrunk,
period_shrunk_no_burst and constrained_after_job. In each, the task has
run in its period when sched_setattr() lowers dl_deadline. The job that
ran counts as a job of the new parameters, released at
deadline - dl_deadline. Its next period starts one dl_period later.
The deadline still comes from the old dl_deadline, so this is later
than period_start + dl_period. The rule that keeps the debt gives this
later start. Today's formula, deadline - dl_deadline + dl_period,
happens to give it too. So the first patch only records period_start.
The second applies the rule, and computes dl_next_period() from
period_start. The part for a boosted task goes to the PI series, since
it builds on the held boost.

Thanks,

Mathieu

--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com