You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vm/devices/chipset/src/cmos_rtc.rs saves the CMOS register array (state.cmos), clock_time_millis, and time_valid, but omits runtime sub-second timer deadlines and phase state. Restoring an RTC therefore alters guest-observable timing in five related ways:
Lost pending alarm within its matching second (run-1-rtc-3): Rtc::set_alarm_timer reconstructs the alarm timeout from whole-second CMOS calendar fields:
If an alarm is armed for 00:01:00 (at VM time 60.200s) and the snapshot is taken at 00:01:00.100 (60.100s) before the alarm fires, the restored calendar already matches 00:01:00, so calculate_alarm_duration schedules the next alarm 24 hours later instead of 100 ms later.
Periodic and update-ended timer phase reset (run-1-rtc-1): During Rtc::restore, update_timers calls set_periodic_timer() and set_update_timer(), which start fresh full periods from the current VmTime instead of preserving the remaining sub-period deadline.
Synthetic Status Register A UIP transition on first read (run-1-rtc-2): Rtc::get_status_byte tracks the 1-second update-in-progress (UIP) blip window using a runtime-only field self.last_update_bit_blip, which defaults to 0 on a fresh Rtc instance and is not saved in SavedState. The first Status A read after restore therefore sees elapsed_millis > 1000 and triggers a synthetic UIP blip and sync_clock_to_cmos().
Cached CMOS calendar byte refresh during restore (run-1-rtc-4): When an alarm is enabled, Rtc::restore -> update_timers -> set_alarm_timer calls sync_clock_to_cmos(), overwriting the saved state.cmos calendar cache. Because Rtc::set_cmos_byte ignores writes where data == self.state.cmos[addr], refreshing the cache during restore changes whether a subsequent guest byte write is treated as a no-op or a clock update.
Wall-clock drift while VM time is stopped (run-1-rtc-7): SystemTimeClock continues advancing with host wall time between VmTime stop and Rtc::save, and again between Rtc::restore_clock and Rtc::advance_clock, so applying downtime adds intervals already elapsed on the host clock.
Proposed Fix
Decide which sub-second RTC invariants the snapshot contract guarantees. To preserve pending alarms, periodic/update timer phases, and UIP behavior without mutating cached CMOS bytes on restore, include optional deadline/phase fields in cmos_rtc::save_restore::state::SavedState (with a fallback to current rearming behavior for older snapshots).
Sample and restore the RTC epoch at the same stopped boundary as VmTime so host save/restore work is not double-counted alongside explicit downtime advancement.
Activity
openvmm: pin the RTC's snapshot time and timer phases