[PATCH 4/4] alarmtimer: Hold wakeup source on resume for imminent alarms
From: Samuel Wu
Date: Tue Dec 01 2026 - 01:13:41 EST
The RTC can wake a device from suspend up to 1s before the alarm is due to
fire, because of the RTC's 1s granularity. This means during the resume
path of suspend, an alarm can be due within the next second.
So to prevent even starting a doomed suspend attempt, check for imminent
alarms and hold a wakeup source to appropriately gate future suspend
attempts. This also saves an unnecessary filesystem sync.
Failed suspend attempts due to alarmtimer are significantly reduced on a
Pixel 9 (v7.3) running Android, and QEMU x86_64 (v7.4) with kernel
autosleep.
Signed-off-by: Samuel Wu <wusamuel@xxxxxxxxxx>
---
kernel/time/alarmtimer.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e582c1c3127a..c9712d84f3f5 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -324,8 +324,10 @@ static int alarmtimer_resume(struct device *dev)
struct rtc_device *rtc;
rtc = alarmtimer_get_rtcdev();
- if (rtc)
+ if (rtc) {
rtc_timer_cancel(rtc, &rtctimer);
+ alarmtimer_wakeup_if_soon(dev, alarmtimer_get_next_delta(NULL, NULL));
+ }
return 0;
}
--
2.56.1.911.g883d8bcb20-goog