From nobody Mon Nov 25 04:59:28 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2062.outbound.protection.outlook.com [40.107.220.62]) (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 E83BB13CF82 for ; Wed, 30 Oct 2024 07:25:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730273161; cv=fail; b=vCSvjeZ7PT9y4brvYgsPhnrM4zFr7pX28u5DqOVMccEDa/h+LdBvXoZYOrQlQOSzc4VrxDlPNe06Tsnt+SfZ0TaDKSFzg/NKemZah4rKG1fxF1i2T9HGVxRl9Qo4BxK1iSD/vpVxIeamlgfxSV6qLO8b95GwiCpHqsZ0FsRG8qQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730273161; c=relaxed/simple; bh=7cN/piHL+RmLwlBogUSCxkXXlV1zB5xh7nO6DwvH/jc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UlHcNfbNI+IyzJfqJPglqWjMCqkHlzobuXV3BKA2qEM8R+AlkFsQ43ZZvMBMP2vucb7Ihp/gdCn8/Wlm60kIQzTChOT/+NxJm8/iGZCOKFm4hWOKdyxa5ABmjx6ybRu92JJeN+5aMyg3OXnMLauJySi4qlUSKd6+80AiVzikhic= 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=s30IwE5k; arc=fail smtp.client-ip=40.107.220.62 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="s30IwE5k" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N94Bbg2+nQ4It+kR/4ISLm88F7Y7wr259QQEQr3+g2XIgBX+eP/RKPQ3fb71JHV0sCNq19yhqy0vycPj+rN759MY8qmzP4pnQm6zqVi92Yhrhr6yHA9ikMRstuVZ6L3b8nevnMNe4Eb3ay0guCn25otHxOd61K2PGO55M5hoWl5Qc68IstW9QeYu5YbMTIcHUKTb3PX99RWnRG72n5c9Cunx7mwSPFBXQQJDIj3anXob/1vgv5X+rdvDZZ7ldj8R7NCwDax0pQ/YOV+ziZe2L2vnckAKiV0sezT3gksjIi7GVypinD+eKvC+PsGMvxueb1lpXc+WfnZ5sIMsCritFw== 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=Nkzv30Ezz7l8xAfvMAVylfwv90yAkDltxvmkMfkX8M0=; b=Cy8GQMCKkbG0SLlIc4EmyJ9B0DyXn8vqbVCgoI7u7fZ9jnGByEb0Kt+xISWrjgN/o42wcyvm7KYsQtivhthb/QW343MoFuIblO05eQbo4sgjXXvyEA8SVFUNqzhEEAgHI+IK3Vu2cxv09TeEvtS6C53viv3I03O1nfPBPd3aYbJmnARTfip5COv4tmTZSlJ9O0A3XY3t4fAL3qb/+9vzbu2b2m8VQVK7NcEikDNsMWEVhYvvRQpgWEbkUKQrnYzeSBMX+BAOhnNmPWe2kwlULkwzEpRBEL39/sGNjMuXvil9dXYt8PY2iH/tFI9UhAKK3DoCBwottaUzu3z5Jf+VQg== 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=Nkzv30Ezz7l8xAfvMAVylfwv90yAkDltxvmkMfkX8M0=; b=s30IwE5kJe/ocIY3u5JP71vGBTpPM4b7TldMqWC6qwUL3EmQJf/4hGrSLe3AyXK93CEP7GKoGHYS24cyp8I9VP3ALr7AWz8ZdsI8w2jXRGgtfQJTpuTo2jG19D4sWP6lik8F2GM+ALs+d2VuR5ikIcaNmNM3uGHWx7cpIA7ZhOg= Received: from DM6PR07CA0062.namprd07.prod.outlook.com (2603:10b6:5:74::39) by SN7PR12MB8132.namprd12.prod.outlook.com (2603:10b6:806:321::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Wed, 30 Oct 2024 07:25:50 +0000 Received: from CY4PEPF0000EDD2.namprd03.prod.outlook.com (2603:10b6:5:74:cafe::3c) by DM6PR07CA0062.outlook.office365.com (2603:10b6:5:74::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.23 via Frontend Transport; Wed, 30 Oct 2024 07:25:50 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EDD2.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8114.16 via Frontend Transport; Wed, 30 Oct 2024 07:25:28 +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; Wed, 30 Oct 2024 02:25:17 -0500 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 , Jens Axboe , NeilBrown , Zqiang , Caleb Sander Mateos , "Gautham R . Shenoy" , Chen Yu , Julia Lawall , "K Prateek Nayak" , Julia Lawall Subject: [PATCH v4 3/3] sched/core: Prevent wakeup of ksoftirqd during idle load balance Date: Wed, 30 Oct 2024 07:15:57 +0000 Message-ID: <20241030071557.1422-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241030071557.1422-1-kprateek.nayak@amd.com> References: <20241030071557.1422-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: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD2:EE_|SN7PR12MB8132:EE_ X-MS-Office365-Filtering-Correlation-Id: 2cfcd6c9-4b2d-45e3-33ab-08dcf8b414a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|7416014|82310400026; X-Microsoft-Antispam-Message-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1soWKinusOWcDe6Beaz3RvxFPrzoRcfCh1CU1?= =?us-ascii?Q?UlipwKca8JuvDLSGRXVoelaueTSEpxTKRB8szSzUEmg+ASpXZiu7udS4rq+f?= =?us-ascii?Q?6OMOpbxQH2pobIyLL+OTG1XvSq5DUtkC2/dc2rQs5t51imcBPqF0Ou5CiYwT?= =?us-ascii?Q?gwSbhNnx/lia6VNbM5NwY5GKRKiSQe6OhHrUnxYY8saYIl4WWIQOYCkvnwj1?= =?us-ascii?Q?aAz6mLnroaqWTl212bR9N78xnr2kxhJ51+dGB1EqBB81p7jE1/2xQV0egcPy?= =?us-ascii?Q?h5I6qScOXXqrnRuyn+tm9m5yhwHeqNbUKAKOn0S5aeBuiWRw502fHomYzwnI?= =?us-ascii?Q?Vdn4ZrVEVvMgJ+2G7CZNzISCZWufaxOz9AGweSlRXlSaCCl44QzOPh1Qwo3P?= =?us-ascii?Q?PKIbWUBXhpJegVC8C7/mN/FaEvi03ggehgZ/uWDzhXPF8EozuxRlQhG2olE2?= =?us-ascii?Q?SP3p6nPx088hffkxyNEllJWiMzfc51pvJCfzw+RhXIC/sA+6qzYqtXTwR2kK?= =?us-ascii?Q?HiC+8sl9gEro2M7IWV2cukZM3NLg2Tugtk35ERTjLaJk5fDfdA=3D=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 07:25:28.1598 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2cfcd6c9-4b2d-45e3-33ab-08dcf8b414a5 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EDD2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB8132 Content-Type: text/plain; charset="utf-8" Scheduler raises a SCHED_SOFTIRQ to trigger a load balancing event on from the IPI handler on the idle CPU. Since the softirq can be raised from flush_smp_call_function_queue(), it can end up waking up ksoftirqd, which can give an illusion of the idle CPU being busy when doing an idle load balancing. Adding a trace_printk() in nohz_csd_func() at the spot of raising SCHED_SOFTIRQ and enabling trace events for sched_switch, sched_wakeup, and softirq_entry (for SCHED_SOFTIRQ vector alone) helps observing the current behavior: -0 [000] dN.1.: nohz_csd_func: Raising SCHED_SOFTIRQ from n= ohz_csd_func -0 [000] dN.4.: sched_wakeup: comm=3Dksoftirqd/0 pid=3D16 p= rio=3D120 target_cpu=3D000 -0 [000] .Ns1.: softirq_entry: vec=3D7 [action=3DSCHED] -0 [000] .Ns1.: softirq_exit: vec=3D7 [action=3DSCHED] -0 [000] d..2.: sched_switch: prev_comm=3Dswapper/0 prev_pi= d=3D0 prev_prio=3D120 prev_state=3DR =3D=3D> next_comm=3Dksoftirqd/0 next_p= id=3D16 next_prio=3D120 ksoftirqd/0-16 [000] d..2.: sched_switch: prev_comm=3Dksoftirqd/0 prev_= pid=3D16 prev_prio=3D120 prev_state=3DS =3D=3D> next_comm=3Dswapper/0 next_= pid=3D0 next_prio=3D120 ... ksoftirqd is woken up before the idle thread calls do_softirq_post_smp_call_flush() which can make the runqueue appear busy and prevent the idle load balancer from pulling task from an overloaded runqueue towards itself[1]. Since the softirq raised is guranteed to be serviced in irq_exit() or via do_softirq_post_smp_call_flush(), set SCHED_SOFTIRQ without checking the need to wakeup ksoftirq for idle load balancing. Following are the observations with the changes when enabling the same set of events: -0 [000] dN.1.: nohz_csd_func: Raising SCHED_SOFTIRQ for= nohz_idle_balance -0 [000] dN.1.: softirq_raise: vec=3D7 [action=3DSCHED] -0 [000] .Ns1.: softirq_entry: vec=3D7 [action=3DSCHED] No unnecessary ksoftirqd wakeups are seen from idle task's context to service the softirq. Fixes: b2a02fc43a1f ("smp: Optimize send_call_function_single_ipi()") Reported-by: Julia Lawall Closes: https://lore.kernel.org/lkml/fcf823f-195e-6c9a-eac3-25f870cb35ac@in= ria.fr/ [1] Suggested-by: Sebastian Andrzej Siewior Signed-off-by: K Prateek Nayak Reviewed-by: Sebastian Andrzej Siewior --- v3..v4: o New patch based on Sebastian's suggestion. --- kernel/sched/core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index aaf99c0bcb49..2ee3621d6e7e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1244,7 +1244,18 @@ static void nohz_csd_func(void *info) rq->idle_balance =3D idle_cpu(cpu); if (rq->idle_balance) { rq->nohz_idle_balance =3D flags; - raise_softirq_irqoff(SCHED_SOFTIRQ); + + /* + * Don't wakeup ksoftirqd when raising SCHED_SOFTIRQ + * since the idle load balancer may mistake wakeup of + * ksoftirqd as a genuine task wakeup and bail out from + * load balancing early. Since it is guaranteed that + * pending softirqs will be handled soon, either on + * irq_exit() or via do_softirq_post_smp_call_flush(), + * raise SCHED_SOFTIRQ without checking the need to + * wakeup ksoftirqd. + */ + __raise_softirq_irqoff(SCHED_SOFTIRQ); } } =20 --=20 2.34.1