From nobody Sun Oct 5 00:08:43 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 8F6F96A8D2; Mon, 11 Aug 2025 15:03:21 +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=1754924601; cv=none; b=mGt2t4kYn/Qg63zJcK78ZAZwy5THafa1xMfRT1lt977cIQRW+93H9iXoKw4IVvxsedfjsQdpMw2lTWbL/pl808DFXAolApMBhtkc7+NxEjdJxjnhKUQIVYd8eG/V7bfooWhEpgDFgxHLSbkx5x1U43OiS1OV3VaRQKGDIA0/tUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754924601; c=relaxed/simple; bh=zH3Xr4/8gJV2SChW0xUKH3jzlpgJZI6xap1AHoXTOnE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=MuLtiF3UoX/IGz4/nUC9/Ptvmsi7LDcKHzQt/ZbAURuK2HwiXo5fzHZUTKF5GCgT+jZenbewOAIvTufAdZM3e50f18JnfU5qr3ecGKdw5mgPidk5YkMH7i7+GYeZ14Vq93RqVrDn+5nK50wy0uMVY6XSwlaE3ir5Ws2BtJySVPI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DH/ynZYC; 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="DH/ynZYC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DE6BC4CEED; Mon, 11 Aug 2025 15:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754924601; bh=zH3Xr4/8gJV2SChW0xUKH3jzlpgJZI6xap1AHoXTOnE=; h=From:To:Cc:Subject:Date:From; b=DH/ynZYCs8+d8JPMciiByh6+fpomeBGINIb88dTAM54Rg4feOgpEFufU0KX7o6gZE W7+IhEnkGBxrt05CBqLVTrW/KTr/IyUoY0NGkbyKQLZbSOAZRVIH96sjhMkACmfynZ x9zQZtv0HJ0/iCPLcXjNxM2mucbwDMCtwWUR3TG0Z1yrfdZipwF521PTEJ3eCFhLtW dyHe+euR/48F7x1wYgl2yN0tr2q0z0g7mOzGRZBHq8mOG6rR+n27312OYbyS/by1aI 4E4ukXnJRVC2Kapa6XjuPXKyBErIp4YIAl3sZJxjmPCFYektTvbyo+zGGmhgPeE+uo kURCTDvNlY2cw== From: "Rafael J. Wysocki" To: Linux PM Cc: Christian Loehle , Marc Zyngier , LKML , Artem Bityutskiy , Aboorva Devarajan Subject: [PATCH v1] cpuidle: governors: menu: Avoid using invalid recent intervals data Date: Mon, 11 Aug 2025 17:03:11 +0200 Message-ID: <2793874.mvXUDI8C0e@rafael.j.wysocki> Organization: Linux Kernel Development 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 Marc has reported that commit 85975daeaa4d ("cpuidle: menu: Avoid discarding useful information") caused the number of wakeup interrupts to increase on an idle system [1], which was not expected to happen after merely allowing shallower idle states to be selected by the governor in some cases. However, on the system in question, all of the idle states deeper than WFI are rejected by the driver due to a firmware issue [2]. This causes the governor to only consider the recent interval duriation data corresponding to attempts to enter WFI that are successful and the recent invervals table is filled with values lower than the scheduler tick period. Consequently, the governor predicts an idle duration below the scheduler tick period length and avoids stopping the tick more often which leads to the observed symptom. Address it by modifying the governor to update the recent intervals table also when entering the previously selected idle state fails, so it knows that the short idle intervals might have been the minority had the selected idle states been actually entered every time. Fixes: 85975daeaa4d ("cpuidle: menu: Avoid discarding useful information") Link: https://lore.kernel.org/linux-pm/86o6sv6n94.wl-maz@kernel.org/ [1] Link: https://lore.kernel.org/linux-pm/7ffcb716-9a1b-48c2-aaa4-469d0df7c792= @arm.com/ [2] Signed-off-by: Rafael J. Wysocki Tested-by: Christian Loehle Tested-by: Marc Zyngier Reviewed-by: Christian Loehle --- drivers/cpuidle/governors/menu.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -97,6 +97,14 @@ =20 static DEFINE_PER_CPU(struct menu_device, menu_devices); =20 +static void menu_update_intervals(struct menu_device *data, unsigned int i= nterval_us) +{ + /* Update the repeating-pattern data. */ + data->intervals[data->interval_ptr++] =3D interval_us; + if (data->interval_ptr >=3D INTERVALS) + data->interval_ptr =3D 0; +} + static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device = *dev); =20 /* @@ -222,6 +230,14 @@ if (data->needs_update) { menu_update(drv, dev); data->needs_update =3D 0; + } else if (!dev->last_residency_ns) { + /* + * This happens when the driver rejects the previously selected + * idle state and returns an error, so update the recent + * intervals table to prevent invalid information from being + * used going forward. + */ + menu_update_intervals(data, UINT_MAX); } =20 /* Find the shortest expected idle interval. */ @@ -482,10 +498,7 @@ =20 data->correction_factor[data->bucket] =3D new_factor; =20 - /* update the repeating-pattern data */ - data->intervals[data->interval_ptr++] =3D ktime_to_us(measured_ns); - if (data->interval_ptr >=3D INTERVALS) - data->interval_ptr =3D 0; + menu_update_intervals(data, ktime_to_us(measured_ns)); } =20 /**