From nobody Wed Nov 27 11:53:38 2024 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2062.outbound.protection.outlook.com [40.107.94.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 467571E3773 for ; Thu, 10 Oct 2024 08:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728548979; cv=fail; b=QZKBtp+DEKLO9xmR3uPuwjPna+/YmhJ36/gjiVTPhMiFH4aHSA4ZCXlj6l7lPcyDggbSwCSjGCRLDyiJ9GQTj3Jd23PZoeEMH9Wd3jfWCj+IBC2CGi2fTyNYWts46RLvdg7uaefB8TAxRymoMDo5tGfPEyMI/A0qsr5ove3DahM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728548979; c=relaxed/simple; bh=hulwKX8jWsZiNEtFHe9VYYzyLe+Mg3QGnR9P/Tw3xOA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TLvLU7YiWIC953EOYr2tpSB5dXkuWjhGTtAPdKb0GboyDqhXhJCbUnwBXi2PUJNKervAdKMU5+o2k+WhrEh969tkWquq4AHnQuGJqMEzAFoiwXX1TlcTBX9p87sYB1CPMysonp8nH83Y5QBAwAolfxtRlqdwBWnlJPhOk0fJsuM= 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=zTW1mSaJ; arc=fail smtp.client-ip=40.107.94.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="zTW1mSaJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HZIp7/tAY1OdlWU8CXQ7EglJYGfBGgb8C3yoxGtLwnshDaCOFXkGL3cNXM9CNJizrbcUwOfm3XQ0/pvMpIZiPo7VGworJ+8iVyA16NpJm57N4g/jX92EP3abaGw3zxCLmc+ViDpcSm8xpqm+F17HRTuvwxqCj0Kw5ARvdFE0wDQBT+L0ENJ9XJwh4zO7bodrSZGXEUKydWDtZW4XZh10GbvirB71NB97LpDf8ITESmkEr4eshR+LF9yjoE8oKwHuwMfjAvCbmHcsJirgQ6sSC+K2G0NM7BEvQlDFOlHV9BeIMoTuD72lDuwdCd6sflmXtk+bB0wCESxnbUgl4K5GvA== 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=J+cMX++V34JW6/5jOm09lyKyVzUKWmln/w5kZFVId3M=; b=tv2jHmKNg4I/H9FpcjlT8EC0yFDWwuYEqXsml4cW9ZhN2xjFKsZNqsQk6JwiOZEnz5Hz71dL8KZd+ftEquzq0R9L0eVHC8SSeHZ3AkjflKxS41//eKFJORMrLGvgI33qQERpz9VGYlXyE50CufmA9m/IKU8dJ2ZkudMI7c4VI1FMs3WroLp69nvFsG96hHYk2amH4w2qTgUywPIyc/BZcYzv31tEEB+Lof8sJCh1yuwdRI9C53qAZ8C8/Wafe04BxDzKZn7lCMqynlQOwDb/ZEE5yf0AFhcSVURIxZkZb5PjYv3mKLBRkB7SAa9HLVeimXlaqYuyAzt19Leqz952nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org 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=J+cMX++V34JW6/5jOm09lyKyVzUKWmln/w5kZFVId3M=; b=zTW1mSaJGDSTFDgwTNQHgZBdMgp5qP5+961p/m/1JKUT+BKuY1htKrZwd391+xFCwxZaYK/ApAiTYLWGH0V2F7etKgTfE27qg8qgBKFBEs9mtrMqIyMIoJP9WS0nIaYuPX7RLZ9xbqdWhxGvAbgJBhK7V6U2GcBbKpvIZEQVMZM= Received: from BN0PR02CA0031.namprd02.prod.outlook.com (2603:10b6:408:e5::6) by SJ0PR12MB7034.namprd12.prod.outlook.com (2603:10b6:a03:449::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.22; Thu, 10 Oct 2024 08:29:34 +0000 Received: from BL6PEPF00022570.namprd02.prod.outlook.com (2603:10b6:408:e5:cafe::41) by BN0PR02CA0031.outlook.office365.com (2603:10b6:408:e5::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.17 via Frontend Transport; Thu, 10 Oct 2024 08:29:34 +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 BL6PEPF00022570.mail.protection.outlook.com (10.167.249.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8048.13 via Frontend Transport; Thu, 10 Oct 2024 08:29:34 +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; Thu, 10 Oct 2024 03:29:27 -0500 From: K Prateek Nayak To: Peter Ziljstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Johannes Weiner , "Suren Baghdasaryan" , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Thomas Gleixner , Klaus Kudielka , "Chris Bainbridge" , "Linux regression tracking (Thorsten Leemhuis)" , "Gautham R. Shenoy" , Youssef Esmat , "Paul Menzel" , Bert Karwatzki , , K Prateek Nayak Subject: [PATCH 1/3] sched/core: Dequeue PSI signals for blocked tasks that are delayed Date: Thu, 10 Oct 2024 08:28:36 +0000 Message-ID: <20241010082838.2474-2-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010082838.2474-1-kprateek.nayak@amd.com> References: <20241010082838.2474-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: BL6PEPF00022570:EE_|SJ0PR12MB7034:EE_ X-MS-Office365-Filtering-Correlation-Id: d8251522-c341-4e41-cd44-08dce905ab89 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|7416014|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?A71nk6MY8CD4fTAoFvjUP+TrurqXBY0rW/Tp1TB4CRJ+9CxibIR16tyoKOsX?= =?us-ascii?Q?RPXpFsYMNmF3x97FFU8lRuH2d7CdN6+73V40Iew5ob1cXqANFttx3dJ40h4w?= =?us-ascii?Q?YybUmUfcXdRERBoNatrmFx+08R6GoKSDkbNaPDpBEC12qJlGMSXq4AgVG5K4?= =?us-ascii?Q?xNf+QcN4rj7qfWXL5D2glhDEp7kIh2PqAlq7J2maayv2/P6N42BZa8XiELTq?= =?us-ascii?Q?p/4nOQjoaK5VGYq0wNWKGPY6Ef/cZj9fIPuWXJxVcKpK2v8V2KNaKxDlHl74?= =?us-ascii?Q?YrQcHxoofHJICvYmvnd4y7W+M/G58P+g6w8pAJHKM54jon/QoKTmcpR3jBfX?= =?us-ascii?Q?t8P90XmYlFAEyJVZ+J3848qKQR/x4DzxHCzYMnhPpecsPm79NZyT/+ly4EIH?= =?us-ascii?Q?hgi+CjkNggQCQZIVyhdfk4qz3fhvW4rNdxQGb+OPbJoZ068EQSexehNcrSVj?= =?us-ascii?Q?hLkVu9XYiIqVxf6gqsOrwMVWyF53GZwuPUUfmvNvWBjBKzXjjycluBRB/bcz?= =?us-ascii?Q?qqInIn7e8YB9L7H2B0Smai289zzeJ6XZuc8olwUnvjLIInXIR0LLclN9+vWl?= =?us-ascii?Q?JtvdqbPrFalWqafzOJIdYFJFQSYNtMsn4KbPEuQ5TV39fpG2RO1fdJPePMqM?= =?us-ascii?Q?RCMkcQpfELSe41VNoGoFqcVYlXwEuyX7lPagyeDnmcBvJhFx/3QDA5D1JLvj?= =?us-ascii?Q?ztdZv8bj6XJsn4ZayAudTgHJCif2XiAsWwNN5Kty8OuUxnJ64A953QsbgXq5?= =?us-ascii?Q?5yAUY3uuu5I9zREUiVM8iJgO2RelJXTHKJvEFzY9I3GkTnksvR4rCPp8Tb0l?= =?us-ascii?Q?B6z1JWYQ6GegyIzfdJ/3FM2ZRzVyiXmfXZ5VDfYSaMZ9Ilh13pt5eCuISvfL?= =?us-ascii?Q?Qu3tDSvE60XIGviXV9cDAVmoC9mUUffa1DkDlfgrVPCioZn1fHu53SNe7ZxK?= =?us-ascii?Q?1ZHHBqJN9txT6YvFHRaCitRGfn1dlB3nBp32Yl+oKL4GtHEUOwPB2CvUcok3?= =?us-ascii?Q?8vaP31mErNaoKqHSXMI0h51Gp76kAq4F6KtL4AposFSrqU+C8tL1En1N69Vd?= =?us-ascii?Q?ysg4ggIWxAlsi38ZowuF5pXl8TebqQLWru8Y/Yd2448bUu1aDEC8WJdLYK8C?= =?us-ascii?Q?c5+FmSDittEYBmCh+B7snRMTETmpyIHZORRyFI8k92LidyKZRTPbBUv6kHuP?= =?us-ascii?Q?SHIHeZxd49PGMIg2NCgE1i/IceG82hxHT5vEfFVsloHPRwFI44Gdw1qS6cXO?= =?us-ascii?Q?QPgR10wGLhpAAz5svpVIYx4amYhGhyqUV1v3Z+DYgmxZl0ux7K0ic8YLlzC0?= =?us-ascii?Q?NZvIzcg+WGLbFAvX0CQa5mWBl3uZz2tQNNSWJx2KNM+QSIchuRC/KxroCSSu?= =?us-ascii?Q?6vmNDdkhAeodLIN2x8E1HSWdaiuT?= 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)(36860700013)(1800799024)(7416014)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 08:29:34.1185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8251522-c341-4e41-cd44-08dce905ab89 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: BL6PEPF00022570.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB7034 Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra psi_dequeue() in for blocked task expects psi_sched_switch() to clear the TSK_.*RUNNING PSI flags and set the TSK_IOWAIT flags however psi_sched_switch() uses "!task_on_rq_queued(prev)" to detect if the task is blocked or still runnable which is no longer true with DELAY_DEQUEUE since a blocking task can be left queued on the runqueue. This can lead to PSI splats similar to: psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D4 clear= =3D0 set=3D4 when the task is requeued since the TSK_RUNNING flag was not cleared when the task was blocked. Explicitly communicate that the task was blocked to psi_sched_switch() even if it was delayed and is still on the runqueue. [ prateek: Broke off the relevant part from [1], commit message ] Link: https://lore.kernel.org/lkml/20241004123506.GR18071@noisy.programming= .kicks-ass.net/ [1] Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue") Closes: https://lore.kernel.org/lkml/20240830123458.3557-1-spasswolf@web.de/ Closes: https://lore.kernel.org/all/cd67fbcd-d659-4822-bb90-7e8fbb40a856@mo= lgen.mpg.de/ Tested-by: Johannes Weiner Not-yet-signed-off-by: Peter Zijlstra Signed-off-by: K Prateek Nayak Acked-by: Johannes Weiner --- kernel/sched/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 43e453ab7e20..88cbfc671fb6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6537,6 +6537,7 @@ static void __sched notrace __schedule(int sched_mode) * as a preemption by schedule_debug() and RCU. */ bool preempt =3D sched_mode > SM_NONE; + bool block =3D false; unsigned long *switch_count; unsigned long prev_state; struct rq_flags rf; @@ -6622,6 +6623,7 @@ static void __sched notrace __schedule(int sched_mode) * After this, schedule() must not care about p->state any more. */ block_task(rq, prev, flags); + block =3D true; } switch_count =3D &prev->nvcsw; } @@ -6667,7 +6669,7 @@ static void __sched notrace __schedule(int sched_mode) =20 migrate_disable_switch(rq, prev); psi_account_irqtime(rq, prev, next); - psi_sched_switch(prev, next, !task_on_rq_queued(prev)); + psi_sched_switch(prev, next, block); =20 trace_sched_switch(preempt, prev, next, prev_state); =20 --=20 2.34.1 From nobody Wed Nov 27 11:53:38 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2043.outbound.protection.outlook.com [40.107.223.43]) (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 CD0411E47CE for ; Thu, 10 Oct 2024 08:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728548998; cv=fail; b=qrO0ufH9WbFRQk83V93aTdpRUvEmHlSzJA1K+n+/dkt5wXgG1DyytotddRa76wWHoOaXIxuxekOupbZnvi4tp28RL2UbR9CPQkKNz/3wA79QAMI4C85MXor2H6mBH4xSEwGxE3UMO1wRHAtQznYytp6fAD+qCCzRlq1kML8Gjy4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728548998; c=relaxed/simple; bh=XF30CN7cWmudARMquoHOZyuFyy9SaKpDMg+DZXNSi8I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JA1aHc03KiZ5ZIsAqaO4yrGLBBpTvtPr9UHDXbCwz3ndGbFkllPBZDKaK4tLedIRt/DjWnvDJSzo0UmcRNx3JS0YqoQfNmcIBc/y+03Xh41nRvmKgArRxiRg29vvh6C74uxvDCD6ZntU48FDm6qDvOOroBnq1CKpAlgH65nAyi0= 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=im5Buc1A; arc=fail smtp.client-ip=40.107.223.43 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="im5Buc1A" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QVATg5wYZkKQe4uul2O500HMrdG5swMWP9NVPT8E7JbeWPaz5e9cBju/pOFLonhWG5ZbBX6INkOCrdTpgVrhNIJ7HFc0rpn7rxf7yjFiHIAArV3LdAEDe3xSjslQ/gw7kc8U5dLwOCrSOHCPaj4NLq/qaERk/pVGPlhh7NyKLiUd3kHi6bnBUSNkNNZTY+7cAnStY5L+EQZP0wWcPmcV/mVV0gD7swCNbjt36U/gvSqYoRxCgI0KJUfUJD0GtD4QeMcOMoR/gb7s6hLT9n1s8oIZZsYII0YAmJehVicEORqZ/I0jvxE8EEu2ayspIBn+nGA0rq8afbtFCI4QPPQI2g== 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=oRw5K7kejgEm399NaHPqxG2ygmBBVcZmRM0t0JoPNTo=; b=kF7aS1EYv/5spiDimlnLvD8cI8ePJD/DuDUWhH77BjMqJKALF3vcsu1ITEzoPOgypM/wvp2WSIqe/8KkN5wXqkZqJ9vQyH3q8iI1Eqznm32wpnWtO5KuLapoTlU/YG5tKq5cYpPD6yT7wvzrxrwqM0vBvrQa5Bt0pPg2GjlFRh3B9y5GsuC79oo1BkbbtdgGeTymL009YrFvMhv1MyKMRH3NYSi7uPKgntscpvYAZKwdU7ZOx6hELfW1IRWhQtc+ooRCrPk7d4nfvYJAmknJjcvk44YGG3gqeedXdtbPF6WDiyxTiv1BbwM63EF7jJNhyETcuLJQPhot15IJxlvTsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org 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=oRw5K7kejgEm399NaHPqxG2ygmBBVcZmRM0t0JoPNTo=; b=im5Buc1AZ6vhY1Y7WWwrDPPZvJp5mEZvB4AtpypVWDYOh9V7ImKBuKRbHJp2qQKwX+B/6J/M/sLU8oZgd8NWl2r1c6qDPyZI8KDUVSPU9tF3chW2h/Um4znXSx73wqdBYuIE79C2Fay/+yTJkIcjj/U1FnH5VSz/nbOMEC3nNrY= Received: from BN0PR02CA0059.namprd02.prod.outlook.com (2603:10b6:408:e5::34) by MW5PR12MB5652.namprd12.prod.outlook.com (2603:10b6:303:1a0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Thu, 10 Oct 2024 08:29:53 +0000 Received: from BL6PEPF00022570.namprd02.prod.outlook.com (2603:10b6:408:e5:cafe::d2) by BN0PR02CA0059.outlook.office365.com (2603:10b6:408:e5::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18 via Frontend Transport; Thu, 10 Oct 2024 08:29:52 +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 BL6PEPF00022570.mail.protection.outlook.com (10.167.249.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8048.13 via Frontend Transport; Thu, 10 Oct 2024 08:29:52 +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; Thu, 10 Oct 2024 03:29:46 -0500 From: K Prateek Nayak To: Peter Ziljstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Johannes Weiner , "Suren Baghdasaryan" , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Thomas Gleixner , Klaus Kudielka , "Chris Bainbridge" , "Linux regression tracking (Thorsten Leemhuis)" , "Gautham R. Shenoy" , Youssef Esmat , "Paul Menzel" , Bert Karwatzki , , K Prateek Nayak Subject: [PATCH 2/3] sched/core: Add ENQUEUE_WAKEUP flag alongside ENQUEUE_DELAYED Date: Thu, 10 Oct 2024 08:28:37 +0000 Message-ID: <20241010082838.2474-3-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010082838.2474-1-kprateek.nayak@amd.com> References: <20241010082838.2474-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: BL6PEPF00022570:EE_|MW5PR12MB5652:EE_ X-MS-Office365-Filtering-Correlation-Id: 438a52ea-b58c-4027-2037-08dce905b6a6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|7416014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?74q0omOs68bwPu/H9qCOOw3ryaPCV2iI1XdHw3GCC04rUjL3RZaJwXYCjSQ0?= =?us-ascii?Q?SiwA51ETfJbS1+ljdq0GMkqlXPQLeF6NyK1n4q+iVMfN3/bxRAVuUliy03Mb?= =?us-ascii?Q?SDDvcow1PTKX+e29cs1boKgfXbpfMkDOxA0GF7S/pVwAfmtc7xBNXLG9L51J?= =?us-ascii?Q?QAnM55ZoaYqmF7A/TzHrUro4ylfkHxXHci2wTi3hrjCnesTdmZFvoIhk/26g?= =?us-ascii?Q?/WHMhy4nKFuAMBiFsgu/q0ko6u3Ec+uBBSbTK4Kx5C4QXw6dYvlDL2nJzYLb?= =?us-ascii?Q?NlL7GUVYUwdjn3kkY+0XGBBe1Q4uvn+yFXyMFqgNjJjFmdUXkUQzwkGAuqMf?= =?us-ascii?Q?bnRUt4geLzGIcvPqpeyTwFjszxsbuzEpU5qbUo8/mRu1bjKojEkmqCZUqwVJ?= =?us-ascii?Q?WtvDs4tUi7mxL4o2dob65j55Axgdr4dNRGET9qIbnXHcL+AWlIUO3ufAgK+p?= =?us-ascii?Q?2R18bG4VVjQ2c8oMp6ynxwskwApOtn5p2or5S4KiGjKONt+ulEQqdZW0GoLb?= =?us-ascii?Q?GrsVHiBh7ccZgaHwECth7BKg4kHo8qeOhsAYxD6yF8IVtLe3yuWESlG35SYg?= =?us-ascii?Q?Vz879onlwWAEU7CU3CNnoBa+F9YKANmdfnJLfPgDhU3kpxmSOA+y9pM+h34u?= =?us-ascii?Q?zRLZ0IcIV15j83RnaUsyk+4gB498HkivQ0tm1Hb+7RqpTGjKXkwjQnm/Rlb6?= =?us-ascii?Q?CtpSYHM3MNXmpeRg98aT0+uHEvBXLWVujKX5Ds7//4PK4W7SAqEJs0tKrYkV?= =?us-ascii?Q?VGLwYq9KbP1ZDAZEgh860fuDQNG+0UiuCm1kDoCvPTnvc9XtxFLdcLfOztuM?= =?us-ascii?Q?O120Igk9LqASXj19CW93iSGFJTRMbGCpnfPvX0mfkhAJ+50lEcXCb3ecr1G7?= =?us-ascii?Q?6Xmm4bWzBiZWCvh1MkwT2+YW21zfL8kynFkShSCXcG5DsQXZ3ZdMknuEoeqJ?= =?us-ascii?Q?di+SQBPcblupZ8nQmKrL7+AV86c830FyWwDAjkrCoHB51tV3Tx66RGr6vuxc?= =?us-ascii?Q?aAH8cpd0yC8G+3XOp14Whlbr2Y5Kl9PST7OWH7tZ8a83KP4zZakP5X2RDXxr?= =?us-ascii?Q?cWOxIcHwTnNl25zvexmzSf3qZTjQ5/s6eWl6SniBiZn/bDrB/6yKJ9Mvmpcs?= =?us-ascii?Q?9EJIwrzZNGwoIgoWBYqdGa7APcQdQdKAF4W2bcAPibg2upWXdEr967GgqNmS?= =?us-ascii?Q?6gz8XxZW+rJSOP5GrhfECwiyTqJdukcmZGdCeJEoHn54EJgdDn5kKM02CRy+?= =?us-ascii?Q?uS+qjwYEwi+k3qvfTKVtfzqBETbm2p4PyPIUb0pQw1Hg+aeZwGMUryVqqVfH?= =?us-ascii?Q?BEvwGTl2A0GQ7hLEGzfaZNPplT4XftARc+KYCv8tt7364erAJPnkcufFPX7Y?= =?us-ascii?Q?MMM0KZVkbK1JWBef9jEfSlnLWY82?= 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)(36860700013)(1800799024)(376014)(7416014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 08:29:52.7591 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 438a52ea-b58c-4027-2037-08dce905b6a6 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: BL6PEPF00022570.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5652 Content-Type: text/plain; charset="utf-8" With the fixup in dequeuing of PSI signals for delayed tasks, a new inconsistent PSI task state splat was discovered during boot similar to: psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D5 clear= =3D4 set=3D1 Tracking the PSI changes along with task's state revealed the following series of events: psi_task_switch: psi_flags=3D4 clear=3D4 set=3D1 # sched_delayed is set= to 1 psi_enqueue: psi_flags=3D1 clear=3D0 set=3D4 # requeue of delayed e= ntity via ENQUEUE_DELAYED psi_task_switch: psi_flags=3D5 clear=3D4 set=3D1 # task is blocked agai= n but 1 is already set psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D5 clear= =3D4 set=3D1 The TSK_IOWAIT flag was never cleared onrequeue since psi_enqueue() only clears it on a "wakeup" which, in term of enqueue flags, is defined as: (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED) Add ENQUEUE_WAKEUP alongside ENQUEUE_DELAYED for requeue through ttwu_runnable(). psi_enqueue() is the only observer of this flag in the requeue path and it pairs with the DEQUEUE_SLEEP in block_task(). Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue") Closes: https://lore.kernel.org/lkml/20240830123458.3557-1-spasswolf@web.de/ Closes: https://lore.kernel.org/all/cd67fbcd-d659-4822-bb90-7e8fbb40a856@mo= lgen.mpg.de/ Link: https://lore.kernel.org/lkml/f82def74-a64a-4a05-c8d4-4eeb3e03d0c0@amd= .com/ Tested-by: Johannes Weiner Signed-off-by: K Prateek Nayak --- kernel/sched/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 88cbfc671fb6..52be38021ebb 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3733,7 +3733,7 @@ static int ttwu_runnable(struct task_struct *p, int w= ake_flags) if (task_on_rq_queued(p)) { update_rq_clock(rq); if (p->se.sched_delayed) - enqueue_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_DELAYED); + enqueue_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_WAKEUP | ENQUEUE_DELAYED); if (!task_on_cpu(rq, p)) { /* * When on_rq && !on_cpu the task is preempted, see if --=20 2.34.1 From nobody Wed Nov 27 11:53:38 2024 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2084.outbound.protection.outlook.com [40.107.223.84]) (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 3F0DD1C2DC8 for ; Thu, 10 Oct 2024 08:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728549018; cv=fail; b=tuQDnd4ntSTQ4VmxDyXu2KBQJQOmiRqOX+zeyOtgWqBcMIIwr2YWyM7K8VR6Q5xUcnTfRVqF5qne8bsELGDFsgZR2gNvYrU4l0aQumEiDdjur7EB7cjNXU6F03gUsvG+WN/UHPnT3mFPOp3r8pbTI/EaO/wRsAoVApSmASCED8k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728549018; c=relaxed/simple; bh=nbJP8WRnCjnBhKbuGtdSj/ZNwLdbZaPTvZT65ZzOOZ4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Sv76N5v8z++KdFNgcsFuBkmh/mzwemHO8HSu0nRzZgucZc48pAn5U8DD3CskW5H+1fDKhlhU53/pJHup3kbdfpwFaUjs6slb5repHIzryILwfXvTBUlCxwjaG1ysJA9HxZl4NnO6M3scYKFUShCTlbUR8ciw7cnQVV1KQkgGEIs= 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=rtzkaLnX; arc=fail smtp.client-ip=40.107.223.84 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="rtzkaLnX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RrekyXAXoKLM1PSOuuwrEmKZLJGRiYLMtOB5ZgLIOKeoKKHmRE/VvteBewBmPLoaKiFllYwuCznc/pd8b4LgaYqckoh25iSvIc76TV9NZI43+eIvMLIT+Nte06i8qeUIb4Brk+5Zk0SMqti3nJLQbZVTy+zhLySv9/WIzEbudsphX3eoVjxOKIf3oqZBI4O8Ssq4g1WMW1Gqaek1+yCeZaAkuFNqQLkhnbWItV3YP9qHi+eXeOnTt6MHT1UTKnR7cqt5vn9m7oRl1n92q5BQGUi2hD1x4dJPDpxFhsHFqT+mvnROiZXs3fhgcHXho0kC6Cun+UR8HgtEMCYyPxshcA== 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=ll/5a6F3CswLgcNZn8xXuTF5Uvq6c1j7yM9pajEzP0o=; b=LqLr2s7v0VlkcyQ6At8Ysj+8qySAF2nl6WXeTuu4C/eoAua9Ou9YL5ltyNUVBeCu5PVBqAByZWuuVolSJM+ryMjBzuxjq7MbMV4nSly3uXSU64ibqswgTNDnwRHyMwHyS1cjx8X+REEkTlzfDRiMxSS/FSRPcEVNXCmdA75w7qew5reJGhZ7rWbMc3SS4kr1SqZMvVxFCcxgXkzxprrSesjdM/Mv1hcBhpSRivFIYgXK+sD8wJ3ansk0/nR5SiqmmQ94gKsDm7dgBywniSmeRlP2Qjuwh3Rwr3+hA2+Ewck1NTj01TKVIy8XT28o//1HUh5nPwGtLCJhK2w5Y7ndJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=infradead.org 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=ll/5a6F3CswLgcNZn8xXuTF5Uvq6c1j7yM9pajEzP0o=; b=rtzkaLnXszwWNdxwsxuNVxDj4dPEZAKA/7TvEPBeqvpoV5wBdcoOarnJqCFzezK6FG+lqj60j6YLHCo3m6imR/8zFWINieNFQu5RTc8scviEC5N+H44ByFCOb/Kps7a4MirLvx1tZGu5A0LLXlDjfxpAC9y7E2CQQeqm/KHrZY0= Received: from BLAPR03CA0082.namprd03.prod.outlook.com (2603:10b6:208:329::27) by CH2PR12MB4087.namprd12.prod.outlook.com (2603:10b6:610:7f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Thu, 10 Oct 2024 08:30:12 +0000 Received: from BL6PEPF00022575.namprd02.prod.outlook.com (2603:10b6:208:329:cafe::4a) by BLAPR03CA0082.outlook.office365.com (2603:10b6:208:329::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18 via Frontend Transport; Thu, 10 Oct 2024 08:30:11 +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 BL6PEPF00022575.mail.protection.outlook.com (10.167.249.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8048.13 via Frontend Transport; Thu, 10 Oct 2024 08:30:11 +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; Thu, 10 Oct 2024 03:30:05 -0500 From: K Prateek Nayak To: Peter Ziljstra , Ingo Molnar , Juri Lelli , Vincent Guittot , Johannes Weiner , "Suren Baghdasaryan" , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Thomas Gleixner , Klaus Kudielka , "Chris Bainbridge" , "Linux regression tracking (Thorsten Leemhuis)" , "Gautham R. Shenoy" , Youssef Esmat , "Paul Menzel" , Bert Karwatzki , , K Prateek Nayak Subject: [PATCH 3/3] sched/core: Indicate a sched_delayed task was migrated before wakeup Date: Thu, 10 Oct 2024 08:28:38 +0000 Message-ID: <20241010082838.2474-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010082838.2474-1-kprateek.nayak@amd.com> References: <20241010082838.2474-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: BL6PEPF00022575:EE_|CH2PR12MB4087:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e426f38-079d-45be-2a4a-08dce905c1e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?xXpb+KcPp4/Kr/fYldIf8WTNXc+5YlyUKEB8ldcvay0NZCHLy5tFK25NJIMZ?= =?us-ascii?Q?x3wgcESNkFnkSuf/pIXy6AsrNVp7x27euApKAt2O4oaere3GXlDy1jju5UFp?= =?us-ascii?Q?XEyM2DpzO8KtX75mR4r07EMDn2yybSVWz6XaX0sEkH3ETmIhMMTlVsoWhVsY?= =?us-ascii?Q?/Te4Mt9uTfuSxWal0tdiXdQb2vUsqp7nxKGqSI3YBIcyUQNX/Ci0UzqtLGL3?= =?us-ascii?Q?V67s5ls53b1YjdjogepRCLGUJBiVJ0SOKyuVcoXgGSS0MymoDNfRsWr7RAMd?= =?us-ascii?Q?jX6I2T6jWYBy0RN/WCN1jC+B/s19r36bgibqTHAtMcI4BzsbRlsHDFnVOIEL?= =?us-ascii?Q?+Q+kXzh0Uu4xOGHq3jz1wdxIcRXobiciLvtjbm5QfyyhEQILPRYoVjuNnngD?= =?us-ascii?Q?7y+DYl7/he66SKQXFLQSYtQnIYFX+AENuvKeVcbUXc/ZtmEg5Deqx/59TTrq?= =?us-ascii?Q?8iqJIy1mK/hQ9QR7Bxfr+u4O3ODMy3Z0lmernzaJ9HL1LUhtbv8eKXNNTjXs?= =?us-ascii?Q?6xVwmhHA/A9oSx4zQ6Ey62Nb0nYfa4FvbaScuYnL7TgWPf3j2Vurw+SOOJpN?= =?us-ascii?Q?vt5B24wI2SkQagf2dNsrq2D3bMeOE2sXe0Ovfb1WkdV4QCVVdP4QEzm1UJYm?= =?us-ascii?Q?mlve1ecpHghRbkyN5nOzI04H3vxLGyFRheVnQUk8bcpcrWuCL9GcvXwfHt3Z?= =?us-ascii?Q?hhoi6vfdKJzZpyEkf2lnwyFSilRuHGBMT3avZAaeHfoVPBo9LpryiH/6/are?= =?us-ascii?Q?bSJPfZuuvnkVjB/HyjYIRoepXpkAG0pL/9Vq/+1zi7sM8AHmALVCxNQXe+wX?= =?us-ascii?Q?X66cKxgkMRb/XVXjleaILC4JnY0xb1OHg3skWfpLpf2CegrPTHGqzkuxr8wM?= =?us-ascii?Q?9GU9dLQUf8ANJsFtejzh7DxTdCbVhiwJvOu7BQXC3hSVntbvUSp+Ysc+PLub?= =?us-ascii?Q?a4xOSXKN+pnsJUNBi7y5Ntd6p/IG2R5MK/OCiVvqBVCQ1waw4YxWxi+wQdBp?= =?us-ascii?Q?2lzSSRgaVjvMGu99tljwPINfM0sJ5C5x6HpFXe87RqSuCkHayspwkDQSbyUm?= =?us-ascii?Q?iH8TeT3ETaiyw3STribdJliui5UJj7qe1jcCrez2ZgUUgbyNtv8+P2I4u9PP?= =?us-ascii?Q?KRUCVzlYG1NXsynl55Pc9qPQpWMj4TtlhJuCT94+lnaJ0tCh/tyP7zj76bOw?= =?us-ascii?Q?BZpTXNTO8vxn34VKMD3pJJs2pFUbnlO4dub7XlxpdtKI7kn6UP7MsISsqpMt?= =?us-ascii?Q?pjS4nc0CwJbc+wzsPEYHk38gTbyxM3CcWOpLSapL8g7UJzGUV1QDydxK+zC5?= =?us-ascii?Q?9bNL3upmTwaEpMV2hpqaFZRz5I0BBKpljTD1lbRwbWiSeCawpkUtxGBVISWZ?= =?us-ascii?Q?zqZqnRthShskbnrHYaG3XZMHdjQg?= 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)(376014)(36860700013)(1800799024)(82310400026)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 08:30:11.6312 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9e426f38-079d-45be-2a4a-08dce905c1e8 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: BL6PEPF00022575.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4087 Content-Type: text/plain; charset="utf-8" Since sched_delayed tasks remain on "rq->cfs_tasks" list even after blocking, they can be migrated from one runqueue to another in a delayed state by the load balancer. When they are eventually requeued or woken up on the same CPU via the try_to_wake_up() path, the eventual activation is clueless about the migration. This trips the PSI accounting since, in terms of enqueue flags, PSI only considers the following as a wakeup for PSI accounting: (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED) This can lead inconsistent PSI task state splat similar to: psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D4 clear= =3D. set=3D4 # Without partial fixup from this patch psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D0 clear= =3D4 set=3D1 # With partial fixup from this patch Tracking the PSI changes along with task's state revealed the following series of events: psi_task_switch: psi_flags=3D4 clear=3D4 set=3D1 # sched_delayed is set= to 1 psi_dequeue: psi_flags=3D1 clear=3D1 set=3D0 # dequeued for migrati= on psi_enqueue: psi_flags=3D0 clear=3D0 set=3D4 # enqueued after migra= tion psi_enqueue: psi_flags=3D4 clear=3D1 set=3D4 # wakeup after migrati= on psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D4 clear= =3D1 set=3D4 Moving psi_enqueue() to after "p->sched_class->enqueue_task()" and skipping enqueue until the delayed task is actually woken up (referred to partial fixup previously) changes the above scenario to the following: psi_task_switch: psi_flags=3D4 clear=3D4 set=3D1 # sched_delayed is set= to 1 psi_dequeue: psi_flags=3D1 clear=3D1 set=3D0 # dequeued for migrati= on psi_enqueue: psi_flags=3D0 clear=3D0 set=3D0 # enqueued after migra= tion, sched delayed psi_enqueue: psi_flags=3D0 clear=3D1 set=3D4 # wakeup of delayed ta= sk psi: inconsistent task state! task=3D... cpu=3D... psi_flags=3D0 clear= =3D1 set=3D4 psi_enqueue() tries to clear the TSK_IOWAIT since it believes the task has not migrated due to the lack of ENQUEUE_MIGRATED flag in case of a requeue or a full wakeup on "p->wake_cpu", but in-fact TSK_IOWAIT was cleared during dequeue for migration and was never set again. Define "DELAYED_MIGRATED" and set it in "p->migration_flags" when a delayed task is migrated. This flag is consumed when the delayed entity is finally woken up, and psi_enqueue() is notified of the migration. Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue") Closes: https://lore.kernel.org/lkml/20240830123458.3557-1-spasswolf@web.de/ Closes: https://lore.kernel.org/all/cd67fbcd-d659-4822-bb90-7e8fbb40a856@mo= lgen.mpg.de/ Link: https://lore.kernel.org/lkml/f82def74-a64a-4a05-c8d4-4eeb3e03d0c0@amd= .com/ Tested-by: Johannes Weiner Signed-off-by: K Prateek Nayak Suggested-by: Peter Zijlstra Tested-by: K Prateek Nayak --- kernel/sched/core.c | 19 ++++++++++++++++++- kernel/sched/sched.h | 1 + kernel/sched/stats.h | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 52be38021ebb..1a353fa69a54 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2009,12 +2009,19 @@ unsigned long get_wchan(struct task_struct *p) =20 void enqueue_task(struct rq *rq, struct task_struct *p, int flags) { + bool wakee_not_migrated =3D (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE= _MIGRATED); + if (!(flags & ENQUEUE_NOCLOCK)) update_rq_clock(rq); =20 if (!(flags & ENQUEUE_RESTORE)) { sched_info_enqueue(rq, p); - psi_enqueue(p, (flags & ENQUEUE_WAKEUP) && !(flags & ENQUEUE_MIGRATED)); + + /* Notify PSI that the task was migrated in a delayed state before wakeu= p. */ + if ((p->migration_flags & DELAYED_MIGRATED) && !task_on_rq_migrating(p))= { + wakee_not_migrated =3D false; + p->migration_flags &=3D ~DELAYED_MIGRATED; + } } =20 p->sched_class->enqueue_task(rq, p, flags); @@ -2023,6 +2030,8 @@ void enqueue_task(struct rq *rq, struct task_struct *= p, int flags) * ->sched_delayed. */ uclamp_rq_inc(rq, p); + if (!(flags & ENQUEUE_RESTORE)) + psi_enqueue(p, wakee_not_migrated); =20 if (sched_core_enabled(rq)) sched_core_enqueue(rq, p); @@ -2042,6 +2051,14 @@ inline bool dequeue_task(struct rq *rq, struct task_= struct *p, int flags) if (!(flags & DEQUEUE_SAVE)) { sched_info_dequeue(rq, p); psi_dequeue(p, flags & DEQUEUE_SLEEP); + + /* + * Indicate that a sched_delayed task was migrated. + * enqueue_task() needs this for correct accounting + * when the delayed task eventually wakes up. + */ + if (p->se.sched_delayed && task_on_rq_migrating(p)) + p->migration_flags |=3D DELAYED_MIGRATED; } =20 /* diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index b1c3588a8f00..2dc2c4cb4f5f 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1326,6 +1326,7 @@ static inline int cpu_of(struct rq *rq) } =20 #define MDF_PUSH 0x01 +#define DELAYED_MIGRATED 0x02 /* Task was migrated when in DELAYED_DEQUEUE= state */ =20 static inline bool is_migration_disabled(struct task_struct *p) { diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h index 237780aa3c53..06a2c6d3ec1e 100644 --- a/kernel/sched/stats.h +++ b/kernel/sched/stats.h @@ -129,6 +129,13 @@ static inline void psi_enqueue(struct task_struct *p, = bool wakeup) if (static_branch_likely(&psi_disabled)) return; =20 + /* + * Delayed task is not ready to run yet! + * Wait for a requeue before accounting. + */ + if (p->se.sched_delayed) + return; + if (p->in_memstall) set |=3D TSK_MEMSTALL_RUNNING; =20 @@ -148,6 +155,9 @@ static inline void psi_dequeue(struct task_struct *p, b= ool sleep) if (static_branch_likely(&psi_disabled)) return; =20 + /* Delayed task can only be dequeued for migration. */ + WARN_ON_ONCE(p->se.sched_delayed && sleep); + /* * A voluntary sleep is a dequeue followed by a task switch. To * avoid walking all ancestors twice, psi_task_switch() handles --=20 2.34.1