From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2086.outbound.protection.outlook.com [40.107.96.86]) (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 1DBA819D090 for ; Fri, 17 Jan 2025 15:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.86 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737129567; cv=fail; b=OYl2PhzEQnSkr4WNNHoVtQeaJ3mMAvnngvNCLKCq4jCy04E3Y7v7E2V5K7L1sr+GlQZ5O7IkIndAvKXg8efUqFun24bgQTwbTD9PCXOTuMZmSxmZDqmESlmdn06/A/o5CmVQs40c6SiEIrzR4x6GdspuzUbH2fuLuTS3J2lIaHc= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737129567; c=relaxed/simple; bh=bshRHvFqiW8DWeekATxb9AwiKcFacKDxe+ne+8QLObw=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=EeB/9rEZL0OKIs+wwZYxAw22jkK96MvP9dza1EbRXKMexM47fN+VXi+I/kuKxCC/IyFyogYr6eQh+h+dC1d8tgQ6Q3FHfUsgp8oLVCuB2xELMREp8E/WWlX/yfFjHYOcCKdd3nO2UZdgHwlpdghlgdEI6m1aSv3P4KjqFXigAcQ= 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=bOAJzlUo; arc=fail smtp.client-ip=40.107.96.86 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="bOAJzlUo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=b4WC1zTx6eyGhefbZ7HFEMTbUvRDHOJV4evvUEDLG4uLfZ57KIYAyDoLUrrV754juv0ZADf+9NwMfYrgmBZws+JL63qG1Piys6eFmyM+9DIgOf5ljo3JsLiO427nWT/A4dSQMqWczJ1zm15iy29GnLM9epGlANvkfZWP4pzhsAqwU952+wwZBlWo5ESpdC9Cw/hFetxvm1O7H7vlSeIlzIhigUi/ObQzuYTFKDLnEkF4zAUwftWF1IJbqjFtO8w/n4itS2GA2tEdJxBPVrb4ysMqZBNz5f6QVV5wJdF+Rh1D6EZkZ27dkMqbEo85mrj8RkFkqpRbLi8J4CnTeQSJhg== 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=MyzafqxoAwHenIeQQKeX+r3tE6I4lYDQv4wXiKddIJY=; b=OZyf/gJ3QeC1i2k0y2/xIVSml14155yuiCEEM62F1FFxv+rpNuos/0+BQ56lFLim9XFzzRgPrAYxLFbgP1gOUiVxUktaWtmE5Gg2AIi2T/O75hr1/o4mZ5geiPNL6VSnq8aVG6BkxHYzjY6uZteasZ8QpsBKcNMU+G6eZfcM2BbJhsBtAif5GBuY/Got3WMLtZAXTroGJBPeljELQ+QItVvUYbRMpeY1TGR1X0yTOCc+g/h8JbbitXDfIkVwkOGGVarE1qYRa/G7ZXuGZk39TuKBdOV1REfo1njfui0ktCLILzqhWdbmkS5nJZLJhPSTw8micQIVP/hlAKghlIXY4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linaro.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=MyzafqxoAwHenIeQQKeX+r3tE6I4lYDQv4wXiKddIJY=; b=bOAJzlUo/HilK7dHv3bVjWqJ1l9kR8U9I6QToP1nRbmBnXZIYjZ+tCmusodqalOOtt4lzGb3yohvtgCtRPlq9SPtRcNlQqb3OsxovsdWP4nfAEgFj5IPb0YnEZv8W46qNvrWsWbOtQjh/ocMbig9+LRLwPCGu5Ah7B8A6d99HBE= Received: from CH5P220CA0016.NAMP220.PROD.OUTLOOK.COM (2603:10b6:610:1ef::22) by PH7PR12MB5758.namprd12.prod.outlook.com (2603:10b6:510:1d1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Fri, 17 Jan 2025 15:59:20 +0000 Received: from CH2PEPF00000146.namprd02.prod.outlook.com (2603:10b6:610:1ef:cafe::68) by CH5P220CA0016.outlook.office365.com (2603:10b6:610:1ef::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.16 via Frontend Transport; Fri, 17 Jan 2025 15:59:20 +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 CH2PEPF00000146.mail.protection.outlook.com (10.167.244.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8356.11 via Frontend Transport; Fri, 17 Jan 2025 15:59:19 +0000 Received: from [172.31.188.187] (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 09:59:15 -0600 Message-ID: <79cef0b2-4ed2-4141-9a66-150d04b82476@amd.com> Date: Fri, 17 Jan 2025 21:29:12 +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] sched/fair: Fix inaccurate h_nr_runnable accounting with delayed dequeue To: Vincent Guittot CC: Ingo Molnar , Peter Zijlstra , Juri Lelli , , "Dietmar Eggemann" , Steven Rostedt , Ben Segall , Mel Gorman , "Valentin Schneider" , "Gautham R. Shenoy" , Swapnil Sapkal References: <20250117105852.23908-1-kprateek.nayak@amd.com> Content-Language: en-US From: K Prateek Nayak In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF00000146:EE_|PH7PR12MB5758:EE_ X-MS-Office365-Filtering-Correlation-Id: 2be67dd9-6845-4100-6c43-08dd370fe730 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Mld3WU5VMTNEUW4vclAvcVFNNldYaTdjbEVaY1JPenpiZEhKaEdvaE02cEhn?= =?utf-8?B?MUZXMlRSU3Bua2xaZ2wyYkp1ZUFIdFJ2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-8?B?UFRTRlQ4andMb3ZXVmdpd0hJZHhlRmpGR2w3aHliMm1UNjA4R3FLcHNhN1VP?= =?utf-8?B?OUY2YWxCWW5xaVVzZUlLOWpkV2xjdHVldzVVWjRhck13Z0lBTmN6WDJDaWJN?= =?utf-8?Q?0thsbrDe1zBljs0tDr/6oJCnxMU/oE=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)(376014)(7416014)(1800799024)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2025 15:59:19.8288 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2be67dd9-6845-4100-6c43-08dd370fe730 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: CH2PEPF00000146.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5758 Hello Vincent, On 1/17/2025 6:55 PM, Vincent Guittot wrote: > Hi Prateek, > > On Fri, 17 Jan 2025 at 11:59, K Prateek Nayak wrote: >> >> 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 -= 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") > > You probably mean c2a295bffeaf ("sched/fair: Add new cfs_rq.h_nr_runnable") You are right! I had done a git blame on set_delayed() ad landed at commit 76f2f783294d but you are right, it should be c2a295bffeaf ("sched/fair: Add new cfs_rq.h_nr_runnable") when the accounting was inverted to account runnable tasks. Thank you for pointing that out. > Before we were tracking the opposite h_nr_delayed. Did you see the > problem only on tip/sched/core or also before the rework which added > h_nr_runnable and removed h_nr_delayed The problem is on tip:sched/core. I did not encounter any anomalies on 76f2f783294d ("sched/eevdf: More PELT vs DELAYED_DEQUEUE") "h_nr_delayed" was only adjusted in dequeue_entities() for "!seep && !delayed" which would imply migration or a save + restore type operation and the whole "h_nr_delayed" adjusting was contained in {set,clear}_delayed() for delayed dequeue, finish delayed dequeue, and requeue. > > I'm going to have a closer look Thank you! > > >> Reviewed-by: Gautham R. Shenoy >> Tested-by: Swapnil Sapkal >> Signed-off-by: K Prateek Nayak >> --- >> >> [..snip..] >> -- Thanks and Regards, Prateek