From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010030.outbound.protection.outlook.com [52.101.201.30]) (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 E0B5C474264 for ; Tue, 28 Jul 2026 21:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.30 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785275106; cv=fail; b=ZB4/RKm7Not0qTyF+L4oVp7TmU2NE0fYWzaRnwBZZcDBYqof81PB+Yx+RNn8xsZUw4t45UBkHCsN+gEpLUu8fIKN7sfqtXg2n9tsihUe1W6Mzag4FPOKg8iAR7aO/5gQuYjTh6Voxcxew6yFsTmqAAt9FMvvQ5QF1BP8ZQXwBj4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785275106; c=relaxed/simple; bh=iMEJPLcE8A92O9rbEwJ528WVqC5v6c+7uU5MyC1k0bk=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=gImdAVpMdxZZBuWtnt4sLXsZDc+8As77NO3NJrFCyt27zLiyBoBOJ7VCBuy3VX7G84H9P4dMtLzjqIA+zqdpbhymN6D2z8b+EyUauFmTRU9ZecE29uVQK6dIOby96U+rkRNV+wc5ZzKLid8JKE6bbGQ5u0KaMCc/m0mwvX+xXgU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=ZDWpeF8o; arc=fail smtp.client-ip=52.101.201.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="ZDWpeF8o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fqddfkgn+LwA7bAo29Gnr86pslLRsqEnoxEUjSDhItkY5AvqXUaWjvHQBBkki63+TzspAt8w1ZIvH1FeWWznisINfJXYYjnLYZHZF+bK6sR0I4vl23uvQzXWZGh5DzbAnAGO8kN1M4Fa7OEp+F8cCiIcSUcOJj1u17UssXLSj1uE8KIhh4aWdilu2o+c3RO/5PrUDzymbHEK/l4YXm71pDjFANVfkpoJKPu2l0rh8xbnebIKYDQc6x5GL26y1M+zzMEU0IjMfxCaiOBIBf0CgMKtnLf+Woi80aO2cRnmKP5JDrDWHWIZG1U9YaiVG4vAixf8c4uYOrPorcnLXZ4yIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=s++zzKbJBCGl3G2lG38mHdWG03avyvrSKYPVyraxIKY=; b=MvtpeYdLsIAFlf819dG3y77jhKf6UCc0kEaMKlJltsKOrdDbPhk/Sv8IhmyVmJoCuUGdP2YppfYCkRBiULb4RiJNXFDY2yUfSvYkGqXxRMewCTzWsSbssmZT62VxdSNaBrSHmkLiE+iEk9gMQfAMFqVhLDZEvNJm+haSSnrj7/wgCEewnUJ1ksLjxv1y9cid3rIBvikxShsTCGGACu7jKaeUQxWu9CV/DCzlJ2eLhGV+Lm8rZ5JSC8wJ4LwqS4olHiDgFZLOXiVsk+pGKtWR2Ffy4WbsZ04NADNHqUVqcT7kTSpAXkdS6TMcmeOfxjFx2w0g31cwnmW3grgVqF3PwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s++zzKbJBCGl3G2lG38mHdWG03avyvrSKYPVyraxIKY=; b=ZDWpeF8oT9L0MiyF6YHKuNeuBQK/V5xAh9TqrVF3IK5AhKx845GZ29XhJ3Sfk6KBglDzgIX4J09etENwW4aAMLevcYHKxApxKnTWUCKQ+33Dyil2FotSH3+qCIwZGrnoed5IWWDPzzyBg/DzN1w1enIOgtjJN/YspbeXIksgrbmYcmRp/UPlqo/pa1PrTmbeWTVCl5p2RCCm/yNeEQs5rxF37AA6+bpG/xt17pV8/petE31EwtScTKTgcYtjSk1jv0mUInhAlhNhxBfmezDypBh25RXHs/Gb3JV5bDUW9sPvPM6YDJy/BNgB21novW+DSBS1HJFNT7LXqTyLD2Z9Uw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) by CY8PR12MB7194.namprd12.prod.outlook.com (2603:10b6:930:5a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.13; Tue, 28 Jul 2026 21:44:56 +0000 Received: from DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c]) by DM6PR12MB4827.namprd12.prod.outlook.com ([fe80::6261:3040:864b:159c%5]) with mapi id 15.21.0245.012; Tue, 28 Jul 2026 21:44:56 +0000 From: Andrea Righi To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Christian Loehle , Shrikanth Hegde , Phil Auld , linux-kernel@vger.kernel.org Subject: [PATCH] sched/fair: Prefer fully idle cores for NOHZ balancing Date: Tue, 28 Jul 2026 23:44:42 +0200 Message-ID: <20260728214442.1648483-1-arighi@nvidia.com> X-Mailer: git-send-email 2.55.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MI2PEPF00000B84.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::41b) To DM6PR12MB4827.namprd12.prod.outlook.com (2603:10b6:5:1d6::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR12MB4827:EE_|CY8PR12MB7194:EE_ X-MS-Office365-Filtering-Correlation-Id: 61be78d2-638f-498b-7f1f-08deecf176fb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|23010399003|366016|7416014|10067099003|18002099003|11063799006|56012099006; X-Microsoft-Antispam-Message-Info: Tv2SuUY+MzoZwnlhvHUIUqQB8zQju3GCk8uMSJGdkiu9b1hUjgHCETp0J3EvIHg07tpqvVA2WfE4ZaAZHkWxs1yQfIGtNgDcrPPogw2yHVTrs5Da/l+oKH8DFIEzMW7/Bcj2qjYuqhhaGe0nCC3FMsbZg4dOsj09i6x1x6jILD90pcuqzPsdK9yn90dwo2Po+BXdndFX/5yWOQZbbNlbQ8BoNlHJds0ijhiXipdn4vtsSFr9eq4JIyKinJKi/0QuKIp9X8usORYpbVAYrUwqbcv6zmc7iKIeLqis7DyJ4CEIvCasl0Z882BTdEKYgdHw2rKuSAJjXER3VNoJy4OXp65G6ngKMEXh5Zs0h6j/cN4qzA8ZnTp5AZL+XmOw+XaZVfFnDVLmKYxKyo/Nm124rh8zjD0sIB+6FEqaIxXZJ/SkIBfjuewZruhdfOuxMu1Tw9IPqX19aomcOPh3KzVqwCk715oMibLyvORCLTtpIac/Mq5CFX3YOK16w5DEjtbXnK4SRDx/Psy1F+TI2diEYpYMQg04gfg2B4lkTHeDZVKpzLY2O2KcPyKw/+1UVFwKJDuOAh1dJNOn7l3z1xo9ICWIPFBRwJgTHw/kIRHap8atE609PH12jjRfUqyvNOBalBEcg/R92nSKZB7yUjg2E1NpZ/UJnsyTyeffBw0Ipl4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4827.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(23010399003)(366016)(7416014)(10067099003)(18002099003)(11063799006)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?A0iT6cfsEn3edO/Sbd0Z/EWK9dKByLzB3V8zY8ST48HC3ZYoW6r0fkRpu8yO?= =?us-ascii?Q?o5XUpbkcHT91LJvVsgrDg6YatW8zojCMq+7iMvFhx4TxwXIxf3RGCdUK2EGw?= =?us-ascii?Q?scOit7NVyK7w0i6YqnF02FEls1Ogvkl64E2mquk6JKP/CcEpRD++qZ5AYY5n?= =?us-ascii?Q?RWFyyYqLixH15xZA1JbSMoLPfI41YZdV43/KqRDzO3BOY9jyQwjmWNGtoTzx?= =?us-ascii?Q?KHj72hUCzpHu11RrmxbCya8tuCGW/MD2fMAwua483s+uuVNkYh/5VjVIAZlz?= =?us-ascii?Q?LMgBTpSznlDSRrG6lyAkJoeY41OzBFFuVrpOKeAuqTyKWm6AuUUVfSYmM71V?= =?us-ascii?Q?ZWCrjm6Ym0oCdH4BpcdPDgaocZ1MxgQoY8oGFtYQfuY2L9fI32W8t8rOdjBC?= =?us-ascii?Q?PXMz/3U1F9Tml3jwxt6qpfkCQ/HQyTtOqfMP88mgOMUfmJJ14ArGslUNlEEL?= =?us-ascii?Q?NmXdRdwhqED7hkbIXWJzg8hrzb4l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qp8BK1HsGGIAJBo/ti493bJ1yIJh9fxmZDaUa2WXJ8qQQI3bos3M?= =?us-ascii?Q?RC1eXYtvuvCY9cG6PTBqjkSpwZ2ytYfJUpj06oBxq9kD2K6tmqC5i3kkxYeL?= =?us-ascii?Q?PUoz3v5oYtJUIIQF71KyXxKMKhduj4pBY3ueNtRmE62yMGgdqRERzVHd++ga?= =?us-ascii?Q?9GAW6OUqGwPI0SBGxvHjcbNmvM84q20ISoIQqJcm4S6H7I1RBPkSg3GAnBCr?= =?us-ascii?Q?YCej0wRebD7OHu91RUbSTj8QTzdut/uNPRU37aBk35qBR0oAiFMIW6Ek8ZWU?= =?us-ascii?Q?0GVINIC/BOwB2lhWdlR6mCmXUtyQpjj7Rr6igJHqo1LA8+cAvDQcqLX+K6nr?= =?us-ascii?Q?UOZKdXW8/w=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 61be78d2-638f-498b-7f1f-08deecf176fb X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4827.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jul 2026 21:44:56.2537 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: B/tQNFuO2M9Izvqy509jYj5z1/zvm0PLR2KQItW7yXolB+xkivV4YDLeciYlcDBBDO2cNxTgtwQ3eZW4TLw39A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7194 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. 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. Signed-off-by: Andrea Righi --- kernel/sched/fair.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 37001c63452e5..ba713e7c111b6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13966,7 +13966,7 @@ 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; hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE); @@ -13974,19 +13974,32 @@ static inline int find_new_ilb(void) if (ilb_cpu == this_cpu) continue; - if (idle_cpu(ilb_cpu)) + if (!idle_cpu(ilb_cpu)) + continue; + + /* + * 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)) return ilb_cpu; + + if (fallback < 0) + fallback = 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) { -- 2.55.0