From nobody Tue Dec 2 03:00:13 2025 Received: from SJ2PR03CU001.outbound.protection.outlook.com (mail-westusazon11012000.outbound.protection.outlook.com [52.101.43.0]) (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 389E2338F2F for ; Mon, 17 Nov 2025 18:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.43.0 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405830; cv=fail; b=Lq3jVwC/2bJjtVNszv6q9/r9lhkdR60/jxM+1yqmQHDdn1yCeS5XJGOV+mOS6iCMNV7SQUw7qKgEdVQxbMC1WVw0C32p7VWrPw4/XWu8lQsfTftEC2Qfwxw9b1nYEL2cQtuYMchZrOFco06U89JWe7nEIjEA0rTjyOrWWbwTQjs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763405830; c=relaxed/simple; bh=9mUQ9hO7vC81J+ALdSlKa1y6M1KX0DXaTrWqYdzm5qE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W0eNIe2XP9T6WatvXuCdmsjWKpmO3dRJv75XsQptmkSu/SaRqDSOOSDI2a28eZljO01gpTb8KnXzuQqJ23QN1gIOX72wqiTxfV3/brOLQWVWDmMJ4VsHGVr5r6Z1Af9CR+iQjN1LQ9phJcDj0frkC9xF2F1Vc/Ct2lgnz5xrXLw= 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=OsXC+WEn; arc=fail smtp.client-ip=52.101.43.0 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="OsXC+WEn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=URwr7cAue4cpXJmtpWnqgouJMtIa10myqWJbL2BBNtHYs1w9Oty3psTiL16GwTu8g9lCUoTqRW1AMo49HP3ukleQq6mOVaCplxHXIVwIyce2E/7+FuwZrz2t3GENCRIAyHfvkdmqs7OAMQ9O6Xh2LsJK04laUNBvp2QB20TasxBmIOZyIn874JgaWlAocIvmCM8R6nVcECpIthSW3V76jbdwsnWbMnQpMR0jeAQXAALFa+igSIkrbL1ZKQR9PHOZqzcRo7maGtO4z9OPTVmwOlbY8Tns94uXmc0/BNomH0F6nl64VC3+qp0azVBB8D+OBZkCUhV41FREpIi4FkgdHA== 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=10+y+kmbWzK4VCT+QLfTkyLJREuZ/fzyn1aogyiQXeM=; b=Ja9LoqAPQt+VCGOwDq/1aIJhtlRpCJCQg7unjrdL3OOPzbrsLe9j69vGhufbRJuKHe/ffbfKNFvvfrxkcNOKMjs59l+ARPbWzpljpM5K6RuJBhf0QL0tkjqXsZlAMkkapatDtCcgU5w5KGMX4shblCsFGJU5W5r9CNANpGJTXHrSZAUOsXlCpebE8o1nsjx29IpozaSjJjqJX7gHiWJsF3eYYI3D/bNAWG0gJedXQhBcTBJ7YQkWidgCKj5a5uMZyPYe7A/RheG8LbZ2VK17k+HDEH4L5qC9zUNjVu1fLYY9ncmS5ox4MnIIZwEYpFvXgjErTCM9m+Y+zm7soq9iag== 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=10+y+kmbWzK4VCT+QLfTkyLJREuZ/fzyn1aogyiQXeM=; b=OsXC+WEnxL4/TIr0iEXPMVaeTmNksNo+/9dHqDFw051QY1a/ox14g5uCF0eFuAQODYJHFR14KfOlK0AC2axNmsEYBj174fgtB9A7Wmw+2X4fc9NgyOs7XAZ0yB5goPoay4pqpwlosLn5E0aHlxfU6vXr9I1xyDG+SJGLxWiQTQs= Received: from BYAPR08CA0068.namprd08.prod.outlook.com (2603:10b6:a03:117::45) by SA1PR12MB6917.namprd12.prod.outlook.com (2603:10b6:806:24c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.22; Mon, 17 Nov 2025 18:57:03 +0000 Received: from CO1PEPF000066E8.namprd05.prod.outlook.com (2603:10b6:a03:117:cafe::f2) by BYAPR08CA0068.outlook.office365.com (2603:10b6:a03:117::45) 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:57:03 +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 CO1PEPF000066E8.mail.protection.outlook.com (10.167.249.6) 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:57:02 +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:57 -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 3/5] sched/core: Track blocked tasks retained on rq for proxy Date: Mon, 17 Nov 2025 18:55:48 +0000 Message-ID: <20251117185550.365156-4-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251117185550.365156-1-kprateek.nayak@amd.com> References: <20251117185550.365156-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: CO1PEPF000066E8:EE_|SA1PR12MB6917:EE_ X-MS-Office365-Filtering-Correlation-Id: ec8f8767-2d86-4fed-fde4-08de260b1842 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Usx7EAQImtycs9aPHh2tjauVmlhoPmNTmRlPq0fFCLirSunW67kggsHxaV5Q?= =?us-ascii?Q?ItNDBellGwGG4lKT3A7j9MWg8Ea31wYrqe9hHVWDGUOLtkN3JG/Kho4R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m1oyVMHuYR22KhZnddfzyDXLTGfZ4Md/VRuTlnBZ9adwhHA?= =?us-ascii?Q?OCZZYC1zLo+bAy3o0gWxjfPiGmEoAFzzrj/+eJaQmnaL5xIbLgQNTnH5n+MF?= =?us-ascii?Q?ririPV0iSV8TbJfCpiaCTN55uWCkWRYqZn+UmHTJJmGnB5+dcGgSX7qhmAdK?= =?us-ascii?Q?HDWQDOZtG2f77eLhV5jWJWvRNoKLI07dMKC78cLNHsTBnAm+jJPBITnMsgzy?= =?us-ascii?Q?W3IgTLK6sTPHsWXPmWoUQPk+Cc73EpXxPezKkZT5areS9iGxjXXIYKtWlWk8?= =?us-ascii?Q?UxPtgxswYDUgq3Pei8/NfAcaLRqGvUH7qgcAH2fCbezNOaZZ5xs4mppCaBo7?= =?us-ascii?Q?ZUZ1rTt8z3v+UN7A3SY3gQ/t0lEYnHjdjH+wJIYGbs5KY1C0HhSsqv6kfY5d?= =?us-ascii?Q?8aaTVsYJzv41v7+YFYEirzodjWC2VY+s7ZZ6UhXgVldVrw3rarIjCv4QNwRC?= =?us-ascii?Q?3q0HRZME+DP9qin7pOLbX+VduRS8o2I+tLorCls9rSH4ODtxp3Ab0aMkBIPp?= =?us-ascii?Q?Tij/Gon4XgTx4SdnQ5dPdqAlDUd3CHJAy3sEi3lGFZ8Ye9VgaWWLPkpMdPtk?= =?us-ascii?Q?Ll2cYb5CD0Yw2fKPFA4=3D?= 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)(376014)(7416014)(82310400026)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2025 18:57:02.5936 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ec8f8767-2d86-4fed-fde4-08de260b1842 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: CO1PEPF000066E8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6917 Content-Type: text/plain; charset="utf-8" Track blocked task retained on runqueue to act as a proxy donor. This is necessary since task's "blocked_on" relationship can be cleared without holding the task_rq lock and a blocked donor can be forced to run on CPU before a wakeup since task_is_blocked() returns false at the time of pick. This is necessary for to fix a PSI task state corruption observed with CONFIG_SCHED_PROXY_EXEC=3Dy but it also serves as a medium to track the lifecycle of proxy donor when it is retained on the rq for proxy. Signed-off-by: K Prateek Nayak --- include/linux/sched.h | 4 ++++ kernel/sched/core.c | 32 +++++++++++++++++++++++++++++++- kernel/sched/sched.h | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index bb436ee1942d..f96ad1ec680b 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -978,6 +978,10 @@ struct task_struct { unsigned sched_contributes_to_load:1; unsigned sched_migrated:1; unsigned sched_task_hot:1; +#ifdef CONFIG_SCHED_PROXY_EXEC + /* To indicate blocked task was retained on the rq for proxy. */ + unsigned sched_proxy:1; +#endif =20 /* Force alignment to the next boundary: */ unsigned :0; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9f10cfbdc228..52a744beeca9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3659,6 +3659,9 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p= , int wake_flags, } } =20 +static inline void set_task_proxy(struct task_struct *p); +static inline void clear_task_proxy(struct task_struct *p); + /* * Consider @p being inside a wait loop: * @@ -3693,6 +3696,8 @@ static int ttwu_runnable(struct task_struct *p, int w= ake_flags) rq =3D __task_rq_lock(p, &rf); if (task_on_rq_queued(p)) { update_rq_clock(rq); + if (is_proxy_task(p)) + clear_task_proxy(p); if (p->se.sched_delayed) enqueue_task(rq, p, ENQUEUE_NOCLOCK | ENQUEUE_DELAYED); if (!task_on_cpu(rq, p)) { @@ -6460,8 +6465,10 @@ static bool try_to_block_task(struct rq *rq, struct = task_struct *p, * blocked on a mutex, and we want to keep it on the runqueue * to be selectable for proxy-execution. */ - if (!should_block) + if (!should_block) { + set_task_proxy(p); return false; + } =20 p->sched_contributes_to_load =3D (task_state & TASK_UNINTERRUPTIBLE) && @@ -6487,6 +6494,23 @@ static bool try_to_block_task(struct rq *rq, struct = task_struct *p, } =20 #ifdef CONFIG_SCHED_PROXY_EXEC +bool is_proxy_task(struct task_struct *p) +{ + return !!p->sched_proxy; +} + +static inline void set_task_proxy(struct task_struct *p) +{ + WARN_ON_ONCE(p->sched_proxy); + p->sched_proxy =3D 1; +} + +static inline void clear_task_proxy(struct task_struct *p) +{ + WARN_ON_ONCE(!p->sched_proxy); + p->sched_proxy =3D 0; +} + static inline struct task_struct *proxy_resched_idle(struct rq *rq) { put_prev_set_next_task(rq, rq->donor, rq->idle); @@ -6502,6 +6526,9 @@ static bool __proxy_deactivate(struct rq *rq, struct = task_struct *donor) /* Don't deactivate if the state has been changed to TASK_RUNNING */ if (state =3D=3D TASK_RUNNING) return false; + + clear_task_proxy(donor); + /* * Because we got donor from pick_next_task(), it is *crucial* * that we call proxy_resched_idle() before we deactivate it. @@ -6649,6 +6676,9 @@ find_proxy_task(struct rq *rq, struct task_struct *do= nor, struct rq_flags *rf) return owner; } #else /* SCHED_PROXY_EXEC */ +bool is_proxy_task(struct task_struct *p) { return false; } +static inline void set_task_proxy(struct task_struct *p) { } +static inline void clear_task_proxy(p) { } static struct task_struct * find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags = *rf) { diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index b419a4d98461..fa2a2d5bff6d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1362,6 +1362,8 @@ static inline u32 sched_rng(void) #define cpu_curr(cpu) (cpu_rq(cpu)->curr) #define raw_rq() raw_cpu_ptr(&runqueues) =20 +bool is_proxy_task(struct task_struct *p); + #ifdef CONFIG_SCHED_PROXY_EXEC static inline void rq_set_donor(struct rq *rq, struct task_struct *t) { --=20 2.34.1