From nobody Sun Feb 8 05:47:49 2026 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2062.outbound.protection.outlook.com [40.107.92.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 33D0F1FDE31 for ; Fri, 17 Jan 2025 10:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.62 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737111552; cv=fail; b=OK6zdALyXHVuHFbRjA0C2sPQpZQoXMidTnWNjGYqDl2tYvRHjnXEwQPFopbVeTJIGurA5IifXmhi5Hrzaj3gQKBvNSaY1CTwZ9nMNFyTzui4Rh82ycNCwUV3z2xXUgrMk9ctphupTkNuVrWpVeyNKuJaIBXfjgWtjTr8oD59KI8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737111552; c=relaxed/simple; bh=wHRoogzKkpptdTAo73o7WTWGXSE3ZQ+1nkkRFXWzixQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=DGyWTUSxdwF3sVz6+kSqHIqYdpk3bTMlTu2QAYgdMtEAet7T5XP89r09uP3tnE1pdrP+9Jd/gxm0UIgTIAg9XxY5Nw4Z3Y48N4I7gNboAsKgzUoArnYRKo9YQa/rlxSf0jMznTi+/NR+jmCTnVziFGKyMTWuyIV7+CNgx/jxgHc= 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=N1EOG1mS; arc=fail smtp.client-ip=40.107.92.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="N1EOG1mS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qw+K129CuApezVzRtgARfg+bF9HlbkxGyC6ml/0Y9506gQ53N04J/LhBVu6/5z8U8mtVv9QIFTZAUcm1LofawWkODTnAsqEdNnq3yCGzSIrNhJKnkkcoVYSsgMMDaeiT5slGuQz0VWpcY7rBJ3fLiIB6bdBpssICMtph9dcs23IoEQJe9im7Pv5hhhLKfOmCO3/HbcaOkXqNQrSjB3WiAlJvzBa4YUGdcpqOBjSdJMzXWgvetcL8xJB8Tyx08KHK9hi/i/Qc0xZrxNQz8timMP8JssT2VZG9Xfxz/SxTpUHPlcaAqjL792TQ05kRj2PIen4EAd69SBjDcGR2tKTqPw== 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=8S7tHIthZgaCt1dkuv5wlRmUxVbkp1XgH8L6fjCvLq8=; b=wXN99OfycGpsrn3+45S+XoxsA1FXTDuDgUSE+yFnATfBfAkcrEljowCAxGcB/AChmg4/QPXWQV0VOSUFvAM60avqufYdJMfJEg7sYd5Eaga1aY86o6FdzaK2Vh299U2uvJmIH0I1VIR/SjPLFPmYkvmBqFSgkJmOk6UtdzzLT98nuchbcHLviarxL1lfT67iOrq85bt2K8HwxWto2yoW5hcKafbtvFFJER5sCeS9GqZfsj6vL2H11NJo4zzY77tx5ubdsu1cmRJe9NArVhh7pfwjlaC1eGcE74JP23JsTCCx2jJfcXrasU/bpgtq5dWxP5ldmALkm+WLjgEeBXl7cg== 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=8S7tHIthZgaCt1dkuv5wlRmUxVbkp1XgH8L6fjCvLq8=; b=N1EOG1mSNNRQemy6SgPbjPdcIVAWJ3QuI+GwDGNgnrO0d7Zl5kpodB4TlAf3aF/ZutSB1CcXmP5s952MSNJLPKNRGAO9BavXokUOmvO7nKDGUSX893ihiFn6iIto8hKLMALBicW9NK9cYSDkruZSVhqssm4N5/NhnBMI5fgEH7E= Received: from DS7PR03CA0313.namprd03.prod.outlook.com (2603:10b6:8:2b::18) by MW4PR12MB7216.namprd12.prod.outlook.com (2603:10b6:303:226::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.16; Fri, 17 Jan 2025 10:59:06 +0000 Received: from CH3PEPF00000011.namprd21.prod.outlook.com (2603:10b6:8:2b:cafe::2e) by DS7PR03CA0313.outlook.office365.com (2603:10b6:8:2b::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.14 via Frontend Transport; Fri, 17 Jan 2025 10:59:06 +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 CH3PEPF00000011.mail.protection.outlook.com (10.167.244.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8377.0 via Frontend Transport; Fri, 17 Jan 2025 10:59:05 +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; Fri, 17 Jan 2025 04:59:00 -0600 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , "Gautham R. Shenoy" , Swapnil Sapkal , "K Prateek Nayak" Subject: [PATCH] sched/fair: Fix inaccurate h_nr_runnable accounting with delayed dequeue Date: Fri, 17 Jan 2025 10:58:52 +0000 Message-ID: <20250117105852.23908-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: 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: CH3PEPF00000011:EE_|MW4PR12MB7216:EE_ X-MS-Office365-Filtering-Correlation-Id: c557cbe3-079f-440a-8fc1-08dd36e5f615 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hEuplFJdoi3SLnpQOdvCr4bFQf741f0uk/wRFvMa9nYf3zdSvbA91A784RHY?= =?us-ascii?Q?g2HiXbxQDXp9XXlBKQ7waGTSXazU6h7/z0hKcE5GHTMvOYHeOYSwiAwiGEd3?= =?us-ascii?Q?8Wb8IvTDckZduj47l5VMlXGlgtOjhvXc1o9RM9bcyLyB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2Ja6zeJhK1QOoPVrkpuu91sr+XzyqjXxq1WoYTLKEwE?= =?us-ascii?Q?vSXXgZlKMlDJOFMRi1pTey5hSB9BcFVwy3akV0Ln5jIkH1vn6yuSCPLmnDDM?= =?us-ascii?Q?8VD33pRxEDHIGzmjvC1xnDoYk4XhMm+MI0QhofR3fpTmcqj0+N+1AZU6H3HL?= =?us-ascii?Q?HI9KJkSQumS2ti6vO/CbXAcsax1uDy0ylcdLwS1c0XsBqN6woP0Rmi9v20DG?= =?us-ascii?Q?59Cz4U3xwrWzMwdZhSboFSs+BH4KXjUfo6w5Y2oIZRGJT/990uonShURrkB8?= =?us-ascii?Q?KNqVutDCsZMgZCVXFtyGekleMY4wOrklFnKd30162YrEWXTg2eCN+bfP16Qt?= =?us-ascii?Q?aTiSjyWVq2kkgGjILHuGTkFvu94KRcF7R8knBZKBNP6FsZY064+p2JKL6Ogf?= =?us-ascii?Q?LlPiDDOUbuMJFIe57UDyfKvQaATobYr77V8fGQi6n8h0Saq1fhSCSJrjqebZ?= =?us-ascii?Q?TJ/ogPtISp8WEjs=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)(7416014)(376014)(1800799024)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2025 10:59:05.9559 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c557cbe3-079f-440a-8fc1-08dd36e5f615 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: CH3PEPF00000011.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7216 Content-Type: text/plain; charset="utf-8" set_delayed() adjusts cfs_rq->h_nr_runnable for the hierarchy when an entity is delayed irrespective of whether the entity corresponds to a task or a cfs_rq. Consider the following scenario: root / \ A B (*) delayed since B is no longer eligible on root | | Task0 Task1 <--- dequeue_task_fair() - task blocks When Task1 blocks (dequeue_entity() for task's se returns true), dequeue_entities() will continue adjusting cfs_rq->h_nr_* for the hierarchy of Task1. However, when the sched_entity corresponding to cfs_rq B is delayed, set_delayed() will adjust the h_nr_runnable for the hierarchy too leading to both dequeue_entity() and set_delayed() decrementing h_nr_runnable for the dequeue of the same task. A SCHED_WARN_ON() to inspect h_nr_runnable post its update in dequeue_entities() like below: cfs_rq->h_nr_runnable -=3D h_nr_runnable; SCHED_WARN_ON(((int) cfs_rq->h_nr_runnable) < 0); is consistently tripped when running wakeup intensive workloads like hackbench in a cgroup. This error is self correcting since cfs_rq are per-cpu and cannot migrate. The entitiy is either picked for full dequeue or is requeued when a task wakes up below it. Both those paths call clear_delayed() which again increments h_nr_runnable of the hierarchy without considering if the entity corresponds to a task or not. h_nr_runnable will eventually reflect the correct value however in the interim, the incorrect values can still influence PELT calculation which uses se->runnable_weight or cfs_rq->h_nr_runnable. Since only delayed tasks take the early return path in dequeue_entities() and enqueue_task_fair(), adjust the h_nr_runnable in {set,clear}_delayed() only when a task is delayed as this path skips the h_nr_* update loops and returns early. For entities corresponding to cfs_rq, the h_nr_* update loop in the caller will do the right thing. Fixes: 76f2f783294d ("sched/eevdf: More PELT vs DELAYED_DEQUEUE") Reviewed-by: Gautham R. Shenoy Tested-by: Swapnil Sapkal Signed-off-by: K Prateek Nayak Reviewed-by: Vincent Guittot Tested-by: Madadi Vineeth Reddy --- kernel/sched/fair.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 98ac49ce78ea..0fe6c6e65e55 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5481,6 +5481,15 @@ static __always_inline void return_cfs_rq_runtime(st= ruct cfs_rq *cfs_rq); static void set_delayed(struct sched_entity *se) { se->sched_delayed =3D 1; + + /* + * Delayed se of cfs_rq have no tasks queued on them. + * Do not adjust h_nr_runnable since dequeue_entities() + * will account it for blocked tasks. + */ + if (!entity_is_task(se)) + return; + for_each_sched_entity(se) { struct cfs_rq *cfs_rq =3D cfs_rq_of(se); =20 @@ -5493,6 +5502,16 @@ static void set_delayed(struct sched_entity *se) static void clear_delayed(struct sched_entity *se) { se->sched_delayed =3D 0; + + /* + * Delayed se of cfs_rq have no tasks queued on them. + * Do not adjust h_nr_runnable since a dequeue has + * already accounted for it or an enqueue of a task + * below it will account for it in enqueue_task_fair(). + */ + if (!entity_is_task(se)) + return; + for_each_sched_entity(se) { struct cfs_rq *cfs_rq =3D cfs_rq_of(se); =20 base-commit: 7d9da040575b343085287686fa902a5b2d43c7ca --=20 2.34.1