From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH0PR06CU001.outbound.protection.outlook.com (mail-westus3azon11011024.outbound.protection.outlook.com [40.107.208.24]) (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 9C9CC370AF6 for ; Fri, 31 Jul 2026 19:20:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.208.24 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785525613; cv=fail; b=CxmvwEwo1Z723FoGNuT2FGqE6QG4ZPzx78uJljzceCChZ7uZVE460Rfz1nW1TJQLR2fXSAaakFA2o0qKJGe/BJlWD8nBlcUexXiSq4qrub8iGpOaWW9g7itYUzpsJ3mSaUYvv/NamM6/JKUKgyMj7TPFUp7Ru//DZDpVHpBraqM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785525613; c=relaxed/simple; bh=Rp8jLV2DElALl/XWNvhPsjVqe6e5WmjRIJZC8yIPFhQ=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=kAXYDH/NU6WtuPVDP4KWgVuL0O6mzQyIQm90Sd1D95rTk6SPZCeoCjOeahjLO2M5akir5eWKI+uiA3OL/i3gJiuULYyJNB5Jb+7uCtm5qADdF0jOTKDuy8hx7otldlaCwhpzdoYA+9VpKhZ7w49xNrtWyBzaPGyKL6TwquS6wkg= 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=LD7OZYKR; arc=fail smtp.client-ip=40.107.208.24 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="LD7OZYKR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vl/QsWCoH+x/zImJ6N5x9TQ5xoyXFR06ZBBQTr2odWZmhil19lCyZ7qJ7XGP6e8dTO2p7BBx97NOEGSdH7gTjhVXE7n6pi6lcOJRnu/jMW3H71oZTM+P3JvjzcundMWiExfO4mzzals/nw9pldwNF1RGE6edwqtEEDfCSknTnYNT5fXpQ/uKU/01VD5FsuYsuZfLOmVb/IW7OybR9Wssx1xmwaH19HNrRVfq61DVwI6qSGBCWD/sUDoCP+gRive5KxKg8kcl559rSEIg7LfNTCN8bfMV+g/Eqe7ZehseaAPUckUlrEbbyyrjdioVn7uCHmOgEj8B1lt7sZUMmqiIGw== 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=fxEeXPW/k8EEP3u2hRjtpmLROQKmXiRtZF6uhRfPljk=; b=IU1TMBGTeYjsgbjXmDKv+26iyRSDHhvlu/Onk1jAPcE5xHu0OPBFe0EDxsFLK1c6PUBKsI6mkGJN64xVMDyH6DcUsGRL3msWrIDUIkbBF3ILO+Rv12XmT0PXAcUCIS6kNZvLyXJpVxDwLHqXLyZuymTJY2vEQwGZE0hTFRy2suhq1QXriLu3V+4NM6MgZ76QVrdwzNMqtGWcRbeIkNC5XixV+Lv6CxBP4ysuGJj0mE0B6QzARP/8UhGe8qXI49lKT7pljLlZ8ofPtu/Bto9kenxlhSNQT5dMI8Hx2Pt9zVHeTdXvghXCoT/GFMDKT98TnolPT1u8tu9zEL4ek1x7aQ== 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=fxEeXPW/k8EEP3u2hRjtpmLROQKmXiRtZF6uhRfPljk=; b=LD7OZYKRdFCtYvP95ffRITyEV+uedk+OzmxP85FgExdRbchkm2jNcycohMHdPOx7QjIrWzENsoWO0OMBQVPZJ1jRasOdX41CGn2qqbCJQ4emLPufJm2SOU0X0nQDQ8Mf9QmG2RW+5mcXwE6c5x7aKhwM/fUkbpuZZ8+I0VAMj7VPkDkBLflsUyyQyYDNebeq4kFlV3riYSd0n3xbtRYiec1kl8UXIwa4kxGq6ZMSecW/PHOIJNJL8TCOJzE+NSc1BDLSwu6N52Ea4cTuBJEyzqrDsZKJPIsRBQko7sUkX3iIDY3hpteNgj8dz/JNpTQTuaf0/uncytTlMfJRKDElRw== 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 SJ2PR12MB8160.namprd12.prod.outlook.com (2603:10b6:a03:4af::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.15; Fri, 31 Jul 2026 19:20:07 +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.0270.015; Fri, 31 Jul 2026 19:20:06 +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 , Mete Durlu , linux-kernel@vger.kernel.org Subject: [PATCH v3] sched/fair: Prefer fully idle cores for NOHZ balancing Date: Fri, 31 Jul 2026 21:19:57 +0200 Message-ID: <20260731191957.3199642-1-arighi@nvidia.com> X-Mailer: git-send-email 2.55.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MI2PEPF00000B81.ITAP293.PROD.OUTLOOK.COM (2603:10a6:298:1::418) 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_|SJ2PR12MB8160:EE_ X-MS-Office365-Filtering-Correlation-Id: 0e7e4e9d-2d19-4b8c-da48-08deef38ba6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|376014|7416014|56012099006|10067099003|18002099003|11063799006; X-Microsoft-Antispam-Message-Info: d625oA3/FNOuRpuJ30EwXvv1WUq3tEWy2x0qrUjx8YiHXjQPTqcUGNuoZz/kAcZLPlLUCH5DnWYvPhI0ess/juKgLJarrFOTg/GbjyN6PxvLDJx5z7lTzzDt7Ah/+yW8smquWN3mBMf0GHTkpOF9n6FfxRL1LXYCrQrEEj4O6u/HcuuMKm9PXDu+MqfOqwMtx8BWpUFDHZucV7fLpbA9w/2l4F0n44B1zs7at05mquNYIk0j9knkbQlUJuQPWr7y1uqRTlqqk0N/OiQtfIynVPqsgGFQu16+O/i+DIQN5FTAkEG0TIrziVMpxuqcLuWRBMuB5j6Yo6ErL7Gcv1uTnQthsEdGaiRV6JleRsITBMkTWnc3PBvbf2GXxclxLjH0tjNeZGWLAF57aSb+tZ1GAo/rrhhPKOUdX4g2rraGnlIEBGFL+vcWGdw4IN5qeW5Apm7eSVI1sgEH4cbVfcb1JvUXsXrU1qF4YdFKYLG4R/eCpAc190sO1p2TlntFCDH4t2q8PgyMy7mkNL3KqtLOpfnTNPQKTNUqKtxGhmOm26h/HrcgmpNnLZQGFVDVgCZ96zUVs78ZUs0fS1VCEEeP++86EY8Tij4hy6AMIrIp4W0vR2Efianyu6qyPKYBVpsM8J0/q1g9WCC825LAx252F+1xgknTtGpHNGckgEFzqqE= 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)(366016)(23010399003)(1800799024)(376014)(7416014)(56012099006)(10067099003)(18002099003)(11063799006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yXObRF9Jtrx2Ob1y0X7G3SfT79gMKn/eB4i/G6WGpkXAQ1lEd/S34Rj7vBwK?= =?us-ascii?Q?7U0djxI893v9VHbEshWZrxe/pTQIhw+wq9wO8+boR8Ka8z0gPAnwm1ReXrS8?= =?us-ascii?Q?9/wEJm+WG9gYILDH17nShdUkGTaI0006fg3DA4+Q7cejVdhWpuIWhr+AyEBq?= =?us-ascii?Q?84GI8vgVr485J7GiHrz8WYi3Iuz0SPh7M2l7OwEx0sE1tDZkK/iVYQ5F95/8?= =?us-ascii?Q?obaT9l9O/zhLRFlHxXpSLHVEz7501Km4BYuHIvpFmtaodwVLyhPlHlCWrWu+?= =?us-ascii?Q?hOIT3Vp2ehHNOBiPRBpVt2/hOKy/LDhjQ3A6BRT2s3ZyYrJg8w+NqqXQsMvK?= =?us-ascii?Q?tw/AA84ElcmtW+jh75TzKJFVZtm/Xnyg2ZAy5penet79HuppCpc9nR6DEYJC?= =?us-ascii?Q?zDpa+KWZk/DuzU11xsbK4nUKeMkMEv7lgxr/hWOc9mwKlGGiXoOg1/IOmkAu?= =?us-ascii?Q?27pP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Gy6p2JmQhYnx8?= =?us-ascii?Q?Q3bQ16ljV+IVJIXBMd5jTMA86N3swzOrK7p3nJcO/xwwiZ7eh1HA34JPeale?= =?us-ascii?Q?07Yi014uAUqFQhz0q/88sSFavulRICzwtbXpWQJ49+kFdMa6pvieHuJmj6tc?= =?us-ascii?Q?8M7Tbce6Z1IHYc7j1WCTs0eK2XVW8Y9hgXs5CMSLVaB+hzgmtgHQZZOw02B6?= =?us-ascii?Q?2DcpZKX9Inu++O9S9KSfm8WJ1pyDvC3bXVE+ppOQNrIx4ftNcO9GsEAa1RZn?= =?us-ascii?Q?zpVs18NexIrQcvbf3omCjhOseFNL5yO+BTzcLxqfOD+tDQUR/Ut8XvqNsB7X?= =?us-ascii?Q?sY4+90oh9ps+Fla3W1LMVGTGnhw0IOhsRGAIW1HQT09u3YjjXdyHDSyVxXo5?= =?us-ascii?Q?b43DSaEpuw=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e7e4e9d-2d19-4b8c-da48-08deef38ba6f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4827.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2026 19:20:06.0110 (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: 1dC4rNdE7boSzTJb3P5FjTVNveGE2xmkFFlM6v4Exrj+m8bZPpOPwghll4/X0jFa2XQ2hfAQUII/OKguWJJ2XA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8160 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. Cc: Mete Durlu Cc: K Prateek Nayak Cc: Shrikanth Hegde Signed-off-by: Andrea Righi --- 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 | 56 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 37001c63452e5..574b6b3ee922a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -13965,28 +13965,66 @@ 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; + struct cpumask *ilb_cpus; + int ilb_cpu, fallback = -1; + + lockdep_assert_irqs_disabled(); - hk_mask = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE); + /* + * 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_and(ilb_cpu, nohz.idle_cpus_mask, hk_mask) { + for_each_cpu(ilb_cpu, ilb_cpus) { if (ilb_cpu == this_cpu) continue; - if (idle_cpu(ilb_cpu)) - return ilb_cpu; + 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; + } + + /* + * 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)) { + if (fallback < 0) + fallback = ilb_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; + } + + 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) { -- 2.55.0