From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011011.outbound.protection.outlook.com [52.101.52.11]) (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 985322AE7A for ; Tue, 2 Jun 2026 05:25:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.11 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780377954; cv=fail; b=joKyRObYmQkRvu5JCyajFfuk48+RmQLG8Aafj0RsAxGJwdCVwYLdBjhaCB41/hgGv/9tJl9xlKpficsK+6uwgC+ViJutlvWjHD5bYgKkKmTB/IKd3SwdDuXVnBbaDURDgaNvJqpufXOXhSSNgitRP8lsTY3TsuWpuoP98WXZigM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780377954; c=relaxed/simple; bh=YFJkYOi8z1oqR8JwFkDdRSpF+bdEnrm0x1m2P4zcLUU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AREeinuRScNpzA5lCJjxO3XcpoywJ0sJTmJPMLNY+erhIzJJt47yQUHA/JV6gBsnYsjRn4Hl9XhpojoBoU4Ewnd+uKPniz7HBBTY3wDg2A8/9LWFMs+Z9seaVjos0IFv37xmwkt0KP9xhqziyt5jDnnPi6hBZAdHEjtIODs5Kuk= 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=5uePIOpL; arc=fail smtp.client-ip=52.101.52.11 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="5uePIOpL" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mcS+DQvADuKoonwkJlbPgxwFBCIzBKgFgYNuBJxWEcDwteoo5GDSDZW7lGqzwG6Pv0/rFMFwqGDlt1AMwfpJq8GHrFaX7IQwbZhb2D8nAUUpDwO2J0M+TowBDLnt7kqS9Lec/MCJydsEKUKcbeW74LvoGX+bkL/2LU6dMv3yN71j4vUBhASq7RVn1iqjCVSpSD4OReZHv+M6Oxzw0uxx+tm9R0YJdYs4pEv23VgyslCViR/uH7gT371DWHnwViIJGGrBvZzpypkaNCd2aLALP31fC5ZroVRuwV5BwVyDzUGYA62SPohOzFScg3kMHBLWoog1NqUP9dq9gLeNck7EtQ== 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=tgzz6mOc6ODmaX9v3KW/x2FXuLDrBJKZcq+ZnH/L/2g=; b=scVA1xwl9+LkIv1pyoVSN9bzGB1GiKIMB3UcFga/wIQ+rF2W3AUC0EC1xGnhL3gWQXWKyhY2U5bOe93OGjAi/x/jH90OBiSCiiH9hd3tVLb/HsQqGt3KlriIPHPZ8pOLaz4c2m58LF24cWW8UbdrP53MM6IUYluWfjiTQ5No9/PEggGw0SzO8Zl7JJsbxLtdsz+MLMza7xjHEKUPjKJA5RSTg6VrXfSgwLDr7Lv1hlOuLgMmZmhG1QQ9fEJt07sdwRDog4rMMNhXho0lcD4zjhxHJLQ3aD4ba0+C937/KO0TFHMs8s2G7pbGKZ+fyrjaUzwLcAuZE1lnstVg1w7s3A== 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=tgzz6mOc6ODmaX9v3KW/x2FXuLDrBJKZcq+ZnH/L/2g=; b=5uePIOpL8RhFvfjhM3xXLg28faxEpzIxaoJxQq3w9PS2PaAHfBOzV44bGvLG5NFuli6W3eRXr05AkRDA2VF/3PTif38JiQe6EEHvoJs87mlZr+aA37B/uclZCikx4Lb5YcTnuYCprnCvSiYCnL2TuuLQi8S0JHikk30jvVDYYy8= Received: from MW4PR03CA0023.namprd03.prod.outlook.com (2603:10b6:303:8f::28) by DS5PPF8B1E59479.namprd12.prod.outlook.com (2603:10b6:f:fc00::659) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.71.14; Tue, 2 Jun 2026 05:25:49 +0000 Received: from CO1PEPF00012E81.namprd03.prod.outlook.com (2603:10b6:303:8f:cafe::60) by MW4PR03CA0023.outlook.office365.com (2603:10b6:303:8f::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.92.7 via Frontend Transport; Tue, 2 Jun 2026 05:25:48 +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 CO1PEPF00012E81.mail.protection.outlook.com (10.167.249.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.92.5 via Frontend Transport; Tue, 2 Jun 2026 05:25:48 +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.41; Tue, 2 Jun 2026 00:25:44 -0500 From: K Prateek Nayak To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot CC: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Aaron Lu , Josh Don , K Prateek Nayak , Subject: [PATCH v2 3/5] sched/fair: Call update_curr() before unthrottling the hierarchy Date: Tue, 2 Jun 2026 05:25:29 +0000 Message-ID: <20260602052531.11450-1-kprateek.nayak@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260602050005.11160-1-kprateek.nayak@amd.com> References: <20260602050005.11160-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: 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: CO1PEPF00012E81:EE_|DS5PPF8B1E59479:EE_ X-MS-Office365-Filtering-Correlation-Id: b48f52ee-ba09-41fa-5c28-08dec06767c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|7416014|82310400026|1800799024|18002099003|10063799003|22082099003|11063799006|5023799004|6133799003|56012099006; X-Microsoft-Antispam-Message-Info: rVGh5og75ZZIOZtVzlGIpcw2VvtMW4CRWesAgYTbKADpWrPcqUJLWRJb6K6DQ3nshPeUlaY6eYrNGVJmqeK3OnhzlfB+YZZIk5RzGB6qiVyDOVjou0yh4gbauFTFshlODGgUEMOmqxNweDcch73Uf55bjSaHFN0WXtMYqS+NycgZT/chz7WWJ9F7z0DaFKw+IezT082PU6bS9CWLJkSumfXa5TonDZ110ISfD9b+IrNMU64TdMz880ZfkxhuXHWmps+YHluWUYPY47wXGZ7QYqz2gyUy7/vPPYOHrK7NkBHGtEnr0wGFkTRC9I9ajdROubbcqCmKM8MGiwxxrWLnC2JUBC3+PnNh78ir38LKPWrhwKJ/TxqjUWMCmo6fcAsUZ8Sklk/dJACz37w+uWemCWrC3JATznW2AAG3t0ofFlITNgQVlvnul/yXfHWuKi7LmmlvXoGSscZFSBNpLdLIPps0E1uxyI6m4pSZcq4Z8dr3TPSlAyy6tH27JE5GwI9sr7d5PXXZeBid8Sm6dtXxNy2aOGn6GtrdBQDOHOCUfQVzrzLDx9LNqnczLhR3xt1hEmWUVoyUwcU/W/0Sm+7T9+pq4HZF0dM0ZIaYMGC3qURlsQBR1a3NW/oYT564PiuAosFLKn9bERxx+PjJHvMilD5spzRYKeMKI/cPFHRW948bJIJehyWyeBYJSi3GWK+1up6mFYuusLxIkqhxO9TtZEYQridl2qjwOUE+HSq7o70= 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)(376014)(7416014)(82310400026)(1800799024)(18002099003)(10063799003)(22082099003)(11063799006)(5023799004)(6133799003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4vdO63QMDjakS4bm6SLoueTQIMS56zNRYP01YmPUWjii0KDVppIqtJZ3UTUlx43kuidG8dKjMW7XLkyoAMqhpEuDELHt0KPdEUlMzeMns2Fo7/2/8wo6IN2fJzgR7IRfe60iELCO2u0Ddq+8gm1S3jzn4hSVPp5p2QHpPujg/gCg75TNZZDlt8QR/hqGnD3PlMg2QjmKWJhFcQarhmQWav3FLh6Jm9vryg8zP5OcnDhU7jijkX4xs6tAINjD1ALhAyki/QLvZUaj6kk5zMHyM5ZNfKoXe57Slts01y/vEq5MRlyobFT3QaIalKxl3LohgMw88ertfsiEO3tgo/Kp6wQ6DDqGWH3XFXjVd0RQk5d974G+/RddkKgvjzGtGq//PtPL1+Nmd0/9fJZdIU9aJpXPBTWMt9KEHPoTdzDszRK/6uYr0q3i8RtbqUFpsWDE X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2026 05:25:48.7312 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b48f52ee-ba09-41fa-5c28-08dec06767c6 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: CO1PEPF00012E81.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS5PPF8B1E59479 Subsequent commits will allow update_curr() to throttle the hierarchy when the runtime accounting exceeds allocated quota. Call update_curr() before the unthrottle event, and in tg_unthrottle_up() to catch up on any remaining runtime and stabilize the "runtime_remaining" and "throttle_count" for that cfs_rq. Doing an update_curr() early ensures the cfs_rq is not throttled right back up again when the unthrottle is in progress. Since all callers of unthrottle_cfs_rq(), except two, already update the rq_clock and call rq_clock_start_loop_update(), move the update_rq_clock() from unthrottle_cfs_rq() to the callers that don't update the rq_clock. Reviewed-by: Benjamin Segall Signed-off-by: K Prateek Nayak Tested-by: Aaron Lu --- changelog v1..v2: o Added the missing update_rq_clock() in tg_set_cfs_bandwidth() - well, Peter added it and I just moved it just before the unthrottle and made the robots happy with the build. (Aaron, Peter, Intel Test Robot) o Added an update_curr() before replenish in distribute_cfs_runtime() which helps performance a little bit. Since this was trivial addition, I've retained the tags. o Collected tags from Ben, and Aaron (Thanks a ton!) --- kernel/sched/core.c | 5 ++++- kernel/sched/fair.c | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index dd031410ab1a..e745c58671ed 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -9859,11 +9859,14 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, struct rq *rq = cfs_rq->rq; guard(rq_lock_irq)(rq); + cfs_rq->runtime_enabled = runtime_enabled; cfs_rq->runtime_remaining = 1; - if (cfs_rq->throttled) + if (cfs_rq->throttled) { + update_rq_clock(rq); unthrottle_cfs_rq(cfs_rq); + } } if (runtime_was_enabled && !runtime_enabled) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 825393d3f039..16e0ccaffe6e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6711,6 +6711,15 @@ static int tg_unthrottle_up(struct task_group *tg, void *data) struct cfs_rq *cfs_rq = tg_cfs_rq(tg, cpu_of(rq)); struct task_struct *p, *tmp; + /* + * If cfs_rq->curr is set, the cfs_rq might not have caught up + * since the last clock update. Do it now before we begin + * queueing task onto it to save the need for unnecessarily + * unthrottle the hierarchy for this cfs_rq to be throttled + * right back again. + */ + update_curr(cfs_rq); + if (--cfs_rq->throttle_count) return 0; @@ -6853,14 +6862,16 @@ void unthrottle_cfs_rq(struct cfs_rq *cfs_rq) * We can't unthrottle this cfs_rq without any runtime remaining because * any enqueue in tg_unthrottle_up() will immediately trigger a throttle, * which is not supposed to happen on unthrottle path. + * + * Catch up on the remaining runtime since last clock update before + * checking runtime remaining. */ + update_curr(cfs_rq); if (cfs_rq->runtime_enabled && cfs_rq->runtime_remaining <= 0) return; cfs_rq->throttled = 0; - update_rq_clock(rq); - scoped_guard(raw_spinlock, &cfs_b->lock) { list_del_rcu(&cfs_rq->throttled_list); @@ -6935,6 +6946,7 @@ static inline void __unthrottle_cfs_rq_async(struct cfs_rq *cfs_rq) bool first; if (rq == this_rq()) { + update_rq_clock(rq); unthrottle_cfs_rq(cfs_rq); return; } @@ -6988,6 +7000,11 @@ static bool distribute_cfs_runtime(struct cfs_bandwidth *cfs_b) if (!list_empty(&cfs_rq->throttled_csd_list)) continue; + if (cfs_rq->curr) { + update_rq_clock(rq); + update_curr(cfs_rq); + } + /* By the above checks, this should never be true */ WARN_ON_ONCE(cfs_rq->runtime_remaining > 0); -- 2.34.1