From nobody Mon May 25 00:09: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 E69033BD64D; Wed, 20 May 2026 08:34:08 +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=1779266050; cv=none; b=UbpzbMmci48ai3RJB1P9tiD5h01dYeboJS89Kzu/ywSgyr8KW4gFIum9CyDUxTDytzfKIa+mjKeVmoi6758KEpq9+JSDfYAQWsoc6P1YK0BJUsgtX+C0i8agpsi9o0KDMbmOkd4dEDXc/Gjfd2X+Hygv9JQtmDLoF7P5Jp7WVh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779266050; c=relaxed/simple; bh=hwo3Sg61YM3LaeoKmYTLxCbpGKU4RGsq7dAH50lJ0Bk=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=YQ1PxIbAyCksnKaLqeEHgKcsCEUzkiMU2YDqj70Ly/wtAj6h0nswmFpxa62E1MdQpnxilXrEnzb4rNetHzuj0S/nb/ZkR6ltlNtMhUrja7zz/itLjvk5ycHhK9OKgDc5BIwX/wREFf/O2zDiypD9NMyzidrVNmwEEeL4WGXcQuE= 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=W6oE0YMj; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GX//P5DE; 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="W6oE0YMj"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GX//P5DE" Date: Wed, 20 May 2026 08:34:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779266047; 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=PMBph4f29wyoucSqL2GikCDFQ41KsHmWXWnH+7Vco+s=; b=W6oE0YMjifInyyOVJl/Iql1jAVyCtwOJlWVZp2j+q444gjcgerK9I2S8awrv/H2Bzn5Ig+ fambQz75zcHvQ3StkPl1C1i5qL+0W0Kn+k7nniiBwlNoalFvGoT5KtK5pSgMbNJsiIN0ul rSgHNRAC+U9SMvNY+iwot3y+GqUPBglB2OWL2KL4iHtiT23v6wxVwCDkJfWuhxmbVI0M5w iLjRLBk2KQkKAOboOmysCoN+kGx6O37Lzda2WqQ6mm5pPoslv+7oz2njqIXXXiy6bQ1+jH xzWaZikrweYaAXsXtZFe0BD5ccwT2eYcFd/XuHdcMQwEpF3QizPpVZhKXV2Deg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779266047; 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=PMBph4f29wyoucSqL2GikCDFQ41KsHmWXWnH+7Vco+s=; b=GX//P5DEjvHp6bDbjZZB56ry6H7T/QBxHHXR39EPTkX7lbybI36j/3R+WG1zeDkHCgaXB7 KeSzHNVWXUFKY7AQ== From: "tip-bot2 for Andrea Righi" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: Drop redundant RCU read lock in NOHZ kick path Cc: K Prateek Nayak , Andrea Righi , "Peter Zijlstra (Intel)" , Vincent Guittot , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260509180955.1840064-2-arighi@nvidia.com> References: <20260509180955.1840064-2-arighi@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177926604618.711.1519878744921626789.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: c9d93a73ce871ca32caf9308562501290b64b955 Gitweb: https://git.kernel.org/tip/c9d93a73ce871ca32caf9308562501290= b64b955 Author: Andrea Righi AuthorDate: Sat, 09 May 2026 20:07:25 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 19 May 2026 12:17:37 +02:00 sched/fair: Drop redundant RCU read lock in NOHZ kick path nohz_balancer_kick() is reached from sched_balance_trigger(), which is called from sched_tick(). sched_tick() runs with IRQs disabled, so the additional rcu_read_lock/unlock() used around sched_domain accesses in this path is redundant. Rely on the existing IRQ-disabled context (and the rcu_dereference_all() checking) instead. The same applies to set_cpu_sd_state_idle(), called from the idle entry path with IRQs disabled, and to set_cpu_sd_state_busy(), reachable via nohz_balance_exit_idle() from two contexts: nohz_balancer_kick() (IRQs disabled, as above) and sched_cpu_deactivate() (the CPUHP_AP_ACTIVE teardown, which runs under cpus_write_lock(), so it cannot race with sched-domain rebuilds). In both cases the rcu_dereference_all() validation is sufficient. No functional change intended. Suggested-by: K Prateek Nayak Signed-off-by: Andrea Righi Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: K Prateek Nayak Reviewed-by: Vincent Guittot Link: https://patch.msgid.link/20260509180955.1840064-2-arighi@nvidia.com --- kernel/sched/fair.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bcaaddd..03f63b0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12715,8 +12715,6 @@ static void nohz_balancer_kick(struct rq *rq) goto out; } =20 - rcu_read_lock(); - sd =3D rcu_dereference_all(rq->sd); if (sd) { /* @@ -12724,8 +12722,8 @@ static void nohz_balancer_kick(struct rq *rq) * capacity, kick the ILB to see if there's a better CPU to run on: */ if (rq->cfs.h_nr_runnable >=3D 1 && check_cpu_capacity(rq, sd)) { - flags =3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; - goto unlock; + flags |=3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; + goto out; } } =20 @@ -12741,8 +12739,8 @@ static void nohz_balancer_kick(struct rq *rq) */ for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) { if (sched_asym(sd, i, cpu)) { - flags =3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; - goto unlock; + flags |=3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; + goto out; } } } @@ -12753,10 +12751,8 @@ static void nohz_balancer_kick(struct rq *rq) * When ASYM_CPUCAPACITY; see if there's a higher capacity CPU * to run the misfit task on. */ - if (check_misfit_status(rq)) { - flags =3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; - goto unlock; - } + if (check_misfit_status(rq)) + flags |=3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; =20 /* * For asymmetric systems, we do not want to nicely balance @@ -12765,7 +12761,7 @@ static void nohz_balancer_kick(struct rq *rq) * * Skip the LLC logic because it's not relevant in that case. */ - goto unlock; + goto out; } =20 sds =3D rcu_dereference_all(per_cpu(sd_llc_shared, cpu)); @@ -12780,13 +12776,9 @@ static void nohz_balancer_kick(struct rq *rq) * like this LLC domain has tasks we could move. */ nr_busy =3D atomic_read(&sds->nr_busy_cpus); - if (nr_busy > 1) { - flags =3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; - goto unlock; - } + if (nr_busy > 1) + flags |=3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; } -unlock: - rcu_read_unlock(); out: if (READ_ONCE(nohz.needs_update)) flags |=3D NOHZ_NEXT_KICK; @@ -12798,17 +12790,13 @@ out: static void set_cpu_sd_state_busy(int cpu) { struct sched_domain *sd; - - rcu_read_lock(); sd =3D rcu_dereference_all(per_cpu(sd_llc, cpu)); =20 if (!sd || !sd->nohz_idle) - goto unlock; + return; sd->nohz_idle =3D 0; =20 atomic_inc(&sd->shared->nr_busy_cpus); -unlock: - rcu_read_unlock(); } =20 void nohz_balance_exit_idle(struct rq *rq) @@ -12827,17 +12815,13 @@ void nohz_balance_exit_idle(struct rq *rq) static void set_cpu_sd_state_idle(int cpu) { struct sched_domain *sd; - - rcu_read_lock(); sd =3D rcu_dereference_all(per_cpu(sd_llc, cpu)); =20 if (!sd || sd->nohz_idle) - goto unlock; + return; sd->nohz_idle =3D 1; =20 atomic_dec(&sd->shared->nr_busy_cpus); -unlock: - rcu_read_unlock(); } =20 /*