From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013064.outbound.protection.outlook.com [40.107.201.64]) (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 607B429D29F for ; Fri, 3 Jul 2026 03:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.64 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783048027; cv=fail; b=ed+qwIxmckl7hMWlGKjubNXt1EbQJZCy0IIL9KWDYdzHeNyi98qMlFVXOtWbiQPxEywRAk1sGg1vMqpRGqkxU11QdjuC0hGhGnSoTO1P2z9lUgT1EGWg0XSMuDUWdf/teXwQpBgsw0AE6yCKDVDdEfWHdSD9Q6zCzpXSg+EP8V4= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783048027; c=relaxed/simple; bh=X5F1N0rxNJgrnPsiebAMIt7hyHJpjp8uosoyENWnceE=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=t0wQALgE8Qcsk0thCq10qUo0VIi8y1jbiKjwRcwU7HjeNvLraJ1+cvNraAVGv1aSNPfPrsOxnyVc0eH+8oA+iAC1ihaA+dKsRLvM+ldLHfKVQgCU0ZIzN37oaGfO9CACEirCmRylWvFCj2IqE58t+Jte9GRcRNnHoK3Ei0XcUCI= 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=ZGW+4c5F; arc=fail smtp.client-ip=40.107.201.64 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="ZGW+4c5F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pIE8yhL4hxyAZ9RgHOB5uT6gZsNztrKeSg+n/DfpQL5VqqmUjdBkzwRy+IscVMIVuGf0OfqgKXBktZzIlWWrHpoTUgvZVyhXPNwGYrt782czULhGupdYME/XXs2wjHtQ40W3ez8U1YBi0pndLdgvCYMyKxJ2FB0lu8J9RfNFksdohXlI0HJNdj1eOcUp8JaButnSuUDH3ODgeVeiPoscz9gieS5RknyGT/VHnauYa2d3QdV4J0j0cQrx7Na+tm3ksqsjLTPIJjHwDUQXRxO5/GV3jJn9njZuPRQb857R6P5ghJpA/fyix1IvnTOGPhvxj8z+XoIi/gfsjAVN36roMg== 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=9+4SI5WNr7bmT4sevSwOSrLoX7IWiwLWcyUQlUh969w=; b=GK6dFMx3MOJXZv/1stLl5ayQM5xL08QKffmCD/gc9jA4JvG1ruAgUEnkWsvRihByhZQZbvfMJbn+/OgcbQ7MgQ39TRXteDakQYtN1FaCacJSdlFuiemdg7pUF2k0pRIH8WpJMBijrsgnHDB+JiMFOqEkcUOXKB4ibLbuFmdic04CCo/R/WyAfNzBe2JGppfEkJnr+qWv9GwvEJdkLScV5A+6snhBpYT8Xss2IOI+oWzxtI7bTmaXUhQQ2rC/vEZZPxn7Ug0h/YwlRpPq7VriJvARIE/sXCkHiEqBJnTLDolQSvBRG//bDDO6u0IuPF90271lmcFPeP2ohs17yGF3fA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.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=9+4SI5WNr7bmT4sevSwOSrLoX7IWiwLWcyUQlUh969w=; b=ZGW+4c5Fv5PfPT3uxKG/rgQCXFSvmzBmlhP4QTyp7Zc84nJzvAfmDjyNhhuo3zIbR0zXTMlSFKnvRJBzWRb6w+CKglT/mW4fNa8ZxerdKCIWvZrvuxCdM6AULqeH0NfET9nb2nibif6GiLZEIO5v4sFestZyzuaLEkOkiGToPHY= Received: from SJ0PR13CA0117.namprd13.prod.outlook.com (2603:10b6:a03:2c5::32) by PH7PR12MB7164.namprd12.prod.outlook.com (2603:10b6:510:203::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.8; Fri, 3 Jul 2026 03:06:57 +0000 Received: from BY1PEPF0001AE19.namprd04.prod.outlook.com (2603:10b6:a03:2c5:cafe::a5) by SJ0PR13CA0117.outlook.office365.com (2603:10b6:a03:2c5::32) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.202.4 via Frontend Transport; Fri, 3 Jul 2026 03:06:57 +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 BY1PEPF0001AE19.mail.protection.outlook.com (10.167.242.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.181.6 via Frontend Transport; Fri, 3 Jul 2026 03:06:57 +0000 Received: from satlexmb10.amd.com (10.181.42.219) 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.41; Thu, 2 Jul 2026 22:06:56 -0500 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Thu, 2 Jul 2026 22:06:56 -0500 Received: from [10.85.47.78] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.41 via Frontend Transport; Thu, 2 Jul 2026 22:06:49 -0500 Message-ID: <2d96999e-961b-4a10-b4ea-a8480baea2a3@amd.com> Date: Fri, 3 Jul 2026 08:36:48 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v30 7/7] sched: Add deactivated (sleeping) owner handling to find_proxy_task() To: John Stultz , LKML CC: Peter Zijlstra , Juri Lelli , Valentin Schneider , Connor O'Brien , Joel Fernandes , Qais Yousef , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Valentin Schneider , Steven Rostedt , Ben Segall , Zimuzo Ezeozue , Mel Gorman , Will Deacon , Waiman Long , Boqun Feng , "Paul E. McKenney" , Metin Kaya , Xuewen Yan , Thomas Gleixner , Daniel Lezcano , "Suleiman Souhlal" , kuyo chang , hupu , Vasily Gorbik , References: <20260701214615.3773339-1-jstultz@google.com> <20260701214615.3773339-8-jstultz@google.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: <20260701214615.3773339-8-jstultz@google.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY1PEPF0001AE19:EE_|PH7PR12MB7164:EE_ X-MS-Office365-Filtering-Correlation-Id: b79fdef8-487a-4352-6713-08ded8b024be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|7416014|82310400026|1800799024|30052699003|376014|56012099006|11063799006|4143699003|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: x+Oby/NE/gyqpf2qPxg1FuyGMezKQcEKFYMMdeq0v4X0DN+srM1/uGRD0f0X4Aae4TdTdG0yxNGbbyBKg4xE5cpXdGOsnZa1U6Yudyao2AqULdm7BSHaeUD9JaBP1ZlvLcTPbevWwgfMCPK6S7O3OO4GZO2Ep5pGsYQVbwGkHqm41+69gLEg8xbitIQj3LAlB1tRg9XAYt4IMd82tnabXxuhS0RhocU5/SW5KqAWv+Pe85NP5OaVyX63aV20m+0Xgd43scrlNw0rCsMyLMTXMP3PwbljpyDkEcKKpZjM3Y+nrZPpmvdLUghmlcT9vvw9uGqiriOTPOa1cgCDnTwEEG+SoClKia1NMgouVE099xJG00EpVyPKMy6e8nJ2NCo8MFXPCwQwNZf99wHhM4b9P92bL6oZbpaTdex5eXrx8p22XtzoCz8b2uSAPY/MsP2obf3IE/RcbEnH3CawNekzvNWUVjXxTf2JGYiZSitFPgV6ZV4vnWqqGoBVyOsoVxIKYMm7N+rq774/eqY9VRtw6w6HdKNa+xdYmiFUEv2EgX2h6Wm66xYQf8Xz+jR2SeJcZYNi+ZLeF1sIsPoC+eR3vWN/uHdvsolHOFH0hNbfteGfOe4cavHPz4Aco/mlfNhQlCWEcZFinUY/cL/Y2QnGtPmoGPecZfZ+SzvjbKBAyb1mfNMgi8piAzClTiHqvvdA/AKIGzVek8KvJz3rLjZm0g== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(7416014)(82310400026)(1800799024)(30052699003)(376014)(56012099006)(11063799006)(4143699003)(18002099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tPBBFYuJaMGfsrZSkDQW/pM9cqGB5DVluzxYqKo0xU9eAHaskz5TyeCODZCotKsFfp7SXdhkw2qaY336dXxsZzm6fI3UxtP+omPuB0aIYBLGF4KVa3gMEJnC++Gl3j9GW44dZ6bsxn3Ikx5jq9u8Ru69bf38MIoeL5lxFFjFgGb5KAp/iTG/TfNrml0t0dnmxXm2WtB6/NSTDRubxaaBfdm0lb4Kai6/s4N5awJc1ZqoSh/u9w/qaL6/JKKFClTauNVZAd8KJrJ3lFW4H9yvaVhoNHfgWewyPPD+Q9aROzjmfmGy+BXSkMqznzv1sBpPAYcbzZKpNmP7Lhy+IOlIh1Q1B7UddotPgfmGLFomD55VFZ4LNuaZ9vEzwuw3eaPnZWPlZUA8rtg3Eu2ygq/xrgwLEeUSds0ZWkb5CsnUO8MhIDuRXXIKxf5hPNvvMvsx X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2026 03:06:57.4227 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b79fdef8-487a-4352-6713-08ded8b024be 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: BY1PEPF0001AE19.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7164 Hello John, On 7/2/2026 3:16 AM, John Stultz wrote: > @@ -6852,6 +7073,28 @@ static void proxy_migrate_task(struct rq *rq, struct rq_flags *rf, > proxy_reacquire_rq_lock(rq, rf); > } > > +static void proxy_enqueue_on_owner(struct rq *rq, struct task_struct *owner, > + struct task_struct *p) > +{ > + lockdep_assert_rq_held(rq); > + lockdep_assert_held(&owner->blocked_lock); > + /* > + * ttwu_activate() will pick them up and place them on whatever rq > + * @owner will run next. > + */ > + WARN_ON(p == owner); > + WARN_ON(!p->on_rq); > + WARN_ON(p->sleeping_owner); > + get_task_struct(owner); > + WRITE_ONCE(p->sleeping_owner, owner); > + /* > + * ttwu_do_activate must not have a chance to activate p > + * elsewhere before it's fully extricated from its old rq. > + */ > + list_add(&p->blocked_node, &owner->blocked_head); I'll refer to this list_add() as (1) below ... > + block_task(rq, p, READ_ONCE(p->__state)); > +} > + > /* > * Find runnable lock owner to proxy for mutex blocked donor > * > @@ -6938,11 +7181,31 @@ find_proxy_task(struct rq *rq, struct task_struct *donor, struct rq_flags *rf) > } > > if (!READ_ONCE(owner->on_rq) || owner->se.sched_delayed) { I'm having a sneaky feeling that, with enough bad luck, we can go from seeing !owner->on_rq and here to actually finish enqueuing the owner by the time we get to (1) ... > - /* XXX Don't handle blocked owners/delayed dequeue yet */ > + /* > + * rq->curr must not be added to the blocked_head list or else > + * ttwu_do_activate could enqueue it elsewhere before it switches > + * out here. The approach to avoid this is the same as in the > + * migrate_task case. > + */ > if (curr_in_chain) > return proxy_resched_idle(rq); > - __clear_task_blocked_on(p, NULL); > - goto deactivate; > + /* > + * If !@owner->on_rq, holding @rq->lock will not pin the task, > + * so we cannot drop @mutex->wait_lock until we're sure its a blocked > + * task on this rq. > + * > + * We use @owner->blocked_lock to serialize against ttwu_activate(). > + * Either we see its new owner->on_rq or it will see our list_add(). > + */ > + WARN_ON(owner == p); > + raw_spin_unlock(&p->blocked_lock); > + raw_spin_lock(&owner->blocked_lock); ... by the time we get here, activate_blocked_waiters() could have already bailed out for: !list_empty(&owner->blocked_activation_node) and then we go and add the task to list. I feel, like most conditionally adding to list patterns, we should add the task to list, check the condition once again under owner->blocked_lock, and then proceed. That way we can sure the activate will definitely see the queued task. Sorry in advance in case I've been blind and missed something obvious :-) On a separate note, is it worth tracking if the task is a mutex / lock owner and only go through the activate_blocked_waiters() path only when a __mutex_owner() somewhere can return the task being activated? Perhaps a per-task counter that increments at every mutex_lock() and decrements at a mutex_unlock()? > + proxy_resched_idle(rq); > + proxy_enqueue_on_owner(rq, owner, p); > + raw_spin_unlock(&owner->blocked_lock); > + raw_spin_lock(&p->blocked_lock); > + > + return NULL; /* retry task selection */ > } > > owner_cpu = task_cpu(owner); -- Thanks and Regards, Prateek