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=1796309956; b=wIp0EJO+GWRBnzHLtbFySc4K8t7xNIjFpDI5ozvVf7cj3bwaHPvlPkZoRrjYS2KKtniN sqiQN7EIjhe1J5S+H7tQIGxaPYcMFvTvmw/jgIytDWa4PRU5ACGCrMKHC15ZFK1a5b4Mk 0suRXKtXOXaF0x6sYtQ5UzJB1MHhdqgENe39sVo5OF4/dCNNcpmB+WTlBbptQ0cVjyaXe dhz7P7QavOJ1jqVhw5mtOpsU9T37PViH0lHt0ZQMkCB1Dg8NKPmLSglU8O2WoDTLArWEs /vjB7u/UkXuQo18w5y3kKhip4jxuJPCC6i/hB87S46pScCL3tNFOcYS8ollysO/bYOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309956; 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=4gic6dSef5khaVhAZ0GHCuggiUvMdrB1RnJku1jg3pY=; b=IB8Of3Jqhn3ivJvpXx+t6wVabOY08FFl/5NDv+NQ0RKXbBj3kzidXaoHTZeEMJEBc1en j5jBpV/4wqMMZWBBAssnnvnPtNWP6fg0ves9NrWugHJ7zbMwaa73SktcWOCwufEO/Ywks Q/Qh5rfktLySSgn+71VQoIAjWMTZEkI/r6SQOzlsvD5VF9zQ3JbwHRdl8ilPtCNplODmt hgUZmURLRSsHNbhzQK01KKDmJezC0pJo1su3QvjmwXPZMoCkw9QaCI0TzLWyMgPM+Qfq3 7Ir/R0FyrEvqgpO5xwB/bpfYy16VnHl4JH3aa5K0EzTWROTDriZO7vzBWzSP3Av8wdg== 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=wcB4lvya; 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 027F9606A693; Thu, 3 Dec 2026 14:59:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 027F9606A693 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=wcB4lvya DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796309955; bh=4gic6dSef5khaVhAZ0GHCuggiUvMdrB1RnJku1jg3pY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wcB4lvyakUQx7Gt2ZTeDOKJDCG2MAeGXoSDq+C6319COk4uqCsKaUeyzBB4VTOoXH d5NcsIL8BSj+XYi1mmLBdDs5ZYzXiByVBLg5msuQsoXBgIR1B0WPjwTMp+Rq3FgPyK qME2ore7DasuRmRWVttdOOy3Q7PeBwwcWn3IbbMDSh6XDtrroNtD04T8mEuA/K5JFX BznznDxjGQCxO6Uu8vhQ38O2n7jHcLUf1nIGSIzcmlRo+zUF7Pa407glTIJOcxnROn KTxvC+T6bZwLJwoaIofNG0WicW+iuzmIEI4mNhZ6/LY9CrcQok7rTWjBKHPgtVrdaJ dUyS40XtkY1cg== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHp953bFzZxG; Thu, 03 Dec 2026 09:59:13 -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, stable@vger.kernel.org Subject: [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task Date: Thu, 3 Dec 2026 09:58:22 -0500 Message-ID: <65864008a1fdbd111bd0612860a4ccad3f4c7a75.1796296313.git.mathieu.desnoyers@efficios.com> 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 A task that leaves SCHED_DEADLINE keeps its bandwidth until its 0-lag time, so that leaving and coming back gains nothing. Two patches of the first series, which this one applies on, also clear its deadline at that time: - "sched/deadline: Reset the deadline and the runtime with the parameters" resets the deadline in __dl_clear_params(). - "sched/deadline: Release the bandwidth of a task that leaves the class asleep" calls __dl_clear_params() for a task that leaves asleep with no timer pending. For an implicit deadline, this changes nothing. A wakeup after the 0-lag time starts a new period anyway. A constrained task is different. Commit df8eac8cafce ("sched/deadline: Throttle a constrained deadline task activated after the deadline") throttles a task that wakes up after its deadline until its next period. Without its deadline, a task that comes back before its next period starts a new period at once. Repeated, this gives the task more than its bandwidth. Other deadline tasks could then miss their deadlines. For example, take a task with a runtime of 10ms, a deadline of 20ms and a period of 500ms. Its period starts at 0ms. 1. It runs 2ms, then sleeps with 8ms left. Its 0-lag time is 500 - 8 * 500 / 10 = 100ms. 2. At 150ms, another thread calls sched_setattr() to make it SCHED_OTHER, then SCHED_DEADLINE again. The 0-lag time has passed, so leaving the class releases its bandwidth and clears its deadline. 3. At 155ms, it wakes up. Its wakeup starts a new period at once, not at 500ms. Between 0ms and 500ms, it can run 12ms, not 10ms. Fix this by keeping the deadline of a constrained task when its bandwidth is released, with no runtime left. A task that comes back then follows the rules of a task asleep in the class. In the example, dl_check_constrained_dl() throttles it at 155ms until 500ms. The bandwidth is still released at the 0-lag time. The two patches named at the top carry Cc: stable. A backport of them needs this patch, and "sched/deadline: Count the 0-lag time from the next period" before it. The reenter_asleep_late_in_gap case of deadline_bw_test runs the example above. "selftests/sched: Test parameter changes in deadline_bw_test", later in this series, adds it. The case fails without this patch, and passes with it. Suggested-by: Juri Lelli Signed-off-by: Mathieu Desnoyers Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@jlelli-thinkpadt14gen4.remote.csb/ --- kernel/sched/deadline.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index c88cac6bc5fe..422a8120454a 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -377,6 +377,7 @@ static void dl_change_utilization(struct task_struct *p, u64 new_bw) static inline u64 dl_next_period(struct sched_dl_entity *dl_se); static void __dl_clear_params(struct sched_dl_entity *dl_se); +static void dl_release_params(struct sched_dl_entity *dl_se); /* * Return the time from now to the 0-lag time of @dl_se, or a negative @@ -551,7 +552,7 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task) raw_spin_lock(&dl_b->lock); __dl_sub(dl_b, dl_se->dl_bw, dl_bw_cpus(task_cpu(p))); raw_spin_unlock(&dl_b->lock); - __dl_clear_params(dl_se); + dl_release_params(dl_se); } } @@ -2341,7 +2342,7 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) raw_spin_lock(&dl_b->lock); __dl_sub(dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p))); raw_spin_unlock(&dl_b->lock); - __dl_clear_params(dl_se); + dl_release_params(dl_se); goto unlock; } @@ -3682,7 +3683,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p) * the "inactive timer" fires, it can continue to consume its current * runtime using its current deadline. If it stays outside of * SCHED_DEADLINE until the 0-lag time passes, inactive_task_timer() - * will reset the task parameters. + * will reset the task parameters. A constrained task keeps its + * deadline: see dl_release_params(). */ if (task_on_rq_queued(p) && p->dl.dl_runtime) task_non_contending(&p->dl, false); @@ -4155,6 +4157,29 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se) dl_se->dl_bw_oncpu = 0; } +/* + * Clear the parameters of a task which left the class, once its + * bandwidth is released. A task with a constrained deadline keeps its + * deadline. Leaving the class and coming back before its next period + * then gives it no new runtime. Back in the class, it waits for that + * period, as a task asleep in the class does: + * - between its deadline and its next period, dl_check_constrained_dl() + * throttles it; + * - before its deadline, it has no runtime left. + * + * An implicit deadline task keeps nothing. In the class too, a wakeup + * after its 0-lag time starts a new period. + */ +static void dl_release_params(struct sched_dl_entity *dl_se) +{ + u64 deadline = dl_se->deadline; + bool constrained = !dl_is_implicit(dl_se); + + __dl_clear_params(dl_se); + if (constrained) + dl_se->deadline = deadline; +} + void init_dl_entity(struct sched_dl_entity *dl_se) { RB_CLEAR_NODE(&dl_se->rb_node); -- 2.47.3