mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] PM-runtime: fix denying of auto suspend in pm_suspend_timer_fn
@ 2025-05-15  6:41 Charan Teja Kalla
  2025-05-16 20:06 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Charan Teja Kalla @ 2025-05-15  6:41 UTC (permalink / raw)
  To: rafael, len.brown, pavel, gregkh, dakr
  Cc: linux-pm, linux-kernel, Charan Teja Kalla, Patrick Daly

pm_runtime_put_autosuspend() schedules a hrtimer to expire at
"dev->power.timer_expires". If the hrtimer's callback -
pm_suspend_timer_fn - observes that the current time equals
"dev->power.timer_expires", it unexpectedly bails out instead of
proceeding with runtime suspend.

pm_suspend_timer_fn():
if (expires > 0 && expires < ktime_get_mono_fast_ns()) {
	dev->power.timer_expires = 0;
	rpm_suspend(..)
}

Additionally, as ->timer_expires is not cleared, all the future auto
suspend requests will not schedule hrtimer to perform auto suspend.

rpm_suspend():
if ((rpmflags & RPM_AUTO) &&...) {
     if (!(dev->power.timer_expires && ...) { <-- this will fail.
	hrtimer_start_range_ns(&dev->power.suspend_timer,...);
  }
}

Fix this by aswell checking if current time reaches the set expiration.

Co-developed-by: Patrick Daly <quic_pdaly@quicinc.com>
Signed-off-by: Patrick Daly <quic_pdaly@quicinc.com>
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
---
 drivers/base/power/runtime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 205a4f8828b0..c55a7c70bc1a 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1011,7 +1011,7 @@ static enum hrtimer_restart  pm_suspend_timer_fn(struct hrtimer *timer)
 	 * If 'expires' is after the current time, we've been called
 	 * too early.
 	 */
-	if (expires > 0 && expires < ktime_get_mono_fast_ns()) {
+	if (expires > 0 && expires <= ktime_get_mono_fast_ns()) {
 		dev->power.timer_expires = 0;
 		rpm_suspend(dev, dev->power.timer_autosuspends ?
 		    (RPM_ASYNC | RPM_AUTO) : RPM_ASYNC);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-18  6:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-15  6:41 [PATCH] PM-runtime: fix denying of auto suspend in pm_suspend_timer_fn Charan Teja Kalla
2025-05-16 20:06 ` Rafael J. Wysocki
2025-05-18  6:43   ` Charan Teja Kalla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®