Linux
VERIFIED FIXES

systemd timer misses periodic jobs after resume — clock jumps forward on resume when host uses TSC as RTC

Environment

Environment

Ubuntu 22.04 laptop running systemd timers for backups and ACME renewals. Host suspends to RAM (S3) overnight. After resume, some timers are not triggered for up to several minutes and ACME renewal fails.

Symptoms

Symptoms

Jobs scheduled via systemd timers (OnCalendar and Persistent timers) either do not run at their expected time after resume or run with a large delay. systemd journal shows 'Stepped system clock forward by 1min 23s' and several timers show 'missed' entries. timedatectl shows that RTC and system time differ after resume.

Observations

Observations

dmesg shows platform resume then 'kvmclock: Syncing TSC' messages on VMs; host uses TSC as clocksource. systemd-timesyncd reports a large step adjustment shortly after resume. Some timers with AccuracySec=1min are not scheduled until systemd steps the clock. Timers with Persistent=true that should have run during sleep do not show RunOnCalender entries until after timesyncd step.

Already attempted

Already attempted

Swapped clocksource to hpet temporarily (echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource) then suspended and resumed — timers fired as expected. Enabled NTP in timesyncd and set NTP server, but step adjustments remain. Upgraded kernel to latest stable; behavior persists.

Question

Question

How to make systemd timers reliably fire immediately after resume without large clock steps, and avoid missed scheduled jobs following suspend/resume cycles?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
alexnord Answer
user
Posted 1mo ago • 0 confirmations

Most cases are caused by the kernel clocksource (TSC) producing a different time after suspend, so switch to a stable clocksource or use a timesync client that slews time. Quick test: sudo sh -c 'echo hpet > /sys/devices/system/clocksource/clocksource0/current_clocksource' then suspend/resume; if timers fire correctly, you can test making that persistent via kernel cmdline (clocksource=hpet) or prefer chrony instead of systemd-timesyncd to avoid large steps. Also ensure critical timers use Persistent=true and consider a small startup script to run missed work on resume. Roll back by removing the cmdline change or switching clocksource back to tsc if it causes regressions (some systems run worse with hpet).

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

TSC or chosen kernel clocksource produces an inconsistent time after suspend/resume causing systemd to step the clock and timers to be delayed 80%
systemd-timesyncd (or other NTP client) steps the clock abruptly after resume due to large offset, causing timers to be rescheduled 50%
Bug in kernel resume path or platform firmware leaving RTC inaccurate so kernel must correct time on resume 35%

Summary

systemd uses the system clock and relies on clocksource consistency. If the hardware TSC drifts or is not synchronized after suspend, kernel steps the clock on resume which can cause systemd to delay or 'miss' timer invocations. Using a steady clocksource (e.g., hpet or tsc stable on modern hardware) or ensuring timesyncd updates clock non-step (slew) can help. Persistent timers depend on systemd detecting missed elapses — but large immediate clock steps can confuse ordering. The working diagnostic (switching clocksource to hpet) confirms clocksource instability is likely root. Another contributor can be aggressive NTP step behavior.

Suggested Fixes

Diagnostic step 1
Test with alternative clocksource temporarily: echo hpet | sudo tee /sys/devices/system/clocksource/clocksource0/current_clocksource and suspend/resume to see if timers behave. If improved, consider making the change persistent or patching kernel cmdline with clocksource=hpet (use with caution on laptops where hpet may be slow).
Diagnostic step 2
Configure timesyncd/ntpd to prefer slew (no-step) corrections on resume if supported, or use chrony which handles slewing better: replace systemd-timesyncd with chrony and enable makestep/step-tolerance settings carefully.
Diagnostic step 3
Ensure systemd timers that must run immediately after resume use OnUnitActiveSec with Persistent=true as appropriate, and add OnCalendar as backup; add a small ExecStartPre check to catch missed work.

Continue troubleshooting

Matched from the title, description and tags