From nobody Sun Feb 8 10:43:52 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3BE71FDE3D; Mon, 2 Dec 2024 11:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733138087; cv=none; b=tvzsklU8A7CPvXtJAs7G4qA9D+168NPTqRaPLOO6J61zwTdc6exd0k8FaTih1VWTv3nBjeP6GTYMHQUArKjdCPOxL8k/7D23tpLwpJwDwzLw1uXKYgdgW/tV1MnF20FHNr9uE4+6WuuApi1idQEmLrgeGwUB24+Oqm0QM31Zsm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733138087; c=relaxed/simple; bh=3IsZJGL5TVquc32odbgzJyLv/kY+CuRZm9G/FPFFfx8=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=KJaJ3SitJGhVTVG9BL+144+4SnQES82mXanZ6Z3FJfSrAti23ExoOF0ofl6+fTGCTdPOe+AAffT8NNHyNWbGmITk7nEInvKU5q0uJ5BSX10Q2er9p60lOZlPlrElsYCWa4u6I7aHcAv9PllPSNOTyAJwz2C1pQXl2JjF6/5Or/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=HoO5tweM; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I3/J8msQ; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="HoO5tweM"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I3/J8msQ" Date: Mon, 02 Dec 2024 11:14:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1733138084; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yV95vHA7bIIblnBzYB3hMPOmsAizjWE8F1TDM9u6ZoI=; b=HoO5tweMXFRKhs7DbTrmXrP7CxYK6b0v5IIjwpPAwRX7abR1FPWc9TlZxPOV0HpnQPc1Fw vIwtEIScTI6w2uO6EfiFNl32b6SAoiKMPsgrfLcN9IrbU9XblnuAHZIhabQRnGz8Q22hDk ax8W0S0Imw9DFg9nXTlXyS+zLxeMMpJeARNP0K2iW8CJA7+TnCFit6RN/7ajruJGRK7zoz 9WfHBpMVsD0tZXYrjXR/o3vJ6mEi4UJZ1CQJoBJPFLprfZQzmA7u3rtQBZ+7OTHPKSqrrb vg46PFIlDzWKFK96hiT1WKq5egvmgguP0iouly12T6zmVthwfK/yD2/Dfqiujg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1733138084; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yV95vHA7bIIblnBzYB3hMPOmsAizjWE8F1TDM9u6ZoI=; b=I3/J8msQx77AeGZtKbwLRTEK4vaE7kT1gS/PaoPaz6+ULAb0FfqMzeRJR1MuHrj08p95vM FPuwWX5zDsZpylDw== From: "tip-bot2 for Juri Lelli" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/deadline: Correctly account for allocated bandwidth during hotplug Cc: Juri Lelli , "Peter Zijlstra (Intel)" , Phil Auld , Waiman Long , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20241114142810.794657-3-juri.lelli@redhat.com> References: <20241114142810.794657-3-juri.lelli@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <173313808321.412.4413834624341687574.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: d4742f6ed7ea6df56e381f82ba4532245fa1e561 Gitweb: https://git.kernel.org/tip/d4742f6ed7ea6df56e381f82ba4532245= fa1e561 Author: Juri Lelli AuthorDate: Thu, 14 Nov 2024 14:28:10=20 Committer: Peter Zijlstra CommitterDate: Mon, 02 Dec 2024 12:01:31 +01:00 sched/deadline: Correctly account for allocated bandwidth during hotplug For hotplug operations, DEADLINE needs to check that there is still enough bandwidth left after removing the CPU that is going offline. We however fail to do so currently. Restore the correct behavior by restructuring dl_bw_manage() a bit, so that overflow conditions (not enough bandwidth left) are properly checked. Also account for dl_server bandwidth, i.e. discount such bandwidth in the calculation since NORMAL tasks will be anyway moved away from the CPU as a result of the hotplug operation. Signed-off-by: Juri Lelli Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Phil Auld Tested-by: Waiman Long Link: https://lore.kernel.org/r/20241114142810.794657-3-juri.lelli@redhat.c= om --- kernel/sched/core.c | 2 +- kernel/sched/deadline.c | 48 ++++++++++++++++++++++++++++++++-------- kernel/sched/sched.h | 2 +- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4ffaef8..29f6b24 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -8185,7 +8185,7 @@ static void cpuset_cpu_active(void) static int cpuset_cpu_inactive(unsigned int cpu) { if (!cpuhp_tasks_frozen) { - int ret =3D dl_bw_check_overflow(cpu); + int ret =3D dl_bw_deactivate(cpu); =20 if (ret) return ret; diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index ff68ce4..fa787c7 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -3460,29 +3460,31 @@ int dl_cpuset_cpumask_can_shrink(const struct cpuma= sk *cur, } =20 enum dl_bw_request { - dl_bw_req_check_overflow =3D 0, + dl_bw_req_deactivate =3D 0, dl_bw_req_alloc, dl_bw_req_free }; =20 static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw) { - unsigned long flags; + unsigned long flags, cap; struct dl_bw *dl_b; bool overflow =3D 0; + u64 fair_server_bw =3D 0; =20 rcu_read_lock_sched(); dl_b =3D dl_bw_of(cpu); raw_spin_lock_irqsave(&dl_b->lock, flags); =20 - if (req =3D=3D dl_bw_req_free) { + cap =3D dl_bw_capacity(cpu); + switch (req) { + case dl_bw_req_free: __dl_sub(dl_b, dl_bw, dl_bw_cpus(cpu)); - } else { - unsigned long cap =3D dl_bw_capacity(cpu); - + break; + case dl_bw_req_alloc: overflow =3D __dl_overflow(dl_b, cap, 0, dl_bw); =20 - if (req =3D=3D dl_bw_req_alloc && !overflow) { + if (!overflow) { /* * We reserve space in the destination * root_domain, as we can't fail after this point. @@ -3491,6 +3493,34 @@ static int dl_bw_manage(enum dl_bw_request req, int = cpu, u64 dl_bw) */ __dl_add(dl_b, dl_bw, dl_bw_cpus(cpu)); } + break; + case dl_bw_req_deactivate: + /* + * cpu is going offline and NORMAL tasks will be moved away + * from it. We can thus discount dl_server bandwidth + * contribution as it won't need to be servicing tasks after + * the cpu is off. + */ + if (cpu_rq(cpu)->fair_server.dl_server) + fair_server_bw =3D cpu_rq(cpu)->fair_server.dl_bw; + + /* + * Not much to check if no DEADLINE bandwidth is present. + * dl_servers we can discount, as tasks will be moved out the + * offlined CPUs anyway. + */ + if (dl_b->total_bw - fair_server_bw > 0) { + /* + * Leaving at least one CPU for DEADLINE tasks seems a + * wise thing to do. + */ + if (dl_bw_cpus(cpu)) + overflow =3D __dl_overflow(dl_b, cap, fair_server_bw, 0); + else + overflow =3D 1; + } + + break; } =20 raw_spin_unlock_irqrestore(&dl_b->lock, flags); @@ -3499,9 +3529,9 @@ static int dl_bw_manage(enum dl_bw_request req, int c= pu, u64 dl_bw) return overflow ? -EBUSY : 0; } =20 -int dl_bw_check_overflow(int cpu) +int dl_bw_deactivate(int cpu) { - return dl_bw_manage(dl_bw_req_check_overflow, cpu, 0); + return dl_bw_manage(dl_bw_req_deactivate, cpu, 0); } =20 int dl_bw_alloc(int cpu, u64 dl_bw) diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 0f6790c..5eb2d5b 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -362,7 +362,7 @@ extern void __getparam_dl(struct task_struct *p, struct= sched_attr *attr); extern bool __checkparam_dl(const struct sched_attr *attr); extern bool dl_param_changed(struct task_struct *p, const struct sched_att= r *attr); extern int dl_cpuset_cpumask_can_shrink(const struct cpumask *cur, const = struct cpumask *trial); -extern int dl_bw_check_overflow(int cpu); +extern int dl_bw_deactivate(int cpu); extern s64 dl_scaled_delta_exec(struct rq *rq, struct sched_dl_entity *dl_= se, s64 delta_exec); /* * SCHED_DEADLINE supports servers (nested scheduling) with the following