From nobody Sat Nov 23 18:05:37 2024 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2083.outbound.protection.outlook.com [40.107.92.83]) (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 CF72311CA0 for ; Tue, 19 Nov 2024 05:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731995151; cv=fail; b=uyYmhfj5Oba66ddOQU8auOV+NDbaHs6Ln1vgWb0G03TaFIUPKxHw9oc53Q1cJIe+zFzbyIRr4N6xD9982wE2ySx3AQApn4y3cGj2hxW6Z3SemiOyc8/mv9IC9QN3+MCz6QXu6vcNqe3az7J/33S1npTwkolcaZ27zNEkHoPo2DE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731995151; c=relaxed/simple; bh=MOSwCEVScRBGxjHxi9jQzzkIWqmKmrg7wW2CnkCTk68=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pi/mfmB1jDSA3GepQ0+2b6/lOg3ob4SghnIVTYmN6aPG29wSvpvUuh57hXq0V42n3bVV1SjSi8hHWdaT41vdww4GcJZSAGzeWDdB6VtTt1ylKPoqGitRfQv8YFL4LHDC2U35UxLfuFV1fVZ3lfayQuzvzLmDMuPHiQc5XLkGZDo= 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=Fm8grh/m; arc=fail smtp.client-ip=40.107.92.83 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="Fm8grh/m" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RxWtC2DxiI8ZoSTJHUNMFEa9ly4ZKEliCq08fCgKrYYapmFsB0HwQ6K37QKvpy2ze1/xMhAlKDQbaBYoTh+fMhLybDS5+h/oK35PoZg8otDF1+Pc9bLN/vMJcrj+c+zFf/RfR2i1fXSj20EF5aItoxGBwXsxJtER/nYtTxtpvwHBLb+FU70AdxECWX+Yp1z9Y3PoPItu9fNmyjY2zYJvj142USymNV4BmibrEyT+Dc2TZSMFqDYbU+WvEqa4LEwv4E0leQz+9NHHqa43E4S57yjwNkVIzU+/a0wy4KlUexsqMPYJZruBjEs32y7R+yU6vqNfdT+DKNyArxmPzmQ1Gg== 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=WS9hm/KjUWl+Wpcw5jNpBeKzC1ALZbApj+pKBhsvbYg=; b=u2AkzO8gZUnkYvcKS4HUSExWx6/Fwo6GqVQx0RJFHX9y1ZRuWH549/M42b+e9OtBuOVcGtizNpKwo0Z82j6CZbdjpdpm1fnh1LkdetVEXhC/KqymXcgOssfNoxUXuX45tn6UuEgis9CS4Uaif7tozRg9v5Fviedve0WP+8hr5zz+NB0eRx4yGUPw5OiDVS6HKlmLoMgHtO7qVmk8PuwnSkgSlZv9tS1oJ2nB0vD8QuvRVvC3gRR7MuyCkqLfWBAjniGdeT+24uRe926FhJGuVcIXI7hJFipX0yBgIXCnlL1Mh2Ec3n1HeqoOesOCB9OpcVwXPm5EkoF/oFZU6xH2LA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.12) 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=WS9hm/KjUWl+Wpcw5jNpBeKzC1ALZbApj+pKBhsvbYg=; b=Fm8grh/mkqCXW2PBR7ZUlvu4WByhVVF/BVKxbqHng1HFdVdLU3yK72TVQ6Z1zCImBfyriS1puMyfeiSK5jdFXgT+/AG6XmAlfKtHGAdo+IZboohVFV7a1MWFTMLK9ZRTf5a1NBsufR93aNeCNwlZuOVdeRXl9evtzWYOmNs1eVM= Received: from SJ0PR03CA0385.namprd03.prod.outlook.com (2603:10b6:a03:3a1::30) by MW5PR12MB5600.namprd12.prod.outlook.com (2603:10b6:303:195::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22; Tue, 19 Nov 2024 05:45:46 +0000 Received: from CY4PEPF0000E9D0.namprd03.prod.outlook.com (2603:10b6:a03:3a1:cafe::58) by SJ0PR03CA0385.outlook.office365.com (2603:10b6:a03:3a1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.22 via Frontend Transport; Tue, 19 Nov 2024 05:45:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.12) 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.12 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.12; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.12) by CY4PEPF0000E9D0.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.14 via Frontend Transport; Tue, 19 Nov 2024 05:45:45 +0000 Received: from BLRKPRNAYAK.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Mon, 18 Nov 2024 23:45:38 -0600 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Sebastian Andrzej Siewior , Clark Williams , "Steven Rostedt" , , CC: Dietmar Eggemann , Ben Segall , Mel Gorman , Valentin Schneider , Thomas Gleixner , Tejun Heo , NeilBrown , Jens Axboe , Frederic Weisbecker , Zqiang , Caleb Sander Mateos , "Gautham R . Shenoy" , Chen Yu , Julia Lawall , K Prateek Nayak Subject: [PATCH v5 3/4] sched/fair: Check idle_cpu() before need_resched() to detect ilb CPU turning busy Date: Tue, 19 Nov 2024 05:44:31 +0000 Message-ID: <20241119054432.6405-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119054432.6405-1-kprateek.nayak@amd.com> References: <20241119054432.6405-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: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D0:EE_|MW5PR12MB5600:EE_ X-MS-Office365-Filtering-Correlation-Id: c4002bed-e9dd-46ce-7c5f-08dd085d69c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|7416014|376014|82310400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Fs+dmsGcrgoHnBCZSpGMU3ne5n73W7YpZ1gKUFDQkGT0jQ80dFD?= =?us-ascii?Q?BJgBZjYFLoBP80CR+4UTXivvX6JhxxR7pQvMdAA7W+wncyiUFIdhrjCddG7B?= =?us-ascii?Q?stXRHMxV341ikYLY7HZyG2uKv+McWWim73AX2Fhwts7ioBHCamGBmPhtPb30?= =?us-ascii?Q?9wFov9Acv1dXcmvg1cRc2boiVLswSsJXrgqZ73EskNNXD9x6K492NrZR0GPG?= =?us-ascii?Q?h3UuqpCvyMN+gCL9KVmVqsfEiOBWlX3PBwR9W82Ptp/uNz84Rh4uNtSTJbAy?= =?us-ascii?Q?4qVvvPVXwWQ3hbyyA0qDrW58JyhL6v0NT7tXp42IkeGhcP/57Y0CNqd70fjz?= =?us-ascii?Q?Tx8R8RCDJmjeVen2bmb7gyj9zk/GiTSFWlHjkgNZKoarq2JqHg7Gj/OByw7T?= =?us-ascii?Q?vzLJkg+4RWyNV0U2zsO+b8yECJtuuCARSCrW6FnP+9SlKEstffB6yo67g19N?= =?us-ascii?Q?mEE4TDxHb4Ry0zjKdXRrBvEyCVhuFOghU5k+ihqa4XmtnTBMJbno6JbvTReg?= =?us-ascii?Q?u7B1X9p9Yowt587JdORyR/VKe/Lxl9rbiaVOqBEjuehGOPyjlw=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.12;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:atlvpn-bp.amd.com;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2024 05:45:45.4225 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c4002bed-e9dd-46ce-7c5f-08dd085d69c4 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.12];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9D0.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5600 Content-Type: text/plain; charset="utf-8" Commit b2a02fc43a1f ("smp: Optimize send_call_function_single_ipi()") optimizes IPIs to idle CPUs in TIF_POLLING_NRFLAG mode by setting the TIF_NEED_RESCHED flag in idle task's thread info and relying on flush_smp_call_function_queue() in idle exit path to run the call-function. A softirq raised by the call-function is handled shortly after in do_softirq_post_smp_call_flush() but the TIF_NEED_RESCHED flag remains set and is only cleared later when schedule_idle() calls __schedule(). need_resched() check in _nohz_idle_balance() exists to bail out of load balancing if another task has woken up on the CPU currently in-charge of idle load balancing which is being processed in SCHED_SOFTIRQ context. Since the optimization mentioned above overloads the interpretation of TIF_NEED_RESCHED, check for idle_cpu() before going with the existing need_resched() check which can catch a genuine task wakeup on an idle CPU processing SCHED_SOFTIRQ from do_softirq_post_smp_call_flush(), as well as the case where ksoftirqd needs to be preempted as a result of new task wakeup or slice expiry. In case of PREEMPT_RT or threadirqs, although the idle load balancing may be inhibited in some cases on the ilb CPU, the fact that ksoftirqd is the only fair task going back to sleep will trigger a newidle balance on the CPU which will alleviate some imbalance if it exists if idle balance fails to do so. Fixes: b2a02fc43a1f ("smp: Optimize send_call_function_single_ipi()") Signed-off-by: K Prateek Nayak --- v4..v5: - New patch. Add some details on implication of threadirqs on idle load balance and how newidle balance helps those cases. --- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 225b31aaee55..fe6db479a855 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12564,7 +12564,7 @@ static void _nohz_idle_balance(struct rq *this_rq, = unsigned int flags) * work being done for other CPUs. Next load * balancing owner will pick it up. */ - if (need_resched()) { + if (!idle_cpu(this_cpu) && need_resched()) { if (flags & NOHZ_STATS_KICK) has_blocked_load =3D true; if (flags & NOHZ_NEXT_KICK) --=20 2.34.1