From nobody Tue Sep 29 14:53:54 2026 Received: from gentwo.org (gentwo.org [62.72.0.81]) (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 D1D6019046E for ; Fri, 7 Aug 2026 00:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.72.0.81 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786063060; cv=none; b=FwLK8OlY7VR3rM3ZdfRfXSHJUvSlNqceenvXguFy2VqnlWFB6S6xakEu8TLm+2l6va15NK6IpPvt3gyljHtpuzXV+Jq9bajstD8KdSgL7jp7D//Ednn7c7zkcJnnDoUiF17DxqaaV9nv27ddRuJHhCxInrUZAgvuOi2LTR8qyT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786063060; c=relaxed/simple; bh=Se3dyKWhSSK8BVG8nLqKLn2DgSvzd5Zbn7tNpBjOHQw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=ElxIKAxdkA9qWKWUBZTml9M1RI/fWPxZIUpfELP/MT+tYxfVkcfoJHo6NIzbZlKqquy8oFQxOJc6i9gAGj/mLBJaVxyiSSRBGFKOpMByqnZBCPp2yGVtoeeEoOWQwVPFPSukfjtSLn+PfRjcNpKjUjqjbLWUDSenwhV9Selh3ZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gentwo.org; spf=pass smtp.mailfrom=gentwo.org; dkim=pass (1024-bit key) header.d=gentwo.org header.i=@gentwo.org header.b=UjMAWUic; arc=none smtp.client-ip=62.72.0.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gentwo.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gentwo.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=gentwo.org header.i=@gentwo.org header.b="UjMAWUic" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gentwo.org; s=default; t=1786062396; bh=Se3dyKWhSSK8BVG8nLqKLn2DgSvzd5Zbn7tNpBjOHQw=; h=From:Date:Subject:To:Cc:From; b=UjMAWUic79WSp5GAxHV++jMTUfkeP+hcMnHPSh3P6jGRaqnpIP21Ap2cO+De6Hx7u V7jlAFBt1IWW1IJY4cpc0GsoVML4oy54fkacjaW3ZFoiGzFT/RPAY9uZgY1BjMNAMA Stq5H+Kfm5/y9PinhAMz09M18T0+a2PLLj8pcUvY= Received: from sut02sys-r112.scc-lab.amperecomputing.com (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTPS id A376C4046D; Thu, 06 Aug 2026 17:26:35 -0700 (PDT) From: "Shubhang Kaushik (Ampere)" Date: Thu, 06 Aug 2026 17:26:27 -0700 Subject: [PATCH v2] sched/core: Skip rq->avg_idle update without a valid idle_stamp Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260806-master-v2-1-e1f3a1a0c903@gentwo.org> X-B4-Tracking: v=1; b=H4sIADImdWoC/2XMQQ7CIBCF4as0sxYDo4i48h6miwpTykIwQFDTc HexW5f/y8u3QqbkKcNlWCFR9dnH0AN3A5hlCo6Yt70BOZ64wjN7TLlQYlIaq4wRB9Qc+vmZaPb vDbqNvRefS0yfza3it/4RVTDBZi2tvnNxVBavjkJ5xX1MDsbW2hdpntf/nQAAAA== X-Change-ID: 20260728-master-55cd7cc13290 To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , John Stultz , Christopher Lameter , Shubhang Kaushik Cc: linux-kernel@vger.kernel.org, "Shubhang Kaushik (Ampere)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1786062395; l=3023; i=sh@gentwo.org; s=20251010; h=from:subject:message-id; bh=Se3dyKWhSSK8BVG8nLqKLn2DgSvzd5Zbn7tNpBjOHQw=; b=0F4zPX2QO4vTNrz+jIBQfUKr80607YPzDqWZgRIGKcNPT8+st1/ZmUnsTCCplaY8EvYhQRODy 3+QI+PU8P5gDlvhaeouPN+b0JbtKNUoUQTuq4Im/cQ26Jqg58KADk3o X-Developer-Key: i=sh@gentwo.org; a=ed25519; pk=jc8YIRvxPSyJaBRe5y+a4N0RXKBUEcAh8+OFhlROXPY= Commit 4b603f1551a73 ("sched: Update rq->avg_idle when a task is moved to an idle CPU") moved rq->avg_idle accounting out of the wakeup path and into put_prev_task_idle(), so that the idle interval is consumed whenever the idle task is switched out. The wakeup-side accounting that it replaced only updated rq->avg_idle when rq->idle_stamp was non-zero. The new helper lost that validity check and unconditionally computes: rq_clock(rq) - rq->idle_stamp If rq->idle_stamp is zero, this uses rq_clock(rq) as the sample. That is not a valid idle duration and can immediately drive rq->avg_idle to its clamp. This can happen when the scheduler switches to the idle task through a path that did not set rq->idle_stamp via newidle_balance(), for example during find_proxy_task() or force-idling. Restore the idle_stamp validity check in update_rq_avg_idle() and skip the rq->avg_idle update when there is no measured idle interval. Fixes: 4b603f1551a73 ("sched: Update rq->avg_idle when a task is moved to a= n idle CPU") Reviewed-by: K Prateek Nayak Signed-off-by: Shubhang Kaushik (Ampere) Acked-by: John Stultz --- Temporary tracing under hackbench load confirmed that update_rq_avg_idle() can be reached with rq->idle_stamp =3D=3D 0. Hackbench showed no material regression versus v7.2-rc5 mainline. Related discussion: https://lore.kernel.org/r/20260423023322.1293923-1-firelzrd@gmail.com This is a narrower variant of the earlier proposal. It keeps the rq->idle_stamp guard in update_rq_avg_idle(), but intentionally does not stamp idle entry from set_next_task_idle(), preserving the existing newidle accounting model and avoiding forced/proxy idle accounting concerns. --- Changes in v2: - Add Reviewed-by from Prateek. - Mention find_proxy_task() and force-idling as examples of paths that can switch to the idle task without a valid rq->idle_stamp. - Cc John Stultz. Link to v1: https://lore.kernel.org/r/20260728-master-v1-1-f95d9b0147d2@gen= two.org --- kernel/sched/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 96226707c2f6135341aa779b8262f113e103d8ad..d8c9a80ffa83ac680bb479f6735= 7ac1ec4a6d55e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3732,11 +3732,17 @@ static inline void ttwu_do_wakeup(struct task_struc= t *p) =20 void update_rq_avg_idle(struct rq *rq) { - u64 delta =3D rq_clock(rq) - rq->idle_stamp; - u64 max =3D 2*rq->max_idle_balance_cost; + u64 idle_stamp =3D rq->idle_stamp; + u64 delta, max; + + if (unlikely(!idle_stamp)) + return; + + delta =3D rq_clock(rq) - idle_stamp; =20 update_avg(&rq->avg_idle, delta); =20 + max =3D 2 * rq->max_idle_balance_cost; if (rq->avg_idle > max) rq->avg_idle =3D max; rq->idle_stamp =3D 0; --- base-commit: c0a27675eaf08255017b3cabc28c99c0cd71f468 change-id: 20260728-master-55cd7cc13290 Best regards, --=20 Shubhang Kaushik (Ampere)