From mboxrd@z Thu Jan 1 00:00:00 1970 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 274A03B0598 for ; Mon, 10 Aug 2026 09:41:57 +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=1786354919; cv=none; b=OUamnnHXfWo+8lOEcq4328x8ajWnG8UAZPDEa+N1pqKO22r9LlIYXuvic8XwZV+vXFPkdD3tuGL0od3irDE+vgDhochj2RfRAjPe1ejMoMgyN82b0vYXSHq6Z/ocwYFlZfGWlLjnWRC3rn9jZqg1UqDGqHl1OUMsg2rcDfnou0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786354919; c=relaxed/simple; bh=q/j2er4sKaS81GcuD4DSNdVM+D3AzYoCTXFXHZYB+Lw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ohYpSuITn5GqTTwI0k3SLZRb/AWun57cVLUOZgokXCp1Vcbe0mnYxRwUfhamtiKQ2zsPCUAr+gcAwGqNFULN1FfwmiuH2B68Cww03l+cEzolgV92xAJHN0ZGYon57TzRZIlXXcpIHv9uhY/mBNLu8SSvuMwZweasmZlsgKFrrzI= 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=k8ZPpPlJ; 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="k8ZPpPlJ" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 67A9ViNt1289922; Mon, 10 Aug 2026 09:41:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=u/GoI3 daP+i1UorfwZykHyC8WCQ/n2ZF13IU7Ommub4=; b=k8ZPpPlJPp8GHW1S5a+7nj V5UYWYsfdHFr4y80ZMCAaZJmdArniQgD3Ysj26bAvdKuBOdvBa3HqWQrueUzu9/t hXbeSdwcSll/ELyzxWkz1tT9edmvQYX6v2n7FRc1qgLJVW5hyOD/Y/P0asZjRRFN xE4VzOJeCHX+iqAG/oUZm0Zb8ph95InsE77jmvPGfOA/+bY01f8s6JeSgJGgutiD dodegPbtV/K8vOLJ/TpTec4tDkgDrOfJ6Bpjo7wkTtjix/NRR8TkgPES1G/HVrp7 hy/Se59wc3sGBkkrciZLpwxdbyve/A0NPKdXX/Wmc5LHIuUSmP24zYhzkSRSK1Tg == Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4fwvnvxx5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2026 09:41:29 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 67A9QGon015205; Mon, 10 Aug 2026 09:41:28 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4fxfsjm7xv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Aug 2026 09:41:28 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 67A9fQba34668920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 10 Aug 2026 09:41:26 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 984BA2004B; Mon, 10 Aug 2026 09:41:26 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 667AC2004E; Mon, 10 Aug 2026 09:41:23 +0000 (GMT) Received: from [9.39.23.237] (unknown [9.39.23.237]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 10 Aug 2026 09:41:23 +0000 (GMT) Message-ID: Date: Mon, 10 Aug 2026 15:11:22 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] sched/fair: Prefer fully idle cores for NOHZ balancing To: Andrea Righi , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Christian Loehle , Phil Auld , Mete Durlu , linux-kernel@vger.kernel.org References: <20260806134355.592145-1-arighi@nvidia.com> Content-Language: en-US From: Shrikanth Hegde In-Reply-To: <20260806134355.592145-1-arighi@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=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/XxfhnkxxWoINCT1Gl8b0aDeq1+XEns62WghxgvhAuT3ciDkV3zOBj/DLz9XXZjuDCl058S+k s+lsz44IsY3uDbMXCAA/+pq6AGbxVww= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-08-10_02,2026-08-07_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 suspectscore=0 clxscore=1015 malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2608100082 On 8/6/26 7:13 PM, Andrea Righi wrote: > find_new_ilb() selects the first idle housekeeping CPU without > considering whether another thread is running on the same physical core. > On an SMT system, the idle load balancer can therefore activate both > siblings even when another housekeeping CPU has an entirely idle core. > > On most SMT systems, this is not problematic because the idle load > balancer is a short-lived activity and the transient wakeup of a sibling > has negligible performance impact. > > However, this can be particularly costly on NVIDIA Olympus cores used in > Vera. Briefly activating an otherwise idle sibling can reduce the > performance available to the other sibling and this effect does not > necessarily end once the activated sibling becomes idle: after the ILB > finishes and its CPU enters WFI, full single-thread performance is > restored only after the sibling has remained idle for a qualification > interval (10 Ki cycles on the tested Vera system). Repeated short > sibling wakeups can therefore sustain the interference even with little > actual overlap. > > Prevent this by preferring an idle housekeeping CPU whose entire SMT > core is idle. Retain the first idle CPU as a fallback when no fully idle > core is available, so NOHZ balancing continues to make forward progress. > Once a partially busy core has been examined, skip its remaining SMT > siblings to avoid repeating the core-idle check on wide SMT systems. > > Tests performed using an ad hoc GEMM benchmark running one CPU-intensive > task per SMT core within its CPU affinity mask improved from > approximately 6.2 TFLOP/s to 9.4 TFLOP/s. > > Note that this preference may wake a fully idle physical core instead of > using an idle sibling of an active core, potentially increasing ILB > wakeup latency or energy consumption on some architectures. It may also > scan additional CPUs before selecting the one to run the ILB. The > selection falls back to the first idle CPU when no fully idle SMT core > is available. Non-SMT systems continue to select the first idle > housekeeping CPU. > > Tested-by: K Prateek Nayak > Reviewed-by: K Prateek Nayak > Reviewed-by: Mete Durlu > Reviewed-by: Vincent Guittot > Reviewed-by: Shrikanth Hegde > Signed-off-by: Andrea Righi > --- > Changes in v5: > - Collect Tested-by and Reviewed-by tags > - Reorder local variable declarations (Prateek Nayak) > - Link to v4: https://lore.kernel.org/all/20260804151324.918020-1-arighi@nvidia.com/ > > Changes in v4: > - Remove redundant this_cpu check (Prateek Nayak, Vincent Guittot) > - Link to v3: https://lore.kernel.org/all/20260731191957.3199642-1-arighi@nvidia.com/ > > Changes in v3: > - After finding an idle fallback, skip all siblings when a busy CPU is > encountered, avoiding per-CPU traversal of known-busy cores (Mete Durlu) > - Link to v2: https://lore.kernel.org/all/20260729163225.1987068-1-arighi@nvidia.com/ > > Changes in v2: > - Avoid repeated is_core_idle() checks on wide SMT systems by pruning > the remaining siblings of a partially busy core (Prateek Nayak) > - Link to v1: https://lore.kernel.org/r/20260728214442.1648483-1-arighi@nvidia.com/ > > kernel/sched/fair.c | 55 ++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 44 insertions(+), 11 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 37001c63452e5..89bec68622db9 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -13964,29 +13964,62 @@ static inline int on_null_domain(struct rq *rq) > */ > static inline int find_new_ilb(void) > { > - int this_cpu = smp_processor_id(); > - const struct cpumask *hk_mask; > - int ilb_cpu; > + int ilb_cpu, fallback = -1; > + struct cpumask *ilb_cpus; > + > + lockdep_assert_irqs_disabled(); > + > + /* > + * Reuse the per-CPU select_rq_mask, which is protected from concurrent > + * use on this CPU by having interrupts disabled. > + */ > + ilb_cpus = this_cpu_cpumask_var_ptr(select_rq_mask); > + cpumask_and(ilb_cpus, nohz.idle_cpus_mask, > + housekeeping_cpumask(HK_TYPE_KERNEL_NOISE)); > + > + for_each_cpu(ilb_cpu, ilb_cpus) { > + if (!idle_cpu(ilb_cpu)) { > + /* > + * Once an idle fallback exists, a busy CPU proves that > + * this core cannot be fully idle. Skip its siblings. > + */ > + if (sched_smt_active() && fallback >= 0) > + cpumask_andnot(ilb_cpus, ilb_cpus, cpu_smt_mask(ilb_cpu)); > + continue; > + } > > - hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE); > + /* > + * Running the idle load balancer on an idle sibling of a busy > + * SMT core can reduce the capacity available to its sibling. Prefer > + * a CPU whose entire core is idle, but retain the first idle CPU as > + * a fallback so idle balancing can still make progress when no fully > + * idle core exists. > + */ > + if (sched_smt_active() && !is_core_idle(ilb_cpu)) { nit: Now, when making the changes for paravirt series, i remembered sched_smt_active() is not needed anymore. since cpu_smt_mask in that case just points to just that cpu. > + if (fallback < 0) > + fallback = ilb_cpu; > > - for_each_cpu_and(ilb_cpu, nohz.idle_cpus_mask, hk_mask) { > - if (ilb_cpu == this_cpu) > + /* > + * The core is not idle, so there is no need to check > + * any of its other SMT siblings. > + */ > + cpumask_andnot(ilb_cpus, ilb_cpus, > + cpu_smt_mask(ilb_cpu)); > continue; > + } > > - if (idle_cpu(ilb_cpu)) > - return ilb_cpu; > + return ilb_cpu; > } > > - return -1; > + return fallback; > } > > /* > * Kick a CPU to do the NOHZ balancing, if it is time for it, via a cross-CPU > * SMP function call (IPI). > * > - * We pick the first idle CPU in the HK_TYPE_KERNEL_NOISE housekeeping set > - * (if there is one). > + * Prefer a CPU on a fully idle core in the HK_TYPE_KERNEL_NOISE housekeeping > + * set. Fall back to the first idle CPU when no fully idle core exists. > */ > static void kick_ilb(unsigned int flags) > {