From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012062.outbound.protection.outlook.com [52.101.53.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 B2D6E302CD1 for ; Mon, 17 Nov 2025 18:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.53.62 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405779; cv=fail; b=EB2KJ4jin1W/igttgiisBx1P9EhllwvW4tr+ZP/vsEZfqlAimIQkOcoHz5ha/rHTjCfc2wVeQdcicVwIfGOjIU6aUv6KpvjzZV2jGhFOSs4oqKWwsDp1Zr+1JlYN+TRj/cH49wWKa7iCO4ccXsSUlYL5kVzOpt9gqNLMDn65kDE= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405779; c=relaxed/simple; bh=PR1pIf6bVj6de4uMJ3SHEYBQ2RTbdw/FnjbW4wLzccU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=azIL8WfMUfgBY/f9+PKOzJhuoLVmDzCZXboKVi6Nmk8d3oTM6bmcIH/5hZztOwz8ULZn6k3PJXESsRhudILRPtUXX0YbkQZeu/+DLmUoxGsGocY+u223WRBK0r4fdqLqR8lu1zqFOjJyLNPD/USaKTV4hFbe7DQ5t9EWjAQK7cE= 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=ip6oLcIj; arc=fail smtp.client-ip=52.101.53.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="ip6oLcIj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zFn2ywMnE0LRPS57ADmPQgXyXTzj/6Ne51dlCI7gh8HnEdzOjllQFj5vWM+uBEeCBAN9OlP/W0eSOeUDqdOq+d+gDdhfnaXqUFXzUrmYoEQdyK0wm0XSycU5A5XhapQ3HCfkr8mN+iFtPhvuCgBiTTErzaYdh7Fq78L2axjgHhcI1EjKtaywmPMPVo3t5AQxmcJ9kiiLquPZuuftgbleZmfyg48OHQxNpYtqYPHgEu2gelCgp273MlUZrFgUqG47BTPIr1EVZgSSk54eePYMhDZ/QF0IDyS/Tr0jyAym6p4unZ2/pD5UyuSD08vkbYN14vZglk3V41ltG3CKZ63hRg== 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=/4Zgo6eyAXbgoXIKXZCO8iWTLJeO0LGItVXukeYAKbo=; b=KBtfuZzue0gzM5hwUEthcKKNXFaBgwdlv8sPXsNEfJoMdkvyFbmKNaH6GMSDcbpARXGUqGQnxaaJ9FnivDFRF1p4xbwh1b8Ssv03iyauwWHt/LEFzpDhCdegcaMKSsBpjdnBbIqqdkpjeJ99dIU9oY0RfVbUK+r41PB2itX1PBTjVfVZaTS5x15jbcz61i97FjOh+WbDxPqlyj1+unDjmSOvsxRti/G3CnMPSpERSBT1p9kYseesdj8cc86BMnbCu+AhtKzw7A05unf+u4wA98+P4QjY3gUKKb7qPJevYJwGTbFsV3gVPnTWgxzES1eWtZL0jGFmLGtr2i15ipYIyw== 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=/4Zgo6eyAXbgoXIKXZCO8iWTLJeO0LGItVXukeYAKbo=; b=ip6oLcIjWLJA7zy8pUhQgolqfQCgbJWUzQ8s2IdqyOo55wsJxbWzYTYSbdF8eOc6sWPMWgePIWH3TeTiz1pqHyvL5dbfj4R8mPbYgvhS9njLfMtqlxobEEtej0Fni4tO/4rVk6TDmVqYYghww2sdfes8Mn0wA0Nzn/g4FgK5uRs= Received: from SA1P222CA0173.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::16) by DS7PR12MB8251.namprd12.prod.outlook.com (2603:10b6:8:e3::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.18; Mon, 17 Nov 2025 18:56:11 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:806:3c3:cafe::7c) by SA1P222CA0173.outlook.office365.com (2603:10b6:806:3c3::16) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9320.22 via Frontend Transport; Mon, 17 Nov 2025 18:56:12 +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 SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9343.9 via Frontend Transport; Mon, 17 Nov 2025 18:56:10 +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, 17 Nov 2025 10:56:06 -0800 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , John Stultz , "Johannes Weiner" , Suren Baghdasaryan , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak Subject: [RFC PATCH 0/5] sched/psi: Fix PSI accounting with proxy execution Date: Mon, 17 Nov 2025 18:55:45 +0000 Message-ID: <20251117185550.365156-1-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: SA2PEPF000015CA:EE_|DS7PR12MB8251:EE_ X-MS-Office365-Filtering-Correlation-Id: 03fc9c69-c400-40bf-45aa-08de260af933 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700013|376014|7416014|13003099007; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?gMAikiyYvr1rtUn1Zvi8dIN7Wz5dr0U1xuINrcoJCcI7nzlXxr417EEBTmQp?= =?us-ascii?Q?R7N9Vu96hHtCZKnEGjMy3KaM6O1FGNtOfuI1APmFxEGYXPWxEZwD7kWlCCPy?= =?us-ascii?Q?f3wCGnEzz3emXjNqSSH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DG5jBsW/ga4wyHx9EfugxSjxiETN86xgFWXpA3gkgArenzjLB924Bs0?= =?us-ascii?Q?Tm0peFhEAeinHEBiKmUTFYPxtFsuN1RZ8FBhiqJA1sNIOG21jfNKkIEKT3vW?= =?us-ascii?Q?8DIfDFgJopyuNfQFX07CvXhB4taIkmOxdg1WZhB0+00GzmkfBm7YGRts6Y2D?= =?us-ascii?Q?9DOXavbgXyI4gkuzSXE43E7AeZ3gSCQFYqQjRUydYvdK0QQ9LtUgHteRaC2Y?= =?us-ascii?Q?mxdHudUho+KL51t3MMK1I1ClptPXupQtf1cJy3EQ6s/W/AEGgTnN2eIuGnCX?= =?us-ascii?Q?NkAbrj6O6jdYzLGMWLcpODWpFkw4tFfb33azcVNTd9Ky+wY6aGWH2ULNe6pR?= =?us-ascii?Q?pkSnANLtvOj3lTnEgIEM/wz8ByKKZV+U0cSzFaog4pV5XRkR2VqF2PxNObVM?= =?us-ascii?Q?0e/w9R8OtaVND/ZYYst2ld3P3OOXIx8iViEZNZ12VeyTXk8QIYvw2QxIfwf4?= =?us-ascii?Q?F7APNVQ/YCCAsFgJA6ZKUwB40IXCq6c6DDTg?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014)(7416014)(13003099007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2025 18:56:10.4951 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 03fc9c69-c400-40bf-45aa-08de260af933 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8251 When booting into a kernel with CONFIG_SCHED_PROXY_EXEC and CONFIG_PSI, a inconsistent task state warning was noticed soon after the boot similar to: psi: inconsistent task state! task=... cpu=... psi_flags=4 clear=0 set=4 On analysis, the following sequence of event was found to be the cause of the splat: o Blocked task is retained on the runqueue. o psi_sched_switch() sees task_on_rq_queued() and retains the runnable signals for the task. o Tasks blocks later via proxy_deactivate() but psi_dequeue() doesn't adjust the PSI flags since DEQUEUE_SLEEP is set expecting psi_sched_switch() to fix the signals. o The blocked task is woken up with the PSI state still reflecting that the task is runnable (TSK_RUNNING) leading to the splat. Simply tracking proxy_deactivate() is not enough since the task's blocked_on relationship can be cleared remotely without acquiring the runqueue lock which can force a blocked task to run before a wakeup - pick_next_task() pickes the blocked donor and since blocked on relationship was cleared remotely, task_is_blocked() returns false leading to the task being run on the CPU. If the task blocks again before it is woken up, psi_sched_switch() will try to clear the runnable signals (TSK_RUNNING) unconditionally leading to a different splat similar to: psi: inconsistent task state! task=... cpu=... psi_flags=10 clear=14 set=0 To get around this, track the complete lifecycle of a blocked doner right from delaying the deactivation to the wakeup. When in blocked/donor state, PSI will consider these tasks similar to delayed tasks - blocked but migratable. When the ttwu_runnable() finally wakeups up the task, or if the donor is deactivated via proxy_deactivate(), the proxy indicator is cleared to show that the task is either fully blocked or fully runnable now. Patch 1 and 2 were cleanups to make life slightly easier when auditing the implementation and inspecting the debug logs. Patch 3 to 5 implement the tracking of donor states and a couple of fixes on top. Series was tested on top of tip:sched/core for a while running sched-messaging without observing any inconsistent task state warning and should apply cleanly on top of: git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git sched/core at commit 33cf66d88306 ("sched/fair: Proportional newidle balance"). --- K Prateek Nayak (5): sched/psi: Make psi stubs consistent for !CONFIG_PSI sched/psi: Prepend "0x" to format specifiers when printing PSI flags sched/core: Track blocked tasks retained on rq for proxy sched/core: Block proxy task on pick when blocked_on is cleared before wakeup sched/psi: Fix PSI signals of blocked tasks retained for proxy include/linux/sched.h | 4 +++ kernel/sched/core.c | 59 +++++++++++++++++++++++++++++++++++++++++-- kernel/sched/psi.c | 4 +-- kernel/sched/sched.h | 2 ++ kernel/sched/stats.h | 6 ++--- 5 files changed, 68 insertions(+), 7 deletions(-) base-commit: 33cf66d88306663d16e4759e9d24766b0aaa2e17 -- 2.34.1