Skip to content

alarmtimer: Reject suspend earlier when alarm is imminent

Samuel Wu linux-pm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4alarmtimer: Bound wakeup source timeout on suspend abortkernel/time/alarmtimer.c+18 -30 replies
2/4alarmtimer: Extract alarmtimer_get_next_delta() helperkernel/time/alarmtimer.c+44 -230 replies
3/4alarmtimer: Reject imminent-alarm suspend in PM_SUSPEND_PREPAREkernel/time/alarmtimer.c+32 -00 replies
4/4alarmtimer: Hold wakeup source on resume for imminent alarmskernel/time/alarmtimer.c+3 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] alarmtimer: Reject suspend earlier when alarm is imminent

alarmtimer_suspend() aborts suspend with -EBUSY when the next alarm is due in less than 2 seconds, and holds a wakeup source for a fixed 2 seconds. This is suboptimal:
- The check runs quite late in the suspend sequence. An abort means kernel spent time doing work it now has to undo.
- The fixed 2 second timeout has no relation to the time at which the alarm is due.

This patchseries addresses both problems:
- 1/4: Hold wakeup source with grace period (100ms) after alarm is due.
- 2/4: Move the lookup of soonest alarm into helper function
- 3/4: Add a PM notifier (earlier in suspend sequence) to do an imminent alarm check. This is the same idea as [1], but without the sysfs node.
- 4/4: Add alarm check in resume path, to handle wakeups that are earlier than the actual alarm, since RTC has up to 1s error compared to an alarm on hrtimer

With patch 3, the time spent on a suspend attempt that is aborted by an imminent alarm drops from:
- ~220 ms to ~20 ms on Pixel 9 (v7.3)
- ~90 ms to ~0.1 ms on Pixel Watch (v6.12)

With patch 4, aborted suspend attempts due to alarmtimer are noticeably lower.

[1]: https://lore.kernel.org/lkml/[email protected]/

Samuel Wu (4):
alarmtimer: Bound wakeup source timeout on suspend abort
alarmtimer: Extract alarmtimer_get_next_delta() helper
alarmtimer: Reject imminent-alarm suspend in PM_SUSPEND_PREPARE
alarmtimer: Hold wakeup source on resume for imminent alarms

 kernel/time/alarmtimer.c | 124 ++++++++++++++++++++++++++++++---------
 1 file changed, 97 insertions(+), 27 deletions(-)
Signature · 1 line
2.56.1.911.g883d8bcb20-goog