From nobody Fri Dec 19 13:09:32 2025 Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012025.outbound.protection.outlook.com [40.107.200.25]) (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 58F0232ABF3 for ; Mon, 8 Dec 2025 09:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.200.25 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765186461; cv=fail; b=Y9wcuhIKwSAa42YQkPyK3Rl+w2c3RFMc/xLczNZvH86MDlwzdHdtbQyuwCcW9ucaWAk4+SB4YEGNHvYmgN32oAFggR/70zyffD5e4xo+MgAgWUhRSa4wH3Y+wWZtUr3mDOF3BbF9FyH6ePT8Ec6N9Ckcuq3ztZS+8qLqS3dhexg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765186461; c=relaxed/simple; bh=io96e90hULF/LhgXhTp6O92S5mSl/kEiEKXt2tB+fuo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FeLOMIw96iamPANRCaAbRw42b/JJ+TawOeCPzwxws1nysGeRschaUVtngb9ADYvgvlCxuDUDtr1aroVRUb1J+cRZr3FfNlxIb1pn8+JJ0Dz/wuE7OHFx61kKqmDCthpbQdpJ77xU7kSGngjQ3CqWv71F8Fhsvh7inNTWvpSJedQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Pp8B8jjM; arc=fail smtp.client-ip=40.107.200.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Pp8B8jjM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XB2uNWh36JOrVbf5fJvj0FHX8geY3HgGG9go0pVr310NNgn0gwKBBdfppQbP2QUX2DHk21V8sinqhzRrLg2mYnVM47DRqhVGKkyhfjS0CryYWqy/y4UxkKk5mpITI2w0EJqu5KP7OQdtd47vr6aseFxbcGz/hit55TMI4AjUBClS+4XUN6ZVKvjqjxYl4x6EW1ibwSISe4rJRHVLDIrMov7S0Soq7M0oyn2n4xu5fwZxtaV34umFxsDnLPaqRRFoNK90Xd9a+jZiHGU0VMmjh0UqLy4HO7oKz3QUfnLm0U0Le4QRc7UJbeJ2OPc3gPVYpEahESbKbLXozT9Esl8wng== 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=CXs6LluM+ephkAJ8Afga0DWVMXyu6xck8veRPK2a8XE=; b=iDT02B69u7dh8HsyCbYKVMkPSxnMG4gJh1VJ0+MPv0VmynM1kU4cQ7s2Piy8ajLSHvbOz3Vz9ornJnLJGDsCWGsxMQCVx/mQ7nzxe7KDCcwDQUr/LXDdThh+H1wYM7n31U4kJjwvWmVl2dw+vu9O3SPM3ug6RKNmUrxUFUdoRSWgXD5TJESqHd+VbqnMa27t+LZ/tQa75WeP5zhYRmmwII943K4T+q+LbWCWDAZP/wh1u7o61HUmOKom+40QHLeXZmMvDpHcQhgQrBk99a+qdh+lcmGyu9QzzMOLptlGdxvQecQ5qop3qd6Eq4+i5Te3k1fxqauA3jmXcmn6yKYgtg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CXs6LluM+ephkAJ8Afga0DWVMXyu6xck8veRPK2a8XE=; b=Pp8B8jjMcuO43pZXqkbAFL3uqoGlqknz4wijds24mkz6X626PawYI+jc28XfivoECRk/7BqE48EWbFIJ2wbKiqigLbbue3P1NyDlg9Cg+dFUxKwKiHEzLdyEhEthuiucHWKqRuViIQcfPYybEqd7AoljQfo1fGv38oFrHwQgM9k= Received: from DM5PR07CA0105.namprd07.prod.outlook.com (2603:10b6:4:ae::34) by DM4PR12MB6280.namprd12.prod.outlook.com (2603:10b6:8:a2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9388.14; Mon, 8 Dec 2025 09:34:12 +0000 Received: from DS3PEPF0000C37D.namprd04.prod.outlook.com (2603:10b6:4:ae:cafe::d8) by DM5PR07CA0105.outlook.office365.com (2603:10b6:4:ae::34) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9388.14 via Frontend Transport; Mon, 8 Dec 2025 09:34:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by DS3PEPF0000C37D.mail.protection.outlook.com (10.167.23.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9412.4 via Frontend Transport; Mon, 8 Dec 2025 09:34:12 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 8 Dec 2025 03:34:06 -0600 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner CC: , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , "Gautham R. Shenoy" , Swapnil Sapkal , Shrikanth Hegde , Chen Yu Subject: [RESEND RFC PATCH v2 22/29] sched/fair: Convert sched_balance_nohz_idle() to use nohz_shared_list Date: Mon, 8 Dec 2025 09:27:08 +0000 Message-ID: <20251208092744.32737-22-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251208083602.31898-1-kprateek.nayak@amd.com> References: <20251208083602.31898-1-kprateek.nayak@amd.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-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37D:EE_|DM4PR12MB6280:EE_ X-MS-Office365-Filtering-Correlation-Id: 1668d8de-77fc-449f-99f3-08de363cf28d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|36860700013|82310400026|30052699003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hgkz1eIq2Zd1WEaxCXQVpr0ZalGnMYlFQoN0uHqoysbJPpS7hbzXjoi5kwNk?= =?us-ascii?Q?T95D2esFToFxTqN66d2UCodmlev7CzPK7mchM5yTEjzP6Gsy5PX0bJz7Xd+9?= =?us-ascii?Q?QQgvYzBUDTksOdQQ3G+rvTYE4uY7pq/bzKduF/xToZS9eOsuQVRD50LkgHA9?= =?us-ascii?Q?q/iePKREWT5flfmjO4Ki+Ngx6gfRmQjaU6C9iDJT64xok2kZICmXLj1Dyptg?= =?us-ascii?Q?kiRjj1adq4eb2RVH4pwjeP+cGAhvJj4zBwlT6OhDqP9hWTxEG0cIc2pUqjMz?= =?us-ascii?Q?zexmucVavEuWiLpauhZlQcM4inbjldVifBrd9XSnMiDjyEEIuY2NViwf6JsL?= =?us-ascii?Q?Qes68MmtULJNuDfugNlv1EIQzZONfFRO21MEhHqKj2tEoGWyjG9qe1R3BaGR?= =?us-ascii?Q?af2HEcZpOR8KF70qYJZp4F8MckYGwe3YCN0ZwVfKLDYRezG5QenaVG82FnVf?= =?us-ascii?Q?2ursdmioeXZDO/2ydrAG0BldVjgRStdQknYGSJ++n8ZzF6Yec257YINXJISN?= =?us-ascii?Q?A0e870p4CCVeJxsVNNpeQJX3ez8u+UUfv5rP39XEDIm1atCXlRewNyQmes+S?= =?us-ascii?Q?hD99TKQgOEqsgxRdC4NC09SYjif731udkydtswa84jVHzaqIoX4xCbAzIcOx?= =?us-ascii?Q?O8gfTv6WRvQhehj2kw0t9jbyebgYLFAX5u1zxxHnYBHDBwWkrvi/Y1FMl6Sv?= =?us-ascii?Q?fB85S0zSeyknrT4n3QT8DS2EChY+/qZ0nzlTkbThFjrK0+wjw5VTam6+bcpK?= =?us-ascii?Q?lenNHZgejOGdOrXBx3ZIEazcTZMJI0k5oWTDPV/t6jTa1s7f0a05rb6UBvhH?= =?us-ascii?Q?bN+B5UJwcZDc++16mJDkOpM0oHtzgkJ5gOQPm5ywbiQYGF57DmFcb2u6+cSv?= =?us-ascii?Q?HRCSv8cdjNXKm/3mCrRM32+e8SgN+0pxGc5etC9bfs4ZQv72JobB+jDiCi6t?= =?us-ascii?Q?l+597QlVNTeVfqR/Um/K1VeL3JEfABcuovST6QrDiJcjkwU3Hjax3qvnHYXE?= =?us-ascii?Q?sE/pOakgD+vMz/5PEhux6aGpCFXgmwGMGRF4BeI3TTajd68DB2KwCiliTg2s?= =?us-ascii?Q?gLAbVxQL9yZJHx42xuR83ybed2DFrMAlYVep+gm1wHoawJ7nSO83sCjHLB4s?= =?us-ascii?Q?7kPYo3cx7EDGkK+kbZrgqxUraS7uK2uLQmEAwzUdijcrYKZCihH0eHxOcdzq?= =?us-ascii?Q?9NlcSiHSZAQTy72Pj/pIcj8cSRIl5dHXQOAKrMqXRJ3I8HZUzpAIx4iC+SRy?= =?us-ascii?Q?ay5SWIMX5gBdG+v6qGXIgR071A2P3VoLqQtUdXt0gIMHbQWSNAC+1J05jJdR?= =?us-ascii?Q?YU3PEaH53kNoiOPF5FKY9RKWaGvb9Am3FwSPNguImqHKG3zNQDYg2ABTphCS?= =?us-ascii?Q?49WYPiHjkP85FuzL22mdNTjk0GvVrXSmBVzXbd5Ws8Kae5eeMmmxsav3dVDm?= =?us-ascii?Q?+r1sMqS/o443L/213x7z0awkQy5ES9eASC3W8DXarhuRK9q8bZirXS4VBjhv?= =?us-ascii?Q?dgN2kThxfh41iqS5rGabEEPGSFX3CK/Jz+vfLRLdyh7lOj9mrlNat6rC7jqG?= =?us-ascii?Q?uXqyVRISUPaGF7KLYJg=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(36860700013)(82310400026)(30052699003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2025 09:34:12.7679 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1668d8de-77fc-449f-99f3-08de363cf28d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF0000C37D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6280 Content-Type: text/plain; charset="utf-8" Convert the main nohz idle load balancing loop in sched_balance_nohz_idle() to use the distributed nohz idle tracking mechanism via "nohz_shared_list". The nifty trick to balance the nohz owner at the very end using for_each_cpu_wrap() is lost during this transition. Special care is taken to ensure nohz.{needs_update,has_blocked} are set correctly for a reattempt if the balance_cpu turns bust towards the end of nohz balancing preserving the current behavior. Signed-off-by: K Prateek Nayak --- kernel/sched/fair.c | 62 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ca119c57a2a9..b17861bd684f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12789,27 +12789,59 @@ static int sched_balance_nohz_idle(int balancing_= cpu, unsigned int flags, unsign { /* Earliest time when we have to do rebalance again */ unsigned long next_balance =3D start + 60*HZ; + struct sched_domain_shared *sds; unsigned int update_flags =3D 0; - int target_cpu; =20 - /* - * Start with the next CPU after the balancing CPU so we will end with - * balancing CPU and let a chance for other idle cpu to pull load. - */ - for_each_cpu_wrap(target_cpu, nohz.idle_cpus_mask, balancing_cpu + 1) { - if (!idle_cpu(target_cpu)) + rcu_read_lock(); + list_for_each_entry_rcu(sds, &nohz_shared_list, nohz_list_node) { + int target_cpu; + + /* No idle CPUs in this domain */ + if (!atomic_read(&sds->nr_idle_cpus)) continue; =20 - /* - * If balancing CPU gets work to do, stop the load balancing - * work being done for other CPUs. Next load balancing owner - * will pick it up. - */ - if (!idle_cpu(balancing_cpu) && need_resched()) - return -EBUSY; + for_each_cpu(target_cpu, sds->nohz_idle_cpus_mask) { + /* Deal with the balancing CPU at the end. */ + if (balancing_cpu =3D=3D target_cpu) + continue; + + if (!idle_cpu(target_cpu)) + continue; =20 - update_flags |=3D sched_balance_idle_rq(cpu_rq(target_cpu), flags, &next= _balance); + /* + * If balancing CPU gets work to do, stop the load balancing + * work being done for other CPUs. Next load balancing owner + * will pick it up. + */ + if (!idle_cpu(balancing_cpu) && need_resched()) { + rcu_read_unlock(); + return -EBUSY; + } + + update_flags |=3D sched_balance_idle_rq(cpu_rq(target_cpu), + flags, &next_balance); + } } + rcu_read_unlock(); + + /* + * If we reach here, all CPUs have been balance and it is time + * to balance the balancing_cpu. + * + * If coincidentally the balancing CPU turns busy at this point + * and is the only nohz idle CPU, we still need to set + * nohz.{needs_update,has_blocked} since the CPU can transition + * back to nohz idle before the tick hits. + * + * In the above case, rq->nohz_tick_stopped is never cleared and + * nohz_balance_enter_idle() skips setting nohz.has_blocked. + * Return -EBUSY instructing the caller to reset the nohz + * signals allowing a reattempt. + */ + if (!idle_cpu(balancing_cpu) && need_resched()) + return -EBUSY; + + update_flags |=3D sched_balance_idle_rq(cpu_rq(balancing_cpu), flags, &ne= xt_balance); =20 /* * next_balance will be updated only when there is a need. --=20 2.43.0