From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309948; b=DzPSzv9W/ow+98NpLoZb2ieab+Sok4mPjSKfHZhygNZYTr46QlSQe+Tq9SVmp5C3hQL5 PyUoaxSnkUQQnerHEldJykriCQs99+0QBiGy1UhbJSsBlyREOut1R6+dsSbnqowFm+5Et CjbAGbmlmoII7/xjzL1LpztDTKoBLn9m3FJ1LlMuR+j1INJsAkjCr34dS69NGZE9RT1OM eIN6kNolI0jjQdszQAVx4pBDpxcOeWdZbnyZPoN5X1SkJCjGRM3h3n6xKigNmFfCOsven ytQ8IStzZmBxb/H2RbHtDnYzhnDQRH3jjplCW9WcOeL6vXDPzCAPnQ/9o7x6/QoFeGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309948; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=ErgDRKUqSCwt3hSTGzvIZ2MnVzONbfb8er14yZBQcks=; b=J0YwGUbthQ5VR/J++L4elQf/2ItQRDilzyVQN6y8fdJ1kKfKaY3/aIOoH9N8xV5dnrMh a66Dup4khHHY7wi6QqfLsQny7XAmA/g1xYvX675MUAYW/AnLT4+w18VsYpgYMsOQibYGk 4ciQZqYZNKOocHhf3BQ3jOapCD3XlNNdLai5n9uJxCCuyxExxpZ7rPUx2h0mGC7tZ7SYS 1d7dT1LVkwqTFNZaCDXtFuynlOkkOGCEP9YCmONjEDmc7eXkEStmBb83MOvScXiZXbDB1 ENABe/pWrH7KmjlJMoxbId/YJfvOjd5OrznifXpr0iOjaAUq3qEsMEXnYbGQ6nBI0AQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=qGJAkeCc; arc=none smtp.remote-ip=158.69.130.18 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1516B606A32F; Thu, 3 Dec 2026 14:59:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1516B606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=qGJAkeCc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796309939; bh=ErgDRKUqSCwt3hSTGzvIZ2MnVzONbfb8er14yZBQcks=; h=From:To:Cc:Subject:Date:From; b=qGJAkeCcbrGMggnzpNJXtm3nOXvGKCNL+fnfcnGp0CdX7nQrMOlbisauotPSB9Guc nBKaCczDOQf/JI3JQwShBHLA/ZS79rFv6Tt3xfijK+uPyU3HtJBhjLXOiiasj56mYr bU6iP8YBtYqFCiL0RRBD7Fiiam5vZPfIrJQKJOjvaxMIVLcghIiXQ/CSgyEE98UGLM mSpzMDhNhED96ReOw5rUe7+cPGrryPHNsHu0mdR5gC2Ttkpl+JE6LYiqToqpxtg88z Vsv6LJVW291wR5h2xSkSJks5JMQMOCLqgJFTB7s/d2MP3AalgaawlNjzwwU2OKwq5f ayzRFF6HheiEg== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHnt08mSzb2k; Thu, 03 Dec 2026 09:58:57 -0500 (EST) From: Mathieu Desnoyers To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: Mathieu Desnoyers , tglx@kernel.org, anna-maria@linutronix.de, frederic@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 Subject: [PATCH v14 00/39] sched/deadline: bandwidth accounting fixes and selftests Date: Thu, 3 Dec 2026 09:58:14 -0500 Message-ID: X-Mailer: git-send-email 2.47.3 X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Hi Ingo, Juri, This is v14. It fixes bugs of SCHED_DEADLINE in 30 patches. It applies on top of the first series [1], with its updated patch 10 [2]. In v13, as Juri asked, most changes to priority inheritance moved out into a series of their own. That series applies on top of this one. v13 also added patches 34 to 38 (31 to 35 then). They fix how a rebuild counts a task that left the class or died, and add warnings. The changes since v13 are at the end. Most of the bugs are in the bandwidth accounting. They 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 tasks that would fit. The other bugs give a task more runtime than its reservation. Deadline tasks can then miss their deadlines. Three worse outcomes were found by reading, not reproduced: - A rebuild would hit its BUG_ON() (patch 21). - An rt_mutex owner can keep a task that has exited as its deadline donor. Its next refill would then read freed memory (patch 1). - A task would never run again (patch 2). As Juri asked, the fixes he named come first: 1 to 8. Patches 1 to 4 keep the order he gave for v12. Patches 5 to 8 come from his review of v13. Patches 1 to 8 need none of patches 9 to 39, and apply on the first series alone. Patches 1 and 2 fix priority inheritance too. They stay here for the outcomes above, while the other changes to priority inheritance moved out. Patches 4 and 8 also fix a regression of the first series. With its patches 9 and 11, a constrained task can leave the class and come back after its 0-lag time, but before its next period. It then starts a new period at once, and gets more than its bandwidth. So patches 4 and 8 should be merged with the first series, or right after it. The patches also come in groups, one per theme. A group of fixes ends with the test cases of deadline_bw_test for these fixes. Two groups have no test patch: - Patches 1 to 8. Patches 1 to 3, 5 and 7 have no test case (see "Testing"). The test cases of patches 4, 6 and 8 are in patch 33, with those of the parameter changes. - Patch 27, which has no test case. Patches 31 and 37 are not fixes. Patch 31 prepares patch 32, and patch 37 adds warnings. Juri, patch 11 replaces your fix 1/4, which Ingo dropped from sched/urgent. It records a CPU of the root domain that counts the bandwidth. Your fix took the first active CPU of the task's mask. The other three fixes are in the first series. The groups ========== The fixes that apply on the first series alone (1-8): 1 Hold a reference on the deadline donor of a boosted task. 2 Replenish a throttled task that a waiter boosts while it sleeps, so that it runs again. 3 Divide a change of total_bw by the number of CPUs on 64 bits: a sum of bandwidths can pass S32_MAX. 4 Count the 0-lag time from the next period, not from the deadline. A constrained task then stays counted until it has paid for what it ran. 5 Clear dl_overrun under the rq lock. The plain store could undo a change to another flag of the same word. 6 A task can come back before its 0-lag time. Check its new bandwidth without the old one it still holds, as for a task in the class. 7 Leave an active task alone in the inactive timer. A task that woke up and then died could keep its bandwidth in running_bw and this_bw. 8 Keep the deadline of a constrained task when its bandwidth is released. A task that comes back before its next period then waits for that period. The rebuild of the root domains' accounting (9-14): 9 Keep the bandwidth of departing tasks across a root domain rebuild. A departed task left the class, or died, before its 0-lag time. It waits on dl_departed_list until that time. 10 Rebuild the root domains' accounting from the task list. 11 Record the root domain that holds a task's bandwidth. 12 Leave out of a rebuild a dying task that released its bandwidth. 13 Add deadline_rebuild_test. 14 Add the 7 test cases of deadline_bw_test for this group. cpuset attach (15-20): 15 Move a task's bandwidth only where an attach made room for it. 16 Wait for an attach before rebuilding the sched domains. 17 Make a policy or affinity change of a deadline task wait for a cpuset attach in progress. 18 Give back the bandwidth an attach did not move. 19 Reserve an attach's bandwidth in the root domain each task moves to. 20 Add the 24 test cases of deadline_bw_test for this group. The root domain of a task, with partitions and isolcpus=domain (21-26): 21 Make a rebuild count a task in the root domain it runs in. 22 Move a task's bandwidth to the root domain it runs in. 23 Pick a CPU for a task in the root domain that counts its bandwidth, if the task's mask has a CPU there. 24 Refuse to take offline the last CPU a task has in the root domain that counts its bandwidth. Also refuse an offline that makes a partition invalid and so moves a deadline task to another root domain. 25 Refuse a cpuset change that leaves a deadline task no CPU in the root domain that counts its bandwidth. 26 Add the 40 test cases of deadline_bw_test for this group. extra_bw (27): 27 Count only the active CPUs when a change of total_bw is spread over extra_bw, at an offline migration and at a rebuild. Parameter changes (28-33): 28 Cancel the replenishment timer with the parameters. 29 Cap the runtime left of a constrained task at dl_runtime when its parameters change. 30 Check the runtime left of a task that comes back to the class runnable, as a wakeup does. 31 Record the start of the period. No functional change. 32 Apply new parameters to the period in progress, at the change. A task that ran ahead of its reservation keeps that debt, and repays it at the new bandwidth. A task with no period to apply them to gets the check of a wakeup. 33 Add the 25 test cases of deadline_bw_test for this group. Departed tasks across a rebuild (34-38): 34 Count a task that leaves the class or dies during a rebuild, before the walk of the task list reaches it. 35 Count again a departed task whose bandwidth a rebuild dropped, when a boost brings it back into the class. 36 Put a reaped deadline task on the departed list, so that a rebuild still counts it until its last schedule. 37 Warn when a runqueue keeps the bandwidth of a task out of the class, or of a task whose parameters are cleared. 38 Add the 2 test cases of deadline_bw_test for this group. Priority inheritance triggers the bugs of patches 34 and 35: a deboost during a rebuild, or a boost after one. A task that dies during a rebuild also triggers the bug of patch 34. Both fixes are in the accounting, so they stay in this series. Patch 39 moves the helpers that the three deadline selftests share to a header. Backporting =========== The fixes and patch 31 carry Cc: stable. The test patches do not. Some fixes need other commits: - Patches 5 to 8 need none of each other. Each applies on top of patch 4. - Patch 9 needs patches 6 and 8. It changes the admission check of patch 6: it removes the old bandwidth from the root domain of the CPU that the departed list records. - Patches 9 to 25 go together. Patch 11 records the root domain that counts a task's bandwidth. This record replaces dl_departed_cpu, which patch 9 adds. Patch 12 completes the task list walk of patch 10. Patches 12, 18, 19 and 21 to 25 use the record of patch 11. Patches 18 and 19 rely on the fixes of patches 15 to 17. - Patch 27 changes code that patches 9 to 25 rework, so it comes after them. - Patch 2 relies on patch 1: its refill from the timer reads the donor. - Patch 1 needs commit 8671bad873eb ("sched: Do not call __put_task_struct() on rt if pi_blocked_on is set") on stable trees older than v6.17. Trees older than v6.12 also need tryget_task_struct(). It was added by commit a8532fac7b5d ("sched_ext: TASK_DEAD tasks must be switched into SCX on ops_enable"). Only that helper of the commit is needed. - A backport of these patches of the first series needs patches 4 and 8, for the regression above: - "sched/deadline: Reset the deadline and the runtime with the parameters" (patch 9). - "sched/deadline: Release the bandwidth of a task that leaves the class asleep" (patch 11). Patch 4 needs patch 10 of the first series, which adds dl_time_to_zerolag(). - Patch 31 needs patch 8: dl_release_params() keeps the start of the period with the deadline. Patch 32 needs patch 31. - Patches 34 to 36 change the departed list and the rebuild of patches 9 to 25, so they come after them. Patches 34 and 35 use dl_bw_move_blocked() and dl_bw_skip_gen, which patch 22 adds. Patches 35 and 36 need patch 34. Notes for the reviewers ======================= Peter, I would like your review of the series. Patches 1 and 2 touch priority inheritance. Patch 1 makes a boosted task hold a reference on its donor. dl_set_donor() reads the donor of the top waiter without the waiter's locks. So it takes the reference with tryget_task_struct(). A failed tryget means that another CPU stored a newer donor. dl_set_donor() then reads the donor again. A writer of pi_se that does not hold a reference on the new donor would make every read fail, with interrupts off. So dl_set_donor() stops after 8 reads. It then warns, and uses the top waiter itself as donor. The top waiter is blocked, so it cannot exit. These patches also touch the core scheduler, the exit path or the CPU timers: - 5: check_dl_overrun(), in kernel/time/posix-cpu-timers.c, clears dl_overrun with the new dl_task_clear_overrun(). That takes the rq lock under the siglock. - 10: without CONFIG_CPUSETS, __sched_setscheduler() takes the new dl_accounting_mutex. - 11: __sched_setscheduler() and dl_task_check_affinity() check a deadline task against the root domain that counts its bandwidth, not that of its runqueue. - 15: the new set_cpus_allowed_bw_reserved() flags a move that reserved bandwidth, with SCA_DL_BW_RESERVED. __set_cpus_allowed_ptr_locked() does not skip such a move when the mask does not change. - 17: __sched_setscheduler() and sched_setaffinity() wait for a cpuset attach in progress. - 18: set_cpus_allowed_bw_reserved() reports the bandwidth it moved. - 19: __set_cpus_allowed_ptr_locked() steers a task to the CPU that an attach reserved. - 23: select_fallback_rq() and __set_cpus_allowed_ptr_locked() keep a deadline task in its root domain. - 32: __setscheduler_params() marks a task that comes back to the deadline policy with the same parameters. Its runtime left is then checked as at a wakeup. - 36: release_task(), in kernel/exit.c, calls the new dl_task_unhash() under tasklist_lock. - 37: set_task_cpu() warns when a task out of the deadline class still counts in the this_bw of a runqueue. Waiman, patches 24 and 25 add refusals, with admission control on: - A CPU offline or a cpuset.cpus write fails with EBUSY if it leaves a deadline task no CPU in the root domain that counts it. This needs a cpuset with CPUs of two root domains. - A write that makes a partition root, or makes it grow, still succeeds in that case. cpuset then makes the partition invalid, and cpuset.cpus.partition reads "root invalid (Deadline task would leave its root domain)". If the partition root holds a deadline task itself, making it invalid would move that task. So a write that makes it grow fails with EBUSY instead: see the next item. - A write to cpuset.cpus or cpuset.cpus.exclusive can make a partition root invalid. The write can be to the partition root, or to an ancestor that takes away all its CPUs. It fails with EBUSY if a deadline task in the partition would then change root domain. A write of "member" to cpuset.cpus.partition still removes the partition. - A write to cpuset.cpus or cpuset.cpus.exclusive can make an isolated partition root give housekeeping CPUs back to a parent that is not isolated. The rebuild then takes these CPUs out of the default root domain. Making the partition invalid would give them back too. So the write fails with EBUSY if a deadline task would then have no CPU left in the default root domain. This holds even if the write also grows the partition. - A partition root can give CPUs back to its parent, and take none. While the partition root holds these CPUs, a cpuset that lists only them gets all the CPUs of its parent. Once they are given back, the tasks of that cpuset get only these CPUs. So does a task whose user affinity holds only these CPUs. With isolcpus=domain, these CPUs can be in another root domain than the task. The write to cpuset.cpus or cpuset.cpus.exclusive then fails with EBUSY if a deadline task would have no CPU left in the root domain that counts it. - Patch 24 also refuses an offline that makes a child or a sibling partition invalid, when a deadline task in it would change root domain. An offline can leave a partition with tasks and no CPU of its own. cpuset then makes it invalid, and its tasks count in its parent. Take a parent partition P with no task of its own. Its child partitions hold all its CPUs. An offline takes the last CPU of one of them, C, which has tasks. On a hotplug event, cpuset updates a parent before its children: - It updates P first. The tasks of C do not count in P yet, so P stays valid with no CPU. - It then makes C invalid. The tasks of C now count in P, which has no CPU. - If P has another child partition, cpuset makes the next one that it updates invalid. P takes its CPUs. Else P stays valid with tasks and no CPU, until a later hotplug event. Patch 24 does not model this order. It goes up from the parent while each partition has no CPU of its own. It refuses the offline if a deadline task is under the last of these partitions. The known limits below say what it then refuses, and what it misses. Questions ========= Waiman, two questions on patch 24: - Would you prefer cpuset to offer a dry run of its hotplug update, as a follow-up? It would be exact, but too large for stable. - An offline can leave a partition valid with tasks and no CPU, until the next hotplug event. Is that state intended? Known limits ============ These limits stay open: - Patch 8: a constrained task that leaves the class 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. - Patch 8: a boost by priority inheritance replaces the deadline that a departed task kept, and the deboost clears it. If the task then comes back before its next period, it starts a new period at once, as without patch 8. The priority inheritance series will handle this case. - Patch 8: 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 its bandwidth at once, as on v7.4-rc2. This is before the 0-lag time of the new period, so the root domain can admit another task into that bandwidth too early. The task keeps its deadline, so it gains no runtime. For this, the CPU of the handler must stall for about a period of the task, between the start of the handler and task_rq_lock(). A preempted vCPU can do this. Juri asked to leave this window open, and to list it here. - Patch 9: a task keeps its bandwidth until its 0-lag time after it leaves the class or dies. A rebuild still drops that bandwidth if the CPU recorded with it is inactive. The root domain that counted it can then no longer be found. total_bw then misses it until that time. Patch 35 counts it again if a boost brings the task back into the class. - Patch 9: a write can put the CPU recorded with a departed task into a new partition root. The rebuild then counts the bandwidth of the task in the new root domain, until its 0-lag time. That root domain can refuse tasks meanwhile. The old root domain of the CPU no longer counts the task, and can admit too much. On v7.4-rc2, the rebuild drops that bandwidth instead. - Patch 9: a task can come back to SCHED_DEADLINE before its 0-lag time, in another root domain than the one that counts its old bandwidth. sched_dl_overflow() then adds the new bandwidth, and removes the old one in a second lock section. In between, the old root domain can refuse a task. - Patch 22 moves the bandwidth of a task to the root domain it runs in with no check for room. dl_task_offline_migration() does the same on v7.4-rc2. - Patch 23: a wakeup inside a rebuild of the sched domains can still move a task's bandwidth to another root domain. It moves with no check for room. This was found by reading. - Patches 24 and 25 refuse nothing during a suspend, or with admission control off. - Patch 24 can refuse an offline that keeps each task in its root domain. This needs nested partitions whose parents have no CPU of their own. - Patch 24 does not check a deadline task that enters a partition after an offline left a parent partition valid with tasks and no CPU. The next hotplug event, an online too, can then move it to another root domain with no check for room. - Patch 24 does not see a task that sched_setattr() makes a deadline task during the offline. That task can then run in a root domain that did not admit it. The bandwidth test of dl_bw_deactivate() has the same window. This was found by reading. - Patch 25 accepts a write that grows a partition root and makes a child partition valid. The child takes the CPUs on which the parent's deadline tasks were admitted. Those tasks then run on the CPUs that the parent just got, in a root domain that did not admit them. On v7.4-rc2, a rebuild does the same. - Patch 25 accepts a write of "member" to cpuset.cpus.partition of a partition root that holds a deadline task. Its tasks then count in the root domain of the parent, with no check for room. This is as on v7.4-rc2. A refusal would keep an administrator from removing the partition while its deadline tasks run. - Patch 25 does not check the room for the deadline tasks of a cpuset that a write makes a partition root. The rebuild counts them in the new root domain, as on v7.4-rc2. In a test, that root domain then counted 125% of its capacity. Deadline tasks that use all their runtime would then miss deadlines there. sched_setattr() refuses new deadline tasks there until it has room again. - Patch 25 does not check a write that makes two invalid child partitions valid. Take a write to the CPUs of a partition root with two invalid child partitions. When the first child takes its CPUs, update_sibling_cpumasks() gives the remaining CPUs to the second child and its tasks, with no check. Those tasks would then run in a root domain that did not admit them. This is as on v7.4-rc2, and was found by reading. - Patch 25 can make an isolated partition root invalid when the change is safe. If the partition root holds a deadline task itself, the write fails with EBUSY instead. Take a write that makes it take CPUs and give others back to its parent. The check does not count the CPUs given back as CPUs of the root domain of the parent. Until the rebuild, these CPUs are still in the default root domain. Counting them would accept a write that leaves a deadline task of the default root domain with no CPU after the rebuild. An administrator can make the change in two writes: make the partition a member, then an isolated partition root of its new CPUs. - The XXX in dl_bw_capacity(), which Juri pointed at in the v5 thread, stays open. In the default root domain, admission control counts the capacity of all its CPUs, not that of the CPU the task runs on. A deadline task in a cpuset with isolated and housekeeping CPUs is admitted that way. - A cpuset attach frees the bandwidth of a task in the root domain it leaves at once, even before the task's 0-lag time. That root domain can then admit a task up to one period too early [3]. A task moved while runnable also keeps its runtime and deadline in the root domain it arrives in (Example 3 of [4]). Both are as on v7.4-rc2. - Patch 32: admission control releases the old bandwidth at the change. Right after a cut of bandwidth, a task admitted into the released bandwidth would rarely miss a deadline near the change. The simulator below shows it. - Patch 32: two costs fall on the task that changes its parameters. With a constrained deadline, a job that already used the new dl_runtime ends at the change. A task that waits for its next period and changes its constrained dl_deadline back and forth moves that period later at each shorter dl_deadline. - Patch 32 does not apply new parameters to the period of a boosted task. The first enqueue after its deboost checks its runtime left, as a wakeup does. That check can start a new period at once. The task then loses its debt, as on v7.4-rc2. The priority inheritance series also fits the period of a boosted task to new parameters. Testing ======= On top of the first series, the 153 test cases of the three deadline selftests pass wherever they run, with lockdep and no kernel warning. deadline_bw_test has 145 of them. They ran in 20 QEMU guests of 4 to 8 vCPUs: - with proxy execution on and off. - with PREEMPT_RT. - without CONFIG_CPUSETS. - with CONFIG_RT_GROUP_SCHED. - booted with isolcpus=domain on CPUs 1-2, 0-1 or 6-7, some with PREEMPT_RT. The 31 test cases that need isolated CPUs skip in the guests without them. No guest combines isolcpus=domain with a kernel without CONFIG_CPUSETS: such a kernel hits a BUG at boot on v7.4-rc2 [5]. At each test patch, the kernel and the test cases of that patch pass in 12 guests of the same kinds. Three guests with kmemleak ran the whole series: no leak. On top of the first series, the series builds at each of its 39 patches. At each patch, it also builds with tinyconfig, without CONFIG_RT_MUTEXES. At each test patch, the series also builds without CONFIG_CPUSETS, with PREEMPT_RT and with CONFIG_RT_GROUP_SCHED. The selftests build there with no warning. The cpuset selftest test_cpuset_prs.sh passes, with and without PREEMPT_RT. Each fix names the test cases that test it. Each test patch says which of its cases fail, and without which fix. These changes have no test case: - patches 2, 12 and 27: they were found by reading. - patch 3: it needs a machine with more than 2048 CPUs. - patch 1: it needs a chain walk preempted at the right step. - the bound of 8 reads in patch 1: it only acts if a writer of pi_se does not hold a reference on the new donor, or if 8 donors exit during the loop. - patch 5: the store must race with a change of another flag of the same word. The window is a few instructions, or a preemption with PREEMPT_RT. - patch 7: the timer handler must wait for the rq lock while the task wakes up and exits. - patch 28: it has no reproducer. - patch 31: it changes no behaviour. - patch 36: a Spin model found it (see below). Its window, from release_task() to the last schedule of the task, is too short for a test. - patch 37: it adds warnings. They do not fire in any of the runs above. - the change of patch 23 in dl_task_offline_migration(): it needs a timer that fires between a CPU going inactive and the cpuset update. - one change of v11 in each of patches 11, 21 and 24. They were found by reading. - the changes of v12. - the change of v13 in patch 32. - the changes of v14 in patches 21, 23, 34, 35 and 36. The changes of v12 to v14 come from the Sashiko reviews of v11 to v13, and from a second LLM review of the fixes. Those of v14 also come from Juri's review of v13. The test cases above pass with them. These were not tested: - cgroup v1 cpusets. - threaded cgroups: every move is a write to cgroup.procs. - the sched_ext server. - CPUs of unequal capacity. 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, and his reviews of v5 and v13. - building deadline_bw_test, and reading the code. - the Sashiko AI reviews of v1 to v13, and of the first series, plus a local run on the patches that changed for v11. Each finding was checked against the code first. - second LLM reads of the fixes and of the harder findings. They found the gaps fixed in patches 1, 23 and 24. - kmemleak, which found a leaked task_struct in an early version of patch 1. - a rare failure of the random_mix case of deadline_bw_test, on top of the priority inheritance series. Reading the accounting code for its cause found the bugs of patches 34 and 35. The likely cause itself was in the test. Since v13, the cases of patch 33 that use a one-CPU partition root wait until this_bw is back to its value before the case. Kernel traces taken with LTTng did not catch the failure. - a Spin model of the bandwidth accounting, which found the bug of patch 36, and the bug of patch 34 again. The rule of patch 32 was first checked in a user-space model of the CBS on one CPU. Two independent LLM reviews of that model found the problem of a task that moves to a constrained deadline, which patch 32 now covers. For v11, the assistant extended that model into a simulator of SCHED_DEADLINE on one CPU. It models these parts: - EDF over several tasks, and the CBS rules. - admission control on total_bw. - class changes, and rt_mutexes with priority inheritance. It has the rules of an earlier version of this series, transcribed by hand from the code. A search over small task sets, random and adversarial, checks two properties: - no task gets more than its bandwidth. - an admitted task meets its deadlines. Without rt_mutexes, those rules show two exceptions only: - the transient after a cut of bandwidth, which the known limits state. - misses in task sets with a density above 1, which admission by bandwidth does not exclude for constrained deadlines. With rt_mutexes, it found cases that the priority inheritance series covers. The search did not run on the rules of v13. The simulator also replays several test cases, and Example 1 of [4]. It is not part of this series. I can share it. For v13, the assistant also wrote a Spin model of the bandwidth accounting. It models this_bw, total_bw, the departed list, the rebuild and the boosts of priority inheritance. It has the rules of v13 with the priority inheritance series on top. It was first checked on a known bug. Without "sched/deadline: Fix this_bw when a task is changed during a remote wakeup", from the first series, it finds that bug again. With patches 31 to 33 of v13, it finds no error for two tasks and one root domain, with every CPU active. The model does not have the changes of v14. It assumes sequential consistency: it does not check memory ordering. It is not part of this series. I can share it. Changes since v13 ================= Juri's review of v13 patch 5 led to patches 5 to 8. Patches 5 and 6 are new fixes that he found. Patch 7 is the check in the inactive timer that v13 patch 5 had, now a fix of its own. Patch 8 replaces the rest of v13 patch 5, as Juri suggested. The series now has 39 patches. Patches 6 to 36 of v13 are now 9 to 39, with the same subjects. Patch 1 now has Juri's Reviewed-by. Patch 22 changed because of a posted proxy execution patch. The other changes come from Juri's review of v13 patch 5, and from the Sashiko AI review of v13. These patches changed: - 5 (new): check_dl_overrun() cleared dl_overrun without the rq lock. Juri found this. - 6 (new): sched_dl_overflow() checked a task that comes back before its 0-lag time with its old bandwidth still counted. Juri found this. The new test case params_return_full, in patch 33, tests it. - 7 (new): inactive_task_timer() now leaves alone a task that is back in the class and active. v13 had this check in patch 5. As Juri noted, it fixes a race of v7.4-rc2 on its own. - 8 (v13 patch 5): rewritten as Juri suggested. The bandwidth goes back at the 0-lag time, as on v7.4-rc2. A constrained task keeps its deadline, with no runtime left. v13 kept the bandwidth until the next period. That needed a timer that restarts itself, and the flag dl_inactive_pending. Both are gone. - 9 (6): in v13, a task could leave the class while its inactive timer handler ran. task_non_contending() then left the release to that handler, and put the task on the departed list. Patch 8 now releases the bandwidth at once in that case, so patch 9 no longer puts the task on the list. If the root domain that admits a returning task counts its old bandwidth, sched_dl_overflow() swaps the old and the new bandwidth in one lock section. - 21 (18): a rebuild can leave a task out, so that no root domain counts its bandwidth. A cpuset attach now reserves room for such a task in its destination, then counts it there. In v13, the attach would reserve no room, and the next wakeup would count the task with no check. - 22 (19): a blocked task that moves to the CPU of a mutex owner now keeps its bandwidth where it is. Proxy execution makes this move, and the task moves back when it wakes up. Its bandwidth stays in the root domain it left, so that no other task takes its room meanwhile. A posted proxy execution patch, "Invoke migrate_task_rq() on proxy-migration", makes that move call migrate_task_rq_dl() [6]. Another move of a blocked task, such as an affinity change, still takes the bandwidth along. enqueue_task_dl() now moves it. - 23 (20): dl_bw_def records whether the default root domain counts a task. A rebuild can move a CPU into or out of the default root domain. So a rebuild that counts a departed task now sets dl_bw_def again. - 25 (22): it now refuses a write that would make a partition root invalid and move a deadline task to another root domain. It also checks a partition root that only gives CPUs back. See the notes for Waiman above. - 26 (23): four new test cases for these refusals. - 31 (28): dl_release_params() also keeps the start of the period. - 33 (30): the new case params_return_full. Test code that only the series on priority inheritance uses moves to that series. - 34 and 35 (31 and 32): a task counted outside the walk of the task list is now counted on a CPU picked by the new dl_task_count_cpu(). It picks the CPU as the walk does, but does not ask the cpuset. v13 preferred the CPU of the task. That CPU can be offline, or outside the mask of the task. - 36 (33): - dl_task_unhash() reads dl_bw under the rq lock, which sched_setattr() takes to admit the task. - A reaped task can still run in the class. If the CPU recorded with it is inactive, a rebuild now counts it on an active CPU of its mask. v13 dropped its bandwidth. - A boost can bring an exited task back into the class during a rebuild of the sched domains. That rebuild now counts it. - 38 (35): pi_deboost_during_rebuild no longer reads out of bounds with fewer than 4 non-isolated CPUs. The first series is based on tip sched/urgent, ec6f6731538e (v7.4-rc2). [1] https://lore.kernel.org/all/cover.1795115075.git.mathieu.desnoyers@efficios.com/ [2] https://lore.kernel.org/all/d975f317a4f9f79d2300b68ad76664755459ba36.1795181168.git.mathieu.desnoyers@efficios.com/ [3] T. Cucinotta, L. Abeni, "Migrating Constant Bandwidth Servers on Multi-Cores", RTNS 2021, section 4 [4] S. Tang, J. H. Anderson, L. Abeni, "On the Defectiveness of SCHED_DEADLINE w.r.t. Tardiness and Affinities, and a Partial Fix", RTNS 2021, https://doi.org/10.1145/3453417.3453440 [5] https://lore.kernel.org/lkml/20261117144817.265109-1-mathieu.desnoyers@efficios.com/ [6] https://lore.kernel.org/lkml/20261202035248.1210026-9-jstultz@google.com/ v13: https://lore.kernel.org/all/cover.1796146461.git.mathieu.desnoyers@efficios.com/ v12: https://lore.kernel.org/all/cover.1795771147.git.mathieu.desnoyers@efficios.com/ v11: https://lore.kernel.org/all/cover.1795646914.git.mathieu.desnoyers@efficios.com/ v10: https://lore.kernel.org/all/cover.1795207232.git.mathieu.desnoyers@efficios.com/ v9: https://lore.kernel.org/all/cover.1795181240.git.mathieu.desnoyers@efficios.com/ v8: https://lore.kernel.org/all/cover.1795116790.git.mathieu.desnoyers@efficios.com/ v7: https://lore.kernel.org/all/cover.1794922146.git.mathieu.desnoyers@efficios.com/ v6: https://lore.kernel.org/all/20261116190549.230119-1-mathieu.desnoyers@efficios.com/ v5: https://lore.kernel.org/all/20261108185406.1549770-1-mathieu.desnoyers@efficios.com/ v4: https://lore.kernel.org/all/20261107014451.1487825-1-mathieu.desnoyers@efficios.com/ Mathieu Desnoyers (39): sched/deadline: Hold a reference on the deadline donor of a boosted task sched/deadline: Replenish a throttled task boosted while asleep sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() sched/deadline: Count the 0-lag time from the next period sched/deadline: Clear dl_overrun under the rq lock sched/deadline: Admit a returning task without the bandwidth it holds sched/deadline: Leave an active task alone in the inactive timer sched/deadline: Keep the deadline of a departed constrained task sched/deadline: Keep departing bandwidth across a root domain rebuild 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 selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild selftests/sched: Test the root domain rebuild in deadline_bw_test sched/deadline: Move a task's bandwidth only where room was made cgroup/cpuset: Wait for an attach before rebuilding the sched domains sched: Make deadline policy and affinity changes wait for a cpuset attach cgroup/cpuset: Give back the bandwidth an attach did not move cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to selftests/sched: Test cpuset moves in deadline_bw_test sched/deadline: Make a rebuild count a task in the root domain it runs in sched/deadline: Move a task's bandwidth to the root domain it runs in sched/deadline: Keep a task in the root domain that counts its bandwidth sched/deadline: Keep the last CPU a task has in its root domain cgroup/cpuset: Refuse to take a deadline task out of its root domain selftests/sched: Test the root domain of a task in deadline_bw_test sched/deadline: Count only active CPUs when spreading extra_bw sched/deadline: Cancel the replenishment timer with the parameters sched/deadline: Cap the runtime left of a constrained task at dl_runtime sched/deadline: Check the runtime of a task that comes back runnable sched/deadline: Record the start of the period sched/deadline: Keep the debt of a task across a change of parameters selftests/sched: Test parameter changes in deadline_bw_test sched/deadline: Count a task that departs while a rebuild walks the tasks sched/deadline: Count again a departed task that a boost brings back sched/deadline: Keep a reaped deadline task in a rebuild sched/deadline: Warn when a runqueue keeps the bandwidth of a task selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test selftests/sched: Share the helpers of the deadline tests Documentation/scheduler/sched-deadline.rst | 12 +- include/linux/cpuset.h | 28 +- include/linux/sched.h | 51 + include/linux/sched/deadline.h | 44 +- kernel/cgroup/cgroup.c | 3 - kernel/cgroup/cpuset-internal.h | 15 +- kernel/cgroup/cpuset.c | 1076 +- kernel/exit.c | 2 + kernel/sched/core.c | 151 +- kernel/sched/deadline.c | 2041 +++- kernel/sched/sched.h | 89 + kernel/sched/syscalls.c | 124 +- kernel/sched/topology.c | 11 + kernel/time/posix-cpu-timers.c | 4 +- .../selftests/sched/deadline/.gitignore | 1 + .../testing/selftests/sched/deadline/Makefile | 4 +- .../sched/deadline/deadline_bw_test.c | 9240 ++++++++++++++++- .../sched/deadline/deadline_rebuild_test.c | 501 + .../sched/deadline/deadline_switch_test.c | 36 +- .../selftests/sched/deadline/deadline_util.h | 106 + 20 files changed, 13009 insertions(+), 530 deletions(-) create mode 100644 tools/testing/selftests/sched/deadline/deadline_rebuild_test.c create mode 100644 tools/testing/selftests/sched/deadline/deadline_util.h base-commit: ec6f6731538e0d45872eb279fdeb477bed152d6f prerequisite-patch-id: 5e2478ffdfb7583751bf44bdf87fb930bc23551b prerequisite-patch-id: d5e5ef986ff2d9bc39a87b56e96a2acbd3158687 prerequisite-patch-id: 99e47f80396008ee2b2576157d37842481ce52d2 prerequisite-patch-id: a10824f98c11a4c902dad55cab3ec03b3dbe2c8a prerequisite-patch-id: 8959e5a408641b4fa81bc79737cd17d5f1b03389 prerequisite-patch-id: 16acf1d18f01d20310d6db767dfbec2f072e0372 prerequisite-patch-id: e1946bb015a7b14ed4e2cd0421e5e30b0c7afdda prerequisite-patch-id: 4daf48a89779fbd8c8bc5fc1d7a7d6df9bca2d9d prerequisite-patch-id: 980d8045f9fe8c3757bb3d82c61d68e321cf74bb prerequisite-patch-id: b2d75d7b3eebbda11af43b3917b1c99e0cce2725 prerequisite-patch-id: fb69a0665dc38ca9022cc2bd75234a90e2035b7f prerequisite-patch-id: 7a115ab83ad96ffaf8e833e0eaeb75f859af2e79 prerequisite-patch-id: 8574b50d81a09ec6091e42d65338adcab2986d71 prerequisite-patch-id: 1aa25df96d60d30f549c71fdfba5589cb239928f prerequisite-patch-id: d38384e0b7d043a3556ee02fb09316a6227038da prerequisite-patch-id: 83ded04a76ecf973e2b8c6e04ff83c2b7278915a prerequisite-patch-id: b8f5d9f9146e887050bbd8ad30463fd81cad9411 -- 2.47.3