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=1796147084; b=R8PUQD5erlcKe4+dK3gTow/FUh4/nkVaPhlbCqKpwpd8b+sqLnVXvrTA0N9r+IY7auR2 c651E33ZDjmwTgDCJi+pnjIFs+OdWXIGhoPCpTgYXv+pN7lYHQ1AsrQuxXmWpMLRx129U qMb5tg0jd2O/F1XqExT1giJm/SnrGu2Yj8RGxAi5GNrfCmIIzLcKe3vbzhnp0IshSaUm+ GD1++gluPNiomhPJN6aQaOYOEWu8GqfdOmLkEtRYcsVbY5D+KhfomUHBmf+PQYMwBeSUr sqZM3atYHQ32DlIj1dZRiF2FiFxxychAJXnNjKx/blc95/eRdiJIhaf8Nz+cj87bvgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147084; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=jGaxkwuH+37oEweWdoxkOQKsg92YVP7m20Pb479H2jc=; b=n3oyqXV6AywdzObYquvRCXN72soOjYmfVirYNQlM7GKGj4Gsr0ywyhUQi7SG5wPeIwhM WVVQN9c9ylmhUyh6Z0RFIksL2znvnPn+g2qmOpbrmjtVzjlquKJQBY/HD9yi9V6pt2Kxg PhCL+/Mz/AqoeDBTkOiWyBqfTRVBHuuLkJvpmZdNN7CHiVe67zLxnN1cFuPSL9NygUV7m yRmbr9bum3Ht7i8/nbm9nm8E2ppqSiLGtthwsiFugTvBuTUnQIQVWJ4sxxEFPRH5tPLMu uP9pm2Z3tfX1WBgpTapveQtPGQdFd6Sz2sd/Bg5XWdZ4mGVgzx+hnA3Huvb9aT5pcQA== 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=Ssog4b0r; 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)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CE8460A6F6C; Tue, 1 Dec 2026 17:44:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0CE8460A6F6C 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=Ssog4b0r DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796147078; bh=jGaxkwuH+37oEweWdoxkOQKsg92YVP7m20Pb479H2jc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ssog4b0r44CK7LZOPFuH3H4SQcj4MuT4HhDuyynFx/JDJSUhBKHrw7X/tsCnhTzZH Ii1UK6ResCxWZ3L2DF4jaSyq8Oqo1n9kpU3N/Oomj32kAn2mw7hRJixK6BtZS6DTaT QfzlbBW0XyCf73uhaCz6PEnprPLkz8LxOpxT++czWM+ECe5GCPUHKlU5+DdsC+77k5 fqIJIOjF5fpVlndoBeQQxkPcG2Um1r8gqcB3VT21hYkSLcnotRrEBkqbazdfQfOC5w x1rzE9dyrZActvch4hdjumx2NU+xhCosCcjBUhOMnrUE7M3J6DoGHdbOyoYfBCPBIt ysDXwU4TLPYXw== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jf7Yy65zLzYk4; Tue, 01 Dec 2026 12:44:38 -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, 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, stable@vger.kernel.org Subject: [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks Date: Tue, 1 Dec 2026 12:44:25 -0500 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: X-Mailing-List: linux-kernel@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 dl_rebuild_rd_accounting() rebuilds the root domains' accounting in two steps. First, dl_clear_root_domains() clears the root domains. Then it puts back the bandwidth of the departed tasks, which left SCHED_DEADLINE or died before their 0-lag time. Second, the walk of the task list counts each deadline task. A task can leave the class after the clear, before the walk reaches it: priority inheritance can deboost it. The walk then finds a task out of the class, and skips it. Neither step counts its bandwidth. The comment above dl_departed_list lists this as a known gap. In this example, the deadline task W waits with a timeout on an rt_mutex that T holds. T was a deadline task too. While W boosted it, sched_setattr() switched T to SCHED_OTHER. The boost keeps T in the class, with its bandwidth. W runs on CPU 1. CPU 0 rebuilds the accounting, for example after a write to cpuset.cpus.partition. CPU 0 CPU 1 ----- ----- dl_rebuild_rd_accounting() dl_clear_root_domains() clear total_bw put back the departed tasks W times out: remove_waiter() rt_mutex_setprio(T) switched_from_dl(T) dl_task_depart(T) T joins the departed list walk of the task list reaches T T is out of the class: skip it total_bw then misses the bandwidth of T until its 0-lag time. Meanwhile, sched_setattr() can admit tasks beyond the capacity of the root domain. Fix this by counting such a task in dl_task_depart(), as the walk would have. dl_bw_move_blocked() already tells whether the walk has yet to reach the task. Count the task on the CPU it departs from, or else on the CPU recorded with it, or else on an active CPU of its mask. If none is active, leave it out, as the walk does. A task that dies in the same window departs too. The walk counted it from the departed list, unless release_task() had taken it off the task list. dl_task_depart() now counts it in both cases. This was found by reading the code, and by a Spin model of the accounting. The pi_deboost_during_rebuild case of deadline_bw_test races the timeout with the rebuild. It failed in 35 of 43 runs without this fix, and passed in 35 of 35 with it. "selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test", later in this series, adds the case. Fixes: f9a25f776d78 ("cpusets: Rebuild root domain deadline accounting information") Signed-off-by: Mathieu Desnoyers Cc: stable@vger.kernel.org --- kernel/sched/deadline.c | 54 ++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 7aa6c3f7e99d..ef97b07c0aa2 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -253,12 +253,14 @@ __dl_overflow(struct dl_bw *dl_b, unsigned long cap, u64 old_bw, u64 new_bw) * harmless. * * A rebuild drops the bandwidth when the CPU recorded is no longer - * active. It also drops the bandwidth of a task that dies while the - * rebuild runs. The walk of the task list does not find that task, and - * it was not dead yet when the list was put back. The same happens to a - * task that priority inheritance deboosts while the rebuild runs. It was - * in the class when the list was put back, and out of it when the walk - * reaches it. + * active. It also drops the bandwidth of a task that release_task() + * took off the task list, if its last schedule comes after the walk. + * The walk does not find that task, and it was not on the departed + * list when the list was put back. + * + * A task can also depart after the list was put back, and before the + * walk reaches it. Priority inheritance can deboost it, or it can die. + * dl_task_depart() then counts it, as the walk would have. * * dl_departed_lock protects the list and both counts. Take it with * interrupts disabled, under the task's rq lock or pi_lock or in the @@ -376,6 +378,23 @@ bool dl_task_holds_bw(struct task_struct *p) return dl_se_holds_bw(&p->dl); } +/* + * Add the bandwidth of @p to the root domain of @cpu, for a task that no + * root domain counts now. Record @cpu, and date the record with the + * current dl_bw_gen. The caller holds dl_departed_lock. + */ +static void dl_task_count_bw(struct task_struct *p, int cpu) +{ + struct dl_bw *dl_b = dl_bw_of(cpu); + + lockdep_assert_held(&dl_departed_lock); + raw_spin_lock(&dl_b->lock); + __dl_add(dl_b, p->dl.dl_bw, dl_bw_cpus(cpu)); + raw_spin_unlock(&dl_b->lock); + dl_record_bw_cpu(&p->dl, cpu); + p->dl.dl_bw_gen = dl_bw_gen; +} + /* * Put @p on dl_departed_list. The root domain of the CPU recorded with it * keeps its bandwidth. @p leaves SCHED_DEADLINE, or dies, before its @@ -400,6 +419,24 @@ static void dl_task_depart(struct task_struct *p) if (dl_se->dl_bw_gen == dl_bw_gen && !dl_bw_rebuilding() && cpu_active(cpu) && cpu_rq(cpu)->rd == cpu_rq(dl_se->dl_bw_cpu)->rd) dl_record_bw_cpu(dl_se, cpu); + /* + * dl_clear_root_domains() counted the departed tasks, and the walk + * of the task list counts the deadline tasks. A task that departs + * after the clear, before the walk reaches it, would be counted by + * neither. Count it here, as the walk would have. Use the CPU it + * departs from, or else the CPU recorded, or else an active CPU of + * its mask. If none is active, leave it out. While the sched domains + * are rebuilt, the clear is still ahead, and finds the task on the + * list. + */ + if (dl_bw_move_blocked(p) && !dl_bw_rebuilding()) { + if (!cpu_active(cpu)) + cpu = dl_se->dl_bw_cpu; + if (!cpu_active(cpu)) + cpu = cpumask_first_and(cpu_active_mask, &p->cpus_mask); + if (cpu < nr_cpu_ids) + dl_task_count_bw(p, cpu); + } list_add(&dl_se->dl_departed_node, &dl_departed_list); } @@ -4539,9 +4576,8 @@ void dl_add_task_root_domain(struct task_struct *p) * dl_clear_root_domains() put it back as a departed task, and * priority inheritance boosted it into the class since. Or it died * since the rebuild started, and dl_task_release_bw() released its - * bandwidth. A task that died since with its 0-lag time ahead is on - * the departed list. Count it in the root domain of the CPU - * recorded, if that CPU is active. + * bandwidth. Or it departed before the walk reached it, and + * dl_task_depart() counted it. */ if (p->dl.dl_bw_gen == dl_bw_gen) goto unlock; -- 2.47.3