mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 00/29] sched/deadline: bandwidth accounting fixes and selftests
@ 2026-11-08 18:53 Mathieu Desnoyers
  2026-11-08 18:53 ` [PATCH v5 01/29] sched: Fix cpuset_mutex double unlock in __sched_setscheduler() Mathieu Desnoyers
                   ` (28 more replies)
  0 siblings, 29 replies; 31+ messages in thread
From: Mathieu Desnoyers @ 2026-11-08 18:53 UTC (permalink / raw)
  To: juri.lelli, peterz, mingo, vincent.guittot
  Cc: linux-kernel, Mathieu Desnoyers, tglx, will, boqun,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	kprateek.nayak, luca.abeni, mathieu.poirier, longman,
	ridong.chen, tj, hannes, mkoutny, shuah, bigeasy, clrkwllms,
	parri.andrea, m.szyprowski, kayracizmeci, weihengqiuu, cgroups,
	linux-kselftest, linux-rt-devel

Hi Ingo, Juri,

This series fixes 25 bugs of SCHED_DEADLINE. Most of them are in its
bandwidth accounting. Then it shows the deadline bandwidth of each
runqueue in sched_debug, and adds three selftests. The fixes come first,
as you asked, so that stable can take patches 1 to 25.

Three of the bugs take the kernel down (patches 5, 8 and 22). Two leave
cpuset_mutex unusable (1 and 6). Most of the others leave total_bw of a
root domain, or this_bw of a runqueue, wrong. The root domain then
admits deadline tasks beyond its capacity, or refuses every one.

The series applies on top of v2 of "locking/rtmutex: priority
inheritance fixes and tests", posted for Peter and Thomas. Patch 8 needs
its patch 3.

Patch 1 is Andrea Parri's, reviewed by Waiman, Kayra and Juri. I carry
it because patches 6 and 15 build on it. Take it by whichever route you
prefer.

Juri, Ingo dropped your four fixes from sched/urgent after the first
one crashed Marek Szyprowski's hotplug test. They are here:
- 1/4 is patch 16. It does not use the task's mask, which can have no
  active CPU during hotplug.
- 2/4 is patch 11, without its double release. It does not carry your
  Signed-off-by, which is yours to add back.
- 3/4 is patch 2.
- 4/4 is patch 12, extended.
Marek found v2 fixed on the board that crashed.

The fixes
=========

 1  Do not unlock cpuset_mutex twice when __sched_setscheduler()
    retries (Andrea Parri).
 2  Refuse SCHED_FLAG_KEEP_PARAMS requests that would change the policy
    or the class.
 3  Skip admission for parameters that SCHED_FLAG_KEEP_PARAMS keeps.
 4  Let a task boosted by a deadline waiter change its policy.
 5  Do not divide by zero active CPUs of a root domain.
 6  Take cpuset_mutex for a deadline policy change only with pi, so
    that sysrq-n does not leave it locked.
 7  Replenish a throttled task switched out and back, so that it runs
    again.
 8  Take a deadline boost from the waiter's rt_mutex node, so that the
    owner never runs on cleared parameters.
 9  Reset the deadline and the runtime with the parameters.
 10 Reset the waiter's deadline and runtime at a deboost in the class.
 11 Release the bandwidth of a task that leaves the class asleep.
 12 Reject SCHED_DEADLINE on exited tasks (Juri Lelli).
 13 Keep the bandwidth of departing tasks across a root domain rebuild.
 14 Keep this_bw right when a task changes during a remote wakeup.
 15 Rebuild the root domains' accounting from the task list.
 16 Record the root domain that holds a task's bandwidth.
 17 Leave out of a rebuild a dying task that released its bandwidth.
 18 Move a task's bandwidth only where an attach made room for it.
 19 Wait for an attach before rebuilding the sched domains.
 20 Give back the bandwidth an attach did not move.
 21 Reserve an attach's bandwidth in the root domain each task moves to.
 22 Make a rebuild use the CPU recorded with a task's bandwidth.
 23 Move a task's bandwidth when it must leave its CPU.
 24 Cancel the replenishment timer with the parameters.
 25 Count in this_bw the bandwidth a boosted task is given.

Patches 16 to 23 go together. 16 records the root domain that counts a
task's bandwidth. 17 to 23 fix the rebuild, attach and migration paths
that the record exposes. Patch 25 completes patch 14. Patch 26 shows
this_bw in sched_debug. Patches 27 to 29 add 65 cases in
tools/testing/selftests/sched/deadline, as Juri suggested.

Peter and Thomas, patch 8 touches the rt_mutex code. It records the
reservation of a deadline waiter in its rt_mutex node, and takes a
deadline boost from there. struct rt_mutex_waiter grows by 48 bytes.
The other classes keep the waiter's own priority, as since commit
acd58620e415 ("sched/rtmutex: Refactor rt_mutex_setprio()").

Peter, patch 21 also touches __set_cpus_allowed_ptr_locked(). A cpuset
attach can reserve a deadline task's bandwidth in one root domain. If
the CPU picked for the task is in the other one, the patch steers the
task to the reserved CPU.

Testing
=======

The 65 cases pass wherever they run, with lockdep and no kernel
warning, in 21 QEMU guests:
- 8 guests of 8 vCPUs.
- 2 guests each with 4 vCPUs, PREEMPT_RT, proxy execution off, and no
  CONFIG_CPUSETS.
- 5 guests of 5 vCPUs booted with isolcpus=domain,1,2 or
  isolcpus=domain,0,1, 2 of them with PREEMPT_RT.
The six isolcpus cases run only in the last group. There, three cases
that need 4 CPUs that are not isolated skip.

The cases of v4 fail on v7.4-rc1 as patches 27 to 29 list. Each case
added in v5 fails on the series without its fix. Kernels stopped at
single patches confirm the claims of patches 11, 13, 19 and 20. The
series builds at each patch whose code changed in v5.

Patch 8 has no selftest. A debug delay, or a stress test, locks up
v7.4-rc1. The series runs the stress test for 600 seconds. The locking
API, ww_mutex, locktorture and futex selftests pass with and without
PREEMPT_RT.

How this was developed
======================

An LLM coding assistant wrote these patches, their messages and the
tests, under my direction and review. I know the concepts behind
SCHED_DEADLINE, but not its implementation well. So I ask those who
know this code for a careful reading of the fixes. A reproducer that
stops failing shows that the symptom goes away. It does not show that
the fix is the one you would have written.

The bugs came from:
- flaky cgroup selftests of a feature I am developing;
- the review of Juri's four fixes;
- building deadline_bw_test, and reading the code;
- the Sashiko AI reviews of v1 to v4. Each finding was checked against
  the code first.

Changes since v4
================

- New patch 10: a deboost in the class resets the waiter's deadline and
  runtime when the task holds more runtime than its own.
- New patch 21: with isolcpus=domain, a cpuset move reserves a task's
  bandwidth in the root domain the task moves to. Found with the new
  isolcpus test cases.
- New patch 23: a task that must leave its CPU takes its bandwidth and
  its record along.
- Fixes from the Sashiko review of v4:
  - 4: sysrq-n drops the boost of a task that leaves the class.
  - 15: the walk skips a zombie whose bandwidth an earlier rebuild
    dropped.
  - 16: a bandwidth of 0 is admitted on the CPU the task is on.
  - 17: moved after 16. It counts a dead task that has not reached its
    last schedule.
  - 22: the rebuild prefers the CPU the task is on.
- Ten new selftest cases test these fixes. Two cases now check that the
  owner was boosted.
- The commit messages and comments are rewritten to read more easily.
  They use short sentences. They give the design intent of the code
  being fixed, and the impact, with fewer numbers. Patches 1 and 12
  are unchanged.
- The rewrite found details that did not match the code or the test
  logs, and fixed them. Patch 18 claimed a case that patch 20 fixes.
  That case moved to the message of patch 20.
- New subjects for patches 14 and 22.
- Patch 8 cites the rtmutex patch by its new subject, "locking/rtmutex:
  Clone the sort keys in rt_mutex_enqueue_pi()".
- Testing with isolcpus=domain found three upstream problems outside
  this series. I reported them separately:
  - An empty sched domain, which leads to a panic at CPU offline:
    https://lore.kernel.org/all/20261108145744.1532128-1-mathieu.desnoyers@efficios.com/
  - A WARNING when isolated partitions take every housekeeping CPU:
    https://lore.kernel.org/all/20261108145754.1532162-1-mathieu.desnoyers@efficios.com/
  - A false "suspicious RCU usage" report without CONFIG_CPUSETS:
    https://lore.kernel.org/all/20261108145931.1532447-1-mathieu.desnoyers@efficios.com/
  For the first two, Waiman answered that cpuset will keep a
  housekeeping CPU in the top cpuset. Guopeng Zhang's series, under
  review, does this:
  https://lore.kernel.org/all/20261105130344.664336-1-guopeng.zhang@linux.dev/
  For the third, I posted the fix as a patch, with Waiman's Reviewed-by:
  https://lore.kernel.org/all/20261108185129.1549419-1-mathieu.desnoyers@efficios.com/

Not changed:
- A departed task that priority inheritance boosts back into the class
  is counted once across a rebuild. The rebuild counts it where it
  runs. If the deboost races the rebuild, its bandwidth is dropped
  until its 0-lag time. Nothing is counted twice.
- At a deboost, the 0-lag time of a task comes from the deadline and
  runtime it ran on during the boost, as upstream.
- The EPERM of a sleeping task moved to another partition is the
  baseline's affinity check.

Based on tip sched/urgent, 006991aa8997, with v2 of "locking/rtmutex:
priority inheritance fixes and tests" applied first:
https://lore.kernel.org/all/20261108141347.1525532-1-mathieu.desnoyers@efficios.com/

v4: https://lore.kernel.org/all/20261107014451.1487825-1-mathieu.desnoyers@efficios.com/

Andrea Parri (1):
  sched: Fix cpuset_mutex double unlock in __sched_setscheduler()

Juri Lelli (1):
  sched/deadline: Reject SCHED_DEADLINE on exited tasks

Mathieu Desnoyers (27):
  sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or
    the class
  sched/deadline: Do not admit bandwidth for parameters that are kept
  sched: Let a task boosted by a deadline waiter change its policy
  sched/deadline: Do not divide by zero active CPUs of a root domain
  sched: Take cpuset_mutex for a deadline policy change only with pi
  sched/deadline: Do not lose a throttled task switched out and back
  sched/deadline: Take a deadline boost from the waiter's rt_mutex node
  sched/deadline: Reset the deadline and the runtime with the parameters
  sched/deadline: Reset the donor's runtime at a deboost in the class
  sched/deadline: Release the bandwidth of a task that leaves the class
    asleep
  sched/deadline: Keep departing bandwidth across a root domain rebuild
  sched/deadline: Fix this_bw when a task is changed during a remote
    wakeup
  sched/deadline: Rebuild the root domains' accounting from the task
    list
  sched/deadline: Record the root domain holding a task's bandwidth
  sched/deadline: Leave a dying task out of a rebuild of the accounting
  sched/deadline: Move a task's bandwidth only where room was made
  cgroup/cpuset: Wait for an attach before rebuilding the sched domains
  cgroup/cpuset: Give back the bandwidth an attach did not move
  cgroup/cpuset: Reserve the bandwidth in the root domain a task moves
    to
  sched/deadline: Make a rebuild use the CPU recorded with a task's
    bandwidth
  sched/deadline: Move a task's bandwidth when it must leave its CPU
  sched/deadline: Cancel the replenishment timer with the parameters
  sched/deadline: Count the bandwidth a boosted task is given
  sched/debug: Show the deadline bandwidth of each runqueue
  selftests/sched: Add a test of SCHED_DEADLINE policy round trips
  selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain
    rebuild
  selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting

 include/linux/cpuset.h                        |    9 -
 include/linux/sched.h                         |   47 +-
 include/linux/sched/deadline.h                |   54 +-
 include/linux/sched/rt.h                      |   11 -
 kernel/cgroup/cgroup.c                        |    3 -
 kernel/cgroup/cpuset-internal.h               |   14 -
 kernel/cgroup/cpuset.c                        |  274 +-
 kernel/locking/rtmutex.c                      |   34 +-
 kernel/locking/rtmutex_api.c                  |    2 +-
 kernel/locking/rtmutex_common.h               |    5 +
 kernel/sched/core.c                           |  116 +-
 kernel/sched/deadline.c                       |  940 ++-
 kernel/sched/debug.c                          |   12 +-
 kernel/sched/sched.h                          |   26 +-
 kernel/sched/syscalls.c                       |   95 +-
 kernel/sched/topology.c                       |    8 +
 tools/testing/selftests/Makefile              |    1 +
 .../selftests/sched/deadline/.gitignore       |    3 +
 .../testing/selftests/sched/deadline/Makefile |    8 +
 tools/testing/selftests/sched/deadline/config |    5 +
 .../sched/deadline/deadline_bw_test.c         | 5038 +++++++++++++++++
 .../sched/deadline/deadline_rebuild_test.c    |  491 ++
 .../sched/deadline/deadline_switch_test.c     |  721 +++
 .../testing/selftests/sched/deadline/settings |    1 +
 24 files changed, 7563 insertions(+), 355 deletions(-)
 create mode 100644 tools/testing/selftests/sched/deadline/.gitignore
 create mode 100644 tools/testing/selftests/sched/deadline/Makefile
 create mode 100644 tools/testing/selftests/sched/deadline/config
 create mode 100644 tools/testing/selftests/sched/deadline/deadline_bw_test.c
 create mode 100644 tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
 create mode 100644 tools/testing/selftests/sched/deadline/deadline_switch_test.c
 create mode 100644 tools/testing/selftests/sched/deadline/settings


base-commit: 006991aa89974378ee579416dba87adc22cd60fd
prerequisite-patch-id: 382feddeb27d226d8711d23036c8ae0c8629c680
prerequisite-patch-id: 72e83c74aa52fcd32afb2909b071f40c82b0ef10
prerequisite-patch-id: ec1db50b63225bf6d9e37c48e808880c087ed2cd
prerequisite-patch-id: 97db185c1e6a2dc57035ae5ad36cbed6142a1c59
prerequisite-patch-id: 891e1ff948178bf81c62424d4af34e46aeee239c
-- 
2.47.3


^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2026-11-08 19:17 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 18:53 [PATCH v5 00/29] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 01/29] sched: Fix cpuset_mutex double unlock in __sched_setscheduler() Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 02/29] sched: Refuse SCHED_FLAG_KEEP_PARAMS that would change the policy or the class Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 03/29] sched/deadline: Do not admit bandwidth for parameters that are kept Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 04/29] sched: Let a task boosted by a deadline waiter change its policy Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 05/29] sched/deadline: Do not divide by zero active CPUs of a root domain Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 06/29] sched: Take cpuset_mutex for a deadline policy change only with pi Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 07/29] sched/deadline: Do not lose a throttled task switched out and back Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 08/29] sched/deadline: Take a deadline boost from the waiter's rt_mutex node Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 09/29] sched/deadline: Reset the deadline and the runtime with the parameters Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 10/29] sched/deadline: Reset the donor's runtime at a deboost in the class Mathieu Desnoyers
2026-11-08 19:17   ` sashiko-bot
2026-11-08 18:53 ` [PATCH v5 11/29] sched/deadline: Release the bandwidth of a task that leaves the class asleep Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 12/29] sched/deadline: Reject SCHED_DEADLINE on exited tasks Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 13/29] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 14/29] sched/deadline: Fix this_bw when a task is changed during a remote wakeup Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 15/29] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 16/29] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 17/29] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 18/29] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 19/29] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 20/29] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 21/29] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-11-08 18:53 ` [PATCH v5 22/29] sched/deadline: Make a rebuild use the CPU recorded with a task's bandwidth Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 23/29] sched/deadline: Move a task's bandwidth when it must leave its CPU Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 24/29] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 25/29] sched/deadline: Count the bandwidth a boosted task is given Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 26/29] sched/debug: Show the deadline bandwidth of each runqueue Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 27/29] selftests/sched: Add a test of SCHED_DEADLINE policy round trips Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 28/29] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-11-08 18:54 ` [PATCH v5 29/29] selftests/sched: Add a test of SCHED_DEADLINE bandwidth accounting Mathieu Desnoyers

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®