From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11023125.outbound.protection.outlook.com [40.107.201.125]) (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 03E80284B26 for ; Wed, 3 Dec 2025 05:31:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.201.125 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764739920; cv=fail; b=jC3NOvo6d2q/rAVNAX7Zh7j3d0YAsAso8nWDm03OeIoYfqVG8UFBE1zWHF7xmAJ6nyR/gJBMIITEU4z7InoP7riyRejAyjjrY43NZlIOY894dU5YvXVMCyStW+fjC5U6KIZO4Yqz8PC8O6IZ3QEpz5V4RQGWuzOfrJFjV9xjlqI= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764739920; c=relaxed/simple; bh=F1k0BYHf1H8AGQzD/wxvwVc4w3mDqJwJorX6g5mOVTE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XDAwc5VL1an1TQtNv3DGxmnmvysmxSe5STvaIFAjHcHEGTrujfCS44mGOjD203CcuB5abRvEkI3R60qzgjt1mv4b+BxB5g/E9Vl9JyTUGNJOXST7/GYGyJn+o/PuB78pBf1xbUPaxBUrhxWNAiNb9qyC7UGJSFqavOYX6F1CaSw= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com; spf=pass smtp.mailfrom=os.amperecomputing.com; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b=QCEHYxEa; arc=fail smtp.client-ip=40.107.201.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=os.amperecomputing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=os.amperecomputing.com header.i=@os.amperecomputing.com header.b="QCEHYxEa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A0ijnUi2Ty3GpTy/qWvKtiFFJflwxurEpe6UKxLiA10ASQiUo7zOsPzlMyn1cUFmfxHun9tlf8l3P9nYjYozgBxXAgFrAsYnrE7JbMBjebGYYx27EhfYhtUUPj4tmzfePkwYW9xpVB7XxPb5lVFeSTw5g/xhGxwGlbRIahIdqK+yDEyjEU1kqTy1YDEV2g5DvKvmcOmcoZR0BukzVkp8xGDfWNVXnzzevaj7wX775b2/Uwzt5k3zmHPoF9oqTQr+oc9x/31Gqcs8XdaJ+yT1adU/dUC4rJ/p/+0Z6Jg4LN2PgVVYdiGzc54ytkWMJmcizVnbcRUQ/7UXbr80beMbaw== 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=06IQ4RM0Bw7/+aOwYYc2l277oyutZwGGm7RF0N+SDpc=; b=Ta+hiETmeJxuoo/QOcMBjrpDZQkx8lMzeY68mxVmHca4B+LDyNCvoCtAqhfNM58hhOb8hVVJOuNjhYyddqtg4/NdikH2EWn0CWSkjUftis7QWyluWBzXRPSJw5rrWC4D4UDLFeb1FW6Ren9PzQHALrgRZGOlYtt8RS3ybTXV810o8aIdF3p+j6JlyOEBbMHIhgMlA+UKRYdI7LbSCg/1hUV5MAlCHxbN+saVavQhdQoRfq7GiNwPTu0lnP+JVIb9ArRUw2KzBYD6+FS/onCzG0d/20qdszPOQ89KupbqZx2X7YQdxLLOvV0rpzfUxe+S9x7O0hHRCRUappBkJwws6g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=06IQ4RM0Bw7/+aOwYYc2l277oyutZwGGm7RF0N+SDpc=; b=QCEHYxEaNNTgD78p9RPk3VbbhWw3/rl/N/s601JGu41NZTYd/IQt3zW2del+gBbpGEaYh5dwIGLUb76uqdX/L4jK8UAT3sF3PFTOsJWPJemoUTUuQ/IGohSc5JpFoKoPDmNj5/j0lY9NkigRhN6dgZ3mrogXaMO/TlnW/JvGwR8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB7975.prod.exchangelabs.com (2603:10b6:510:26d::15) by IA4PR01MB9425.prod.exchangelabs.com (2603:10b6:208:557::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9366.17; Wed, 3 Dec 2025 05:31:56 +0000 Received: from PH0PR01MB7975.prod.exchangelabs.com ([fe80::6926:a627:118e:8050]) by PH0PR01MB7975.prod.exchangelabs.com ([fe80::6926:a627:118e:8050%4]) with mapi id 15.20.9388.003; Wed, 3 Dec 2025 05:31:56 +0000 From: Huang Shijie To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org Cc: patches@amperecomputing.com, cl@linux.com, Shubhang@os.amperecomputing.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, linux-kernel@vger.kernel.org, vschneid@redhat.com, vineethr@linux.ibm.com, kprateek.nayak@amd.com, Huang Shijie Subject: [PATCH v5 1/2] sched/fair: set rq->idle_stamp at the end of the sched_balance_newidle Date: Wed, 3 Dec 2025 13:30:55 +0800 Message-Id: <20251203053056.4128-2-shijie@os.amperecomputing.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20251203053056.4128-1-shijie@os.amperecomputing.com> References: <20251203053056.4128-1-shijie@os.amperecomputing.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TPYP295CA0039.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:7::10) To PH0PR01MB7975.prod.exchangelabs.com (2603:10b6:510:26d::15) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR01MB7975:EE_|IA4PR01MB9425:EE_ X-MS-Office365-Filtering-Correlation-Id: 15c7c875-f0f1-4e8b-7f01-08de322d45fe X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|52116014|7416014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?LcvNzUHu6LuzVuFVlkD7SqkYKjXoNQd3YQUz5mTVOiEs6AP2sXtpIwYdO9BX?= =?us-ascii?Q?pqqqMKwkkdOVXb8C9siL7gyEel2vlnNqMoHPX72SNy9nVDichQOdC6vHKcIk?= =?us-ascii?Q?eNcblgy/35PP+1fw14murCQK4muADPUPEBMYU6k+5w690R5ad1oOq2/GrhNt?= =?us-ascii?Q?tTfQHL+kTwmbFehTUjUk0IWCGYKFKn+Bh2HoztREnTzt1QAe9G33HL/RvEOo?= =?us-ascii?Q?FxxwZs215riBzA4DAE22RU0ctu1KjRCodfrGZzzs3XBoLr94wuhgoT2EkD4C?= =?us-ascii?Q?8SJh6H9/Iaaegi8Jg+z6kZWqiWvbCEosolKTHhLM/reONcuMntL4taviHGoz?= =?us-ascii?Q?sjSCfQLdLwf3zgxT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ascii?Q?xrSnRoXzJdiWZ3Y94I5tkHmQtWgl0XZePeJFRdFh/t3YXWYC51FkuWfWAjAc?= =?us-ascii?Q?iFf13mSVENOAUl+AIoWhK2RxsdG/8QhPaKK5hGV/z517E6N/vhYr7mwXtGrz?= =?us-ascii?Q?ufxrA1S5ZU57tL9rzVHBX580nXHzavwQOgJzBnkSpYnpf3LjNHSOZJoxc5ak?= =?us-ascii?Q?vojMEVHXY+6myUjHB7yoJmDy78wNKqupDpMynNklM/qViRmpXN9TENXHAWRg?= =?us-ascii?Q?9A3tNel4M+SZk8l+Z3N3GUC1gK4tPOab+jF2?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7975.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024)(52116014)(7416014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?y1tQbw4evgaG/WXfMBoDafrGDXP8OeXPEYAY/G9zvvQJVUdyfqOo1dTttYx7?= =?us-ascii?Q?HrVRP6zzc1btmD2jBSCN8aNKdz4nI7jSjqzawgNGcbpHmWU3/3SZuQk/BUrS?= =?us-ascii?Q?wosSX/47K4AE/7gtObocI6y6jG6KeO09kYNsQrkxTbGBHYSF9gczrdU9ou9j?= =?us-ascii?Q?I8aoYjNjq7Dz5WrsVqMa7rIOZ9NeGAj3q8jAbZdAsBQdPE0Arv5bx/3ko0WB?= =?us-ascii?Q?0fS42F+HasFlo7rsbYO2GUgdGaTn5D3YToydY8CfAH+LBMDRiPynWk24Av8P?= =?us-ascii?Q?y7QL0Nf5GWZuRTLNX7wA69Jc/BP5M9lNGt/+z++jI3SnaMX2r/D8tw3qG6ou?= =?us-ascii?Q?swzkOt3gU5yQGT9HFRus1zHLKdoMGG52ySumFn76OJBoFPY+IsG89lbXZA0B?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RQEHL2K9dhDygW9L5x1Pstj3R1gSzxnC+zS1l0bLb?= =?us-ascii?Q?cUloLfEILG2Au1e7rRu8lWhY7jPfGu0PH3KiHkyF0ceLktyU6B1x1n+F4ihZ?= =?us-ascii?Q?ilao4s2/sWafn3yrWO9I1ql/6QXddVMKNOB9Q1DEcXwBwyaJFQW6CufDfo4V?= =?us-ascii?Q?QlCUH1LYEituf06kwwoTE04qLrepf26OpoC7UF3pDYonsH54W7HbN3vVOxdG?= =?us-ascii?Q?Ndy/LAOJNe0+bEa3jbvL/wlyfNsTir8wGEF+0HzB5dZEksCIj6gk88mnl46C?= =?us-ascii?Q?1rIpAnDr5n4hSCmiTxZN6U1VnN3P1zsI9f1Pfgd51rMCZDkRfEBsYCrm2036?= =?us-ascii?Q?D7DHFK0L5H3Jm8M9vhJED6M=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15c7c875-f0f1-4e8b-7f01-08de322d45fe X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7975.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2025 05:31:56.5137 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8mgvfH2ClAR+Ppnq5g6PXafKNu2KXEKFacV3y7kd6mwJMmeeWvaQ96WYdAM5/OtY0zAXFxOlB5npWGJ0TQsKn/S0eh/4gitcNRcXChaDE7q/4uK2bnZFDWuWP3NjWk9d X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR01MB9425 In current newidle balance, the rq->idle_stamp may set to a non-zero value if it cannot pull any task. In the wakeup, it will detect the rq->idle_stamp, and updates the rq->avg_idle, then ends the CPU idle status by setting rq->idle_stamp to zero. Besides the wakeup, current code does not end the CPU idle status when a task is moved to the idle CPU, such as fork/clone, execve, or other cases. In order to fix this issue, we want to add a hook(update_rq_avg_idle()) in the enqueue_task(). With this hook, if a task is moved to the idle CPU, it will update the rq->avg_idle. Unfortunately, this hook is also called in the newidle balance: sched_balance_newidle() --> sched_balance_rq() --> .. --> enqueue_task() If we still set rq->idle_stamp at the beginning of sched_balance_newidle(), the rq->avg_idle will not be updated correctly. In order to make it work correctly, save the idle_stamp at the beginning of sched_balance_newidle(). If newidle balance cannot pull any task, set the saved value for rq->idle_stamp. With this method, the newidle balance still work correctly, and the hook in enqueue_task() also works correctly. Signed-off-by: Huang Shijie --- kernel/sched/fair.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 1855975b8248..cfdd22e5dcab 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -12865,6 +12865,7 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf) u64 t0, t1, curr_cost = 0; struct sched_domain *sd; int pulled_task = 0; + u64 idle_stamp; update_misfit_status(NULL, this_rq); @@ -12880,7 +12881,9 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf) * for CPU_NEWLY_IDLE, such that we measure the this duration * as idle time. */ - this_rq->idle_stamp = rq_clock(this_rq); + idle_stamp = rq_clock(this_rq); + + this_rq->idle_stamp = 0; /* * Do not pull tasks towards !active CPUs... @@ -12992,10 +12995,11 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf) if (time_after(this_rq->next_balance, next_balance)) this_rq->next_balance = next_balance; - if (pulled_task) - this_rq->idle_stamp = 0; - else + if (!pulled_task) { + /* Set it here on purpose. */ + this_rq->idle_stamp = idle_stamp; nohz_newidle_balance(this_rq); + } rq_repin_lock(this_rq, rf); -- 2.40.1