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=1796309998; b=lpOKJhpdoKfOTJ631woIg0/WnisTm40Yy6FvWvqNoiqra0afrF2SA/cJ9yiKli/R2LAV HVJ6cONBBU0RiLWJ1esCZzv8eVcNHlbpiiQccqPzqPlaqd5AXzLpB+yMc4jOuzyCjZQAd IO7uaHwg8QtNh5yPUrvN74cknBdNVfuTmtwTMoF7V4hLiNmIOMiFqV/L0eOdfwI59d2aY I2a6VMfNJTbs6IuzpGWF2i8rPEZBaL9UjCVMUB/VGIk8/bW9rX1lMUAhDU+4lgYMYbjz1 zW2FYfGkKavtWsNvvZWiLaYd1uRFEvnMtsAqnrqdW+n4yp7xdbt4+s64NGFawHQlGtA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309998; 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=WTu41W1/NU5CKpcGF/71fvs4MWGCqtuXs1/yTfdEu2o=; b=dnpwoap2Lw7ITRk1Xp6Rs5vjJvQLWqdoRm/e+cVDa9kT7fzovzC5QUGjP6KifDIwWFA0 L1uoFms7f0r3mR2y42oFlm4roFHKdaidn7a9h+BIX4ImJUrTp7RPnMW/HAMUfD6WgtUX8 EfHZ+CC2lVDTQEMVIdFYSZOyue20e96GyaqboFEZQBNIdeEryohLhA7c3WJc84hNlBpeI zTQReD/XV3RCvG8FT5FV6+40/vGy7jlgp2JMWpeWYYmjmMJeZVCvxgW5HWggpqya2RmtE iuBrMC6FmPUeHKqFnq5Aqy9kiYIFM3Vn1xK/IOCxh+D2doS9hyez8Wa/5YMREh6LTGw== 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=g6GximOx; 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 DCADD606A68B; Thu, 3 Dec 2026 14:59:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DCADD606A68B 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=g6GximOx DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796309997; bh=WTu41W1/NU5CKpcGF/71fvs4MWGCqtuXs1/yTfdEu2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g6GximOxN/bRCT+yCcatTQzaICklzjAyJF9eI2bUNHI71/U3VBtRzEkYaMYA1Zwtr gc2B/OZxeCb9wVuGaY9IZ0TjIt4o1xLbksL45OQiPlW1zxQATbnqU2q6qT8dAWE+HL BAKQaMbMRsk2P8CbcYJ7boCImI6bSgC7otHj34IuhnfWyJAl+WtWd9XaptYMhQ8yo1 5pC57OnhS1/BJYL3bV5RDUAZSClFahkxxi2FINyLpXMXX06L1qi/jewWuQaVCMRD4s iGD3DjNmusauX1vYacz+U7s27U0PD+pwx2/dAKysUqgSNT7IsRbidgtkulGFYY0fIy 5qp07wGtk6QrA== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHpz4MJfzZlJ; Thu, 03 Dec 2026 09:59:55 -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 31/39] sched/deadline: Record the start of the period Date: Thu, 3 Dec 2026 09:58:45 -0500 Message-ID: <6b1869882be16d6d09413804a673ebb3d97aaddb.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 dl_next_period() computes the next period from the deadline: deadline - dl_deadline + dl_period. After sched_setattr() changes dl_deadline, this subtracts the new dl_deadline from a deadline set with the old one. The result is a wrong next period. The next patch fits the period in progress to new parameters at sched_setattr(). To do that, it needs the start of the period. It also makes dl_next_period() count from that start. Add the field period_start. Set it wherever a period starts. Clear it with the deadline. dl_release_params() keeps the deadline of a constrained task: keep period_start there too. Nothing reads it yet: no functional change. Signed-off-by: Mathieu Desnoyers Cc: stable@vger.kernel.org --- include/linux/sched.h | 1 + kernel/sched/deadline.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 69a9a9e5cc80..32ae977a2821 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -661,6 +661,7 @@ struct sched_dl_entity { */ s64 runtime; /* Remaining runtime for this instance */ u64 deadline; /* Absolute deadline for this instance */ + u64 period_start; /* Absolute start of this instance */ unsigned int flags; /* Specifying the scheduler behaviour */ /* diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 58fc1c6c4117..820e71ee7fdf 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1121,7 +1121,8 @@ static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se, struct rq *rq) { /* for non-boosted task, pi_of(dl_se) == dl_se */ - dl_se->deadline = rq_clock(rq) + pi_of(dl_se)->dl_deadline; + dl_se->period_start = rq_clock(rq); + dl_se->deadline = dl_se->period_start + pi_of(dl_se)->dl_deadline; dl_se->runtime = pi_of(dl_se)->dl_runtime; /* @@ -1220,6 +1221,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se) WARN_ON_ONCE(!is_dl_boosted(dl_se)); if (!dl_se->dl_deadline) { dl_se->deadline = rq_clock(rq); + dl_se->period_start = dl_se->deadline; dl_se->runtime = 0; } if (dl_se->runtime < 0 || dl_se->dl_yielded) @@ -1241,7 +1243,8 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se) */ if (dl_se->dl_deadline == 0 || (dl_se->dl_defer_armed && dl_entity_overflow(dl_se, rq_clock(rq)))) { - dl_se->deadline = rq_clock(rq) + deadline; + dl_se->period_start = rq_clock(rq); + dl_se->deadline = dl_se->period_start + deadline; dl_se->runtime = runtime; } @@ -1256,6 +1259,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se) */ while (dl_se->runtime <= 0) { dl_se->deadline += period; + dl_se->period_start += period; dl_se->runtime += runtime; } @@ -2398,6 +2402,7 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perio dl_se->runtime = 0; dl_se->deadline = 0; + dl_se->period_start = 0; dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime); dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime); @@ -4675,6 +4680,7 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p) */ if (!p->dl.dl_runtime) { p->dl.deadline = 0; + p->dl.period_start = 0; p->dl.runtime = 0; } @@ -5196,6 +5202,7 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se) dl_se->dl_density = 0; dl_se->deadline = 0; + dl_se->period_start = 0; dl_se->runtime = 0; dl_se->dl_throttled = 0; @@ -5224,12 +5231,16 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se) */ static void dl_release_params(struct sched_dl_entity *dl_se) { + u64 period_start = dl_se->period_start; u64 deadline = dl_se->deadline; bool constrained = !dl_is_implicit(dl_se); __dl_clear_params(dl_se); - if (constrained) + if (constrained) { + /* Keep the start of the period with its deadline. */ + dl_se->period_start = period_start; dl_se->deadline = deadline; + } } void init_dl_entity(struct sched_dl_entity *dl_se) -- 2.47.3