Fixing (Windows) time on resume in KVM


so we played around with Windows on OpenNebula a little more.
One thing that stood out was that if you suspend and resume a VM the hardware clock isn’t updated for the resume, and even with the guest agent installed, nothing fixes the clock, it’ll be still at the time of shutdown.

I think that’s not OK. I mean… _of course it’s not OK :slight_smile:
Imagine that happening inside a database cluster…
if you’re not at some startup where you can brag about how you found the error, then you’ll be glad if you just get fired over it!
So, I tried to see how to solve it… I searched for a few hours and so far I found out those things:

The libvirt way, and a Hook script

There’s a virsh command to “buff” the clock:
virsh domtime one-vmid --now

I’ll be honest and mention my libvirt doesn’t even have that flag :confused:

One person has apparently made a hook for this:

what time is it anyway?

There’s a KVM setting "localtime"
That means the HW clock will not be a UTC clock I think. Windows would like that, but it is not a default.
Supported since

anyone need some more settings?

This can be expanded further with other parameters:
clock offset=‘localtime’>
timer name=‘rtc’ tickpolicy=‘catchup’/>
timer name=‘pit’ tickpolicy=‘delay’/>
timer name=‘hpet’ present=‘no’/>

(I had to remove the opening braces since forum always tried to parse the XML…

This would be incompatible with the FEATURE flag and mean one needs to put it in the raw section.
I think “catchup” could be interesting.

Other thing people have tried is using cron / scheduler etc. to ntp sync their clocks. That’s kinda shitty and nothing I want to do on servers, unless there’s really no other way in the universe.

##So, please, tell me:

  • Did you fix this?
  • How did you fix this
  • Which approach is best for you?
  • Any comment about how the hook does it?

Side note

For Linux, as far as I could see it’s all fine IF, and only IF, you use the KVM clocksource, kvm-clock.
As a Xen user (at heart, not in this setup) I know that having a proper paravirtualized clock is utterly important for scalability. I checked my VMs for that, and it’s fine:
cat /sys/devices/system/clocksource/clocksource0/current_clocksource

For me, the easier way is using NTP to periodically sync the time.