From nobody Sun Feb 8 03:58:14 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 C74F02749C1 for ; Thu, 15 Jan 2026 07:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768462582; cv=none; b=jDlThUVP50TaLxF2dXSiKp4OKgAsCVfAbwkEWsxHkgF9MlWHaKTP7lnikvtoDWnqg8wrv48HtFgq5pn3LkXdDvdPPzm1A03RGXiKgXtjUVXjlTg88CTO3zVWBEbUKHnZIPqKc8i7elmhYGLa/BZGb4eguxd9P8RxyU7Y5Vv5cIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768462582; c=relaxed/simple; bh=Fw/N5YvomKfaTQXdNsTMP0auJQqXiA/bjGNSx91BY0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TkNSpG1+DnLoHe2X6r5eCC+OwzM8YvBsjAiFNuOXXevu95Ln/jxbmXYAAfI1pFnJB4Gq4RFprIGFJhAxw9maxgzNoHUwk+T9WWzZWgoaA6USQ70X+oK/qNifBfrBk9lBX8OVfF91FJpY3/UQlAyYmCrM6zkL0ph3w/xtCBupaGM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=L/hr+izX; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="L/hr+izX" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 60F6u9oH025015; Thu, 15 Jan 2026 07:35:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=qCfjdGa4M2c8r7kbr 33Crl8xwnVO96UB/7SryoRGwCM=; b=L/hr+izXSFLgWUHk/PpSugwBIcOdTvSGp eFCNkPPaBwA54kcs2cWraMmLsWE2dD4lw+f1YgyHA5rYKY6cDSsrd/fnKtqy/28I DV1q36d7hOhaioY7MHMQHonexBuHMKWgSwIVXh7BK1gYkVyIiF6+zqragYFgB0f1 GkqAjIqfB60oASjlOxlcmlRnEpwKhWpsxHi1bTaTdAx0VJoS+E42S55+XopJI2EU +MJHpy9XeUvKfKUYEunfpxtwqbJLm4Q7tqWVYNikjwHdawwqK4PrDJjGzXpGc2bQ ykJFg71nu+goJYB0RF7DoD+66g/+hbwngvtJ5MwU8zkMQbOYfwCVA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4bkd6ecy5q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Jan 2026 07:35:43 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 60F4PZk5025838; Thu, 15 Jan 2026 07:35:42 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4bm2kkpq0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Jan 2026 07:35:42 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 60F7Zd4S33817046 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Jan 2026 07:35:39 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA3C820040; Thu, 15 Jan 2026 07:35:39 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F1202004B; Thu, 15 Jan 2026 07:35:37 +0000 (GMT) Received: from li-7bb28a4c-2dab-11b2-a85c-887b5c60d769.ibm.com.com (unknown [9.39.17.239]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Jan 2026 07:35:36 +0000 (GMT) From: Shrikanth Hegde To: mingo@kernel.org, peterz@infradead.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org Cc: sshegde@linux.ibm.com, kprateek.nayak@amd.com, juri.lelli@redhat.com, vschneid@redhat.com, tglx@kernel.org, dietmar.eggemann@arm.com, anna-maria@linutronix.de, frederic@kernel.org, wangyang.guo@intel.com Subject: [PATCH v5 1/3] sched/fair: Move checking for nohz cpus after time check Date: Thu, 15 Jan 2026 13:05:22 +0530 Message-ID: <20260115073524.376643-2-sshegde@linux.ibm.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260115073524.376643-1-sshegde@linux.ibm.com> References: <20260115073524.376643-1-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PX0m6cl39yNTUCoWbqmM4K8QXv6Sddsi X-Authority-Analysis: v=2.4 cv=LLxrgZW9 c=1 sm=1 tr=0 ts=696898cf cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=vUbySO9Y5rIA:10 a=VkNPw1HP01LnGYTKEx00:22 a=zd2uoN0lAAAA:8 a=VnNF1IyMAAAA:8 a=BZ9Nrz06eRmaA-7oh88A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTE1MDA0NyBTYWx0ZWRfX1EhZJpvvjCEB 3MPxqEri5kZPFB5YeAXFrJelt2PIUJ/bGyMojfU1zSyvf5OWdPWYYJWACKLC4CLrbrS86lW4YxB nNWS92d2g0IiKuu9KybBf3L5ECti+YCzrc26VLI8tW3E31r5qrOtPjZRMApCPumdno0iyxQcjpg Rp/pX1fllVzu/ZgEQZ/wXZ07YZJINuEOGc4pBPpuQ8Y+D5T1XP8OJIbAZjF9aTEMXiEsqECHk1V UYncsMq9zlRxcR+OPt7D/ykawOcFMUib0SBtt6+2GLGSq2Jfxs8MGnyhHXyDnxj0BXAMkF+/O3x eMCcVho/qIrUEaK1CJhq/ZsGdOd59W5z8Db3owobWwWh4+XkTd1tJMK5YJAkQ3FDgYkn5Vo64qW 2M3I0QTv2hX601VeHAXDfYPrqm5zLiyiBqoV8pyiwiiSyspndS7BDASAUMjjMU8nWybr6qlFX7M znLAJdsfnWes7jP87nA== X-Proofpoint-ORIG-GUID: PX0m6cl39yNTUCoWbqmM4K8QXv6Sddsi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-15_02,2026-01-14_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 clxscore=1015 spamscore=0 impostorscore=0 malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2512120000 definitions=main-2601150047 Content-Type: text/plain; charset="utf-8" Current code does.=20 - Read nohz.nr_cpus=20 - Check if the time has passed to do NOHZ idle balance Instead do this. - Check if the time has passed to do NOHZ idle balance - Read nohz.nr_cpus This will skip the read most of the time in normal system usage. i.e when there are nohz.nr_cpus (system is not 100% busy). Note that when there are no idle CPUs(100% busy), even if the flag gets set to NOHZ_STATS_KICK | NOHZ_NEXT_KICK, find_new_ilb will fail and there will be no NOHZ idle balance. In such cases there will be a very narrow window where, kick_ilb will be called un-necessarily. However current functionality is still retained. Note: This patch doesn't solve any cacheline overheads. No improvement in performance apart from saving a few cycles of reading nohz.nr_cpus Reviewed-and-tested-by: K Prateek Nayak Signed-off-by: Shrikanth Hegde --- kernel/sched/fair.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c921cdc6c3ed..a4910658c5d6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12445,20 +12445,29 @@ static void nohz_balancer_kick(struct rq *rq) */ nohz_balance_exit_idle(rq); =20 - /* - * None are in tickless mode and hence no need for NOHZ idle load - * balancing: - */ - if (likely(!atomic_read(&nohz.nr_cpus))) - return; - if (READ_ONCE(nohz.has_blocked_load) && time_after(now, READ_ONCE(nohz.next_blocked))) flags =3D NOHZ_STATS_KICK; =20 + /* + * Most of the time system is not 100% busy. i.e nohz.nr_cpus > 0 + * Skip the read if time is not due. + * + * If none are in tickless mode, there maybe a narrow window + * (28 jiffies, HZ=3D1000) where flags maybe set and kick_ilb called. + * But idle load balancing is not done as find_new_ilb fails. + * That's very rare. So read nohz.nr_cpus only if time is due. + */ if (time_before(now, nohz.next_balance)) goto out; =20 + /* + * None are in tickless mode and hence no need for NOHZ idle load + * balancing: + */ + if (likely(!atomic_read(&nohz.nr_cpus))) + return; + if (rq->nr_running >=3D 2) { flags =3D NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; goto out; --=20 2.51.0