From nobody Wed Dec 17 13:55:37 2025 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 BBB4823BCFE; Mon, 17 Mar 2025 10:34:43 +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=1742207685; cv=none; b=tZ+KKUIFXYA/CWxBTZLNMsPq5+7prTi0D3vbXiEjkxEYnbnHxOU/jqmsdhcp3Nilb0nxAPHI3gBUKIuI5/GszvJ6lj/gYgUyMheYKq4zFKuGljVqTIgY+977g87eaO7WybyvWhYMDrxguOxMhcqv7xjLXC3oKUB842yG12pbcH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742207685; c=relaxed/simple; bh=I5EJ4rEBowz8X5ax+LKf/mCpjGmRe7UibhoPMUpJbPI=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=iYwGBFB8T4TMTvbz1eNJSzxl52PBuY7zway0ckPXHeatCXAhAKDdZjeHUj8o8V4B9fQQpW+1M5u7jUpyhpSxsB85naSf6dQqq+NTm//PJlk9o2JwNplWOO2y+uB5El9lEDbUvJaS5eIS3kxLY7gCliFxIVws8LtutuXN8FMvmiw= 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=rrsC8b/i; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=R6HKCzrf; 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="rrsC8b/i"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="R6HKCzrf" Date: Mon, 17 Mar 2025 10:34:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1742207682; 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=9nggWXmLg3r6/a5tMfVfI/cHdG8kfH0AJ465ybgcEHc=; b=rrsC8b/i9N+k/VjA/9kNFyBgeG7ttTbnIVahXO0rFYgqAr4dSds5bEhJQ/PDnlsQuO5Tog ZV1ceJ1MXHjYwtftFFRfKsLxA034BKRINSc3PFQDJcj8zyS0sqZy8Yck9viMaYMKAaOMjN Fz26Fh38p4eeSCYmKPUOyqLca9yzKVUNlkipf6swwA2oVaZ8VOx12vE/DrQiz7V1WSMIPo zcqxHORv3tGXZdOloBte4EyeE1vVgLgywfshaZsXBB18qi1RWcnvj+0Rwt54cuqqq3vvXh sqQqrT472uV/8b/tzmQEOpmyUsHmSziRgvVhcYlnHkKC2JBk7wvRTBSkL2KbzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1742207682; 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=9nggWXmLg3r6/a5tMfVfI/cHdG8kfH0AJ465ybgcEHc=; b=R6HKCzrfvdcx9Ea+3EJK8iWS9uRts0Fd919M2zsnqSXATt1Q/6NfsvxO6/l6OoBke8nYvb aMexJGIKMQHWZpDA== 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: Generalize unique visiting of root domains Cc: Jon Hunter , Juri Lelli , "Peter Zijlstra (Intel)" , Valentin Schneider , Dietmar Eggemann , Waiman Long , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174220768140.14745.8170370325966043300.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: 45007c6fb5860cf63556a9cadc87c8984927e23d Gitweb: https://git.kernel.org/tip/45007c6fb5860cf63556a9cadc87c8984= 927e23d Author: Juri Lelli AuthorDate: Thu, 13 Mar 2025 18:05:46 +01:00 Committer: Peter Zijlstra CommitterDate: Mon, 17 Mar 2025 11:23:41 +01:00 sched/deadline: Generalize unique visiting of root domains Bandwidth checks and updates that work on root domains currently employ a cookie mechanism for efficiency. This mechanism is very much tied to when root domains are first created and initialized. Generalize the cookie mechanism so that it can be used also later at runtime while updating root domains. Also, additionally guard it with sched_domains_mutex, since domains need to be stable while updating them (and it will be required for further dynamic changes). Fixes: 53916d5fd3c0 ("sched/deadline: Check bandwidth overflow earlier for = hotplug") Reported-by: Jon Hunter Signed-off-by: Juri Lelli Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Valentin Schneider Reviewed-by: Dietmar Eggemann Tested-by: Waiman Long Tested-by: Jon Hunter Tested-by: Dietmar Eggemann Link: https://lore.kernel.org/r/Z9MQaiXPvEeW_v7x@jlelli-thinkpadt14gen4.rem= ote.csb --- include/linux/sched/deadline.h | 3 +++ kernel/sched/deadline.c | 23 +++++++++++++---------- kernel/sched/rt.c | 2 ++ kernel/sched/sched.h | 2 +- kernel/sched/topology.c | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h index 3a912ab..6ec5786 100644 --- a/include/linux/sched/deadline.h +++ b/include/linux/sched/deadline.h @@ -37,4 +37,7 @@ extern void dl_clear_root_domain(struct root_domain *rd); =20 #endif /* CONFIG_SMP */ =20 +extern u64 dl_cookie; +extern bool dl_bw_visited(int cpu, u64 cookie); + #endif /* _LINUX_SCHED_DEADLINE_H */ diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 1a041c1..3e05032 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -166,14 +166,14 @@ static inline unsigned long dl_bw_capacity(int i) } } =20 -static inline bool dl_bw_visited(int cpu, u64 gen) +static inline bool dl_bw_visited(int cpu, u64 cookie) { struct root_domain *rd =3D cpu_rq(cpu)->rd; =20 - if (rd->visit_gen =3D=3D gen) + if (rd->visit_cookie =3D=3D cookie) return true; =20 - rd->visit_gen =3D gen; + rd->visit_cookie =3D cookie; return false; } =20 @@ -207,7 +207,7 @@ static inline unsigned long dl_bw_capacity(int i) return SCHED_CAPACITY_SCALE; } =20 -static inline bool dl_bw_visited(int cpu, u64 gen) +static inline bool dl_bw_visited(int cpu, u64 cookie) { return false; } @@ -3171,15 +3171,18 @@ DEFINE_SCHED_CLASS(dl) =3D { #endif }; =20 -/* Used for dl_bw check and update, used under sched_rt_handler()::mutex */ -static u64 dl_generation; +/* + * Used for dl_bw check and update, used under sched_rt_handler()::mutex a= nd + * sched_domains_mutex. + */ +u64 dl_cookie; =20 int sched_dl_global_validate(void) { u64 runtime =3D global_rt_runtime(); u64 period =3D global_rt_period(); u64 new_bw =3D to_ratio(period, runtime); - u64 gen =3D ++dl_generation; + u64 cookie =3D ++dl_cookie; struct dl_bw *dl_b; int cpu, cpus, ret =3D 0; unsigned long flags; @@ -3192,7 +3195,7 @@ int sched_dl_global_validate(void) for_each_online_cpu(cpu) { rcu_read_lock_sched(); =20 - if (dl_bw_visited(cpu, gen)) + if (dl_bw_visited(cpu, cookie)) goto next; =20 dl_b =3D dl_bw_of(cpu); @@ -3229,7 +3232,7 @@ static void init_dl_rq_bw_ratio(struct dl_rq *dl_rq) void sched_dl_do_global(void) { u64 new_bw =3D -1; - u64 gen =3D ++dl_generation; + u64 cookie =3D ++dl_cookie; struct dl_bw *dl_b; int cpu; unsigned long flags; @@ -3240,7 +3243,7 @@ void sched_dl_do_global(void) for_each_possible_cpu(cpu) { rcu_read_lock_sched(); =20 - if (dl_bw_visited(cpu, gen)) { + if (dl_bw_visited(cpu, cookie)) { rcu_read_unlock_sched(); continue; } diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 4b8e33c..8cebe71 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2910,6 +2910,7 @@ static int sched_rt_handler(const struct ctl_table *t= able, int write, void *buff int ret; =20 mutex_lock(&mutex); + sched_domains_mutex_lock(); old_period =3D sysctl_sched_rt_period; old_runtime =3D sysctl_sched_rt_runtime; =20 @@ -2936,6 +2937,7 @@ undo: sysctl_sched_rt_period =3D old_period; sysctl_sched_rt_runtime =3D old_runtime; } + sched_domains_mutex_unlock(); mutex_unlock(&mutex); =20 return ret; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e8915ad..5d853f9 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -998,7 +998,7 @@ struct root_domain { * Also, some corner cases, like 'wrap around' is dangerous, but given * that u64 is 'big enough'. So that shouldn't be a concern. */ - u64 visit_gen; + u64 visit_cookie; =20 #ifdef HAVE_RT_PUSH_IPI /* diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c index 296ff2a..4409333 100644 --- a/kernel/sched/topology.c +++ b/kernel/sched/topology.c @@ -568,7 +568,7 @@ static int init_rootdomain(struct root_domain *rd) rd->rto_push_work =3D IRQ_WORK_INIT_HARD(rto_push_irq_work_func); #endif =20 - rd->visit_gen =3D 0; + rd->visit_cookie =3D 0; init_dl_bw(&rd->dl_bw); if (cpudl_init(&rd->cpudl) !=3D 0) goto free_rto_mask;