From nobody Sat Oct 4 21:00:49 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8854B27FB12; Wed, 13 Aug 2025 10:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755081023; cv=none; b=av31feSh3oEH17MY9j5wR7A0zBIApE5vMRurA3NT+ByQAcx0f2lFthEkmZGMOsWr907jq/XKDCu1o9UA7tQpTnZqbafo4XLIGlrV7JWWxgjJwWYa77gaGNR/gJAAO368o5+MM26egN4jRyKHSeEzmMjf8EUsNTcTHbHSOxYSSjY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755081023; c=relaxed/simple; bh=vDPhAaa14SEPGFOTgtOyQn/Sq2qo0iYZvFtBPzZ4t1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kU1GxoWPDcJYt6xJr6Vnq/OABLgojD5ie1U1+JXyg/NgAnRCBpdA2YOU9LK9bTW+4IDMHhg6dQ3q+qgjN+vFOK0ZeL0V2aGtRp1OXZCRl4ei2g5Tb4f01FfRLbbX33jIOuA30rD0p5Z0joAoznQxoTjgA7Kk64DCmH5/ZCZINSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NYcYVq2c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NYcYVq2c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 330A8C4CEEB; Wed, 13 Aug 2025 10:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755081023; bh=vDPhAaa14SEPGFOTgtOyQn/Sq2qo0iYZvFtBPzZ4t1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NYcYVq2cYeyg33K6b1yGD/Zb67bkv0TNBDV+giZjQ0RtN1ktgtRkN08z+/S0klgge 0YlSe+Vfm2kjFp09yuHClNnGrnpWilfZfALso27/9W3WxDW7hJbHKdrrWDtjjqZdbd opNc9/y1IQ64OvOT+D+cgTiglF7ocmEGLqPEjda+EBP4RDRIRJ8rY3iyKZknbyZ4E+ aOATNkv4klY+xnvZJXnjNA1v3apd2FCJe2rdliM3tAawBhSyrVLwc3iQ9gwr9sE1xR 1c07GU1MfRjktDlkMP/654kiFcoxXsp398SJng6Tj1TwZRqPWE0tJE4/cqIVrSlaPX rR2e2V8hGYz/w== From: "Rafael J. Wysocki" To: Linux PM Cc: Frederic Weisbecker , LKML , Peter Zijlstra , Christian Loehle Subject: [PATCH v1 3/3] cpuidle: governors: menu: Special-case nohz_full CPUs Date: Wed, 13 Aug 2025 12:29:51 +0200 Message-ID: <2244365.irdbgypaU6@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <2804546.mvXUDI8C0e@rafael.j.wysocki> References: <2804546.mvXUDI8C0e@rafael.j.wysocki> 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 Content-Type: text/plain; charset="utf-8" From: Rafael J. Wysocki When the menu governor runs on a nohz_full CPU and there are no user space timers in the workload on that CPU, it ends up selecting idle states with target residency values above TICK_NSEC all the time due to a tick_nohz_tick_stopped() check designed for a different use case. Namely, on nohz_full CPUs the fact that the tick has been stopped does not actually mean anything in particular, whereas in the other case it indicates that previously the CPU was expected to be idle sufficiently long for the tick to be stopped, so it is not unreasonable to expect it to be idle beyond the tick period length again. =20 In some cases, this behavior causes latency in the workload to grow undesirably. It may also cause the workload to consume more energy than necessary if the CPU does not spend enough time in the selected deep idle states. Address this by amending the tick_nohz_tick_stopped() check in question with a tick_nohz_full_cpu() one to avoid using the time till the next timer event as the predicted_ns value all the time on nohz_full CPUs. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/menu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -293,8 +293,18 @@ * in a shallow idle state for a long time as a result of it. In that * case, say we might mispredict and use the known time till the closest * timer event for the idle state selection. + * + * However, on nohz_full CPUs the tick does not run as a rule and the + * time till the closest timer event may always be effectively infinite, + * so using it as a replacement for the predicted idle duration would + * effectively always cause the prediction results to be discarded and + * deep idle states to be selected all the time. That might introduce + * unwanted latency into the workload and cause more energy than + * necessary to be consumed if the discarded prediction results are + * actually accurate, so skip nohz_full CPUs here. */ - if (tick_nohz_tick_stopped() && predicted_ns < TICK_NSEC) + if (tick_nohz_tick_stopped() && !tick_nohz_full_cpu(dev->cpu) && + predicted_ns < TICK_NSEC) predicted_ns =3D data->next_timer_ns; =20 /*