[libvirt-users] Time syncing after VM suspend/resume

Hi all. When resuming guest after suspend, the time is wrong (because the guest doesn't know it has been suspended). Apparently, ntp running on the guest doesn't solve this. At least on Linux system. I read it works on Windows guests. I don't understand why, so I'd appreciate a link to an explanation, but I understand it is out of scope for this list. The HW clock is correct and the guest agent is setup to use kvm-clock. Using the guest-set-time command does set the clock on the guest according to the host. But this is not triggered automatically on resume. I found discussions about this, even a patch proposal to call guest-set-time on resume, but all of this is one year old and I can't find any newer information. http://serverfault.com/questions/334698/how-to-keep-time-on-resumed-kvm-gues... https://www.redhat.com/archives/libvirt-users/2014-October/msg00009.html https://www.redhat.com/archives/libvir-list/2014-February/msg00520.html Is there any fresher information I have missed ? Thanks. -- Jérôme

-----Oorspronkelijk bericht----- Van: libvirt-users-bounces@redhat.com [mailto:libvirt-users- bounces@redhat.com] Namens Jérôme Verzonden: woensdag 23 september 2015 15:03 Aan: libvirt-users@redhat.com Onderwerp: [libvirt-users] Time syncing after VM suspend/resume
Hi all.
When resuming guest after suspend, the time is wrong (because the guest doesn't know it has been suspended).
Apparently, ntp running on the guest doesn't solve this. At least on Linux system. I read it works on Windows guests. I don't understand why, so I'd appreciate a link to an explanation, but I understand it is out of scope for this list.
Linux has two methods to use ntp: ntpdate: It will run once at boot time to sync time. (This is probably installed on your system) It will not run after suspend and resume... => no correction ntpd: Continuously adjusts time. The deamon also calculates the drift to anticipate differences. I use this one and works perfectly.
The HW clock is correct and the guest agent is setup to use kvm-clock.
Using the guest-set-time command does set the clock on the guest according to the host. But this is not triggered automatically on resume.
I found discussions about this, even a patch proposal to call guest-set-time on resume, but all of this is one year old and I can't find any newer information.
http://serverfault.com/questions/334698/how-to-keep-time-on-resumed-kvm- guest-with-libvirt https://www.redhat.com/archives/libvirt-users/2014-October/msg00009.html https://www.redhat.com/archives/libvir-list/2014-February/msg00520.html
Is there any fresher information I have missed ?
Thanks.
-- Jérôme
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users

Hi. Thanks for answering. Le 2015-09-23 17:34, Dominique Ramaekers a écrit :
Linux has two methods to use ntp:
ntpdate: It will run once at boot time to sync time. (This is probably installed on your system) It will not run after suspend and resume... => no correction
Nope. This is not installed on my system.
ntpd: Continuously adjusts time. The deamon also calculates the drift to anticipate differences. I use this one and works perfectly.
This is installed (package ntp, Debian Jessie) and runs (I see /usr/sbin/ntpd in `ps aux`). But after more than 24h, the 2'17 gap between hwclock and date has not reduced a bit. I guess this is not the place for me to debug my ntp issues, apart maybe from what could be related to the virtualization itself. I understood from my readings (can't remember where precisely) that the fact that ntp wouldn't work was "normal", but if it is not, maybe trying to have it working is the way to go, rather than searching for a way to automatize guest-set-time. -- Jérôme

Look into the "panic" option to ntpd - once the gap gets to big (such as when the VM is suspended for a few hours) it goes into freewheel and doesn't sync - its in the ntp docs. ntpd doesn't work well (you get ages where a machine is way out of date, or fails to sync ever. I run either chrony (same problem) or ntpd and run a script on startup to restart guest ntp/chrony from the host via ssh. I don't think serious users suspend vm's much or this would have been fixed long ago. BillK On 23/09/15 23:44, Jérôme wrote:
Hi.
Thanks for answering.
Le 2015-09-23 17:34, Dominique Ramaekers a écrit :
Linux has two methods to use ntp:
ntpdate: It will run once at boot time to sync time. (This is probably installed on your system) It will not run after suspend and resume... => no correction
Nope. This is not installed on my system.
ntpd: Continuously adjusts time. The deamon also calculates the drift to anticipate differences. I use this one and works perfectly.
This is installed (package ntp, Debian Jessie) and runs (I see /usr/sbin/ntpd in `ps aux`). But after more than 24h, the 2'17 gap between hwclock and date has not reduced a bit.
I guess this is not the place for me to debug my ntp issues, apart maybe from what could be related to the virtualization itself.
I understood from my readings (can't remember where precisely) that the fact that ntp wouldn't work was "normal", but if it is not, maybe trying to have it working is the way to go, rather than searching for a way to automatize guest-set-time.

Le Thu, 24 Sep 2015 05:32:45 +0800, Bill Kenworthy <billk@iinet.net.au> a écrit :
Look into the "panic" option to ntpd - once the gap gets to big (such as when the VM is suspended for a few hours) it goes into freewheel and doesn't sync - its in the ntp docs.
My use case is when rebooting the host (after a kernel update, for instance). The gap is about 2 minutes.
ntpd doesn't work well (you get ages where a machine is way out of date, or fails to sync ever. I run either chrony (same problem) or ntpd and run a script on startup to restart guest ntp/chrony from the host via ssh.
The guest-set-time command from the host works as well (but requires guest agent). I just don't know how to launch it automatically on guest resume.
I don't think serious users suspend vm's much or this would have been fixed long ago.
Interesting answer. I figured that while interrupting the host for a few minutes, suspending the guest could be a nicer option. I may be wrong. Anyway, the host shall not be rebooted that often, and I think if I don't find any satisfying answer, I may choose guest shutdown instead of suspend. In practice, my guests will likely have the same OS version, therefore the same updates and the same reboot needs. There's no point suspending a guest when rebooting the host if the guest must be rebooted anyway. -- Jérôme

On Wed, 2015-09-23 at 23:54 +0200, Jérôme wrote:
Le Thu, 24 Sep 2015 05:32:45 +0800, Bill Kenworthy <billk@iinet.net.au> a écrit :
Look into the "panic" option to ntpd - once the gap gets to big (such as when the VM is suspended for a few hours) it goes into freewheel and doesn't sync - its in the ntp docs.
My use case is when rebooting the host (after a kernel update, for instance). The gap is about 2 minutes.
ntpd doesn't work well (you get ages where a machine is way out of date, or fails to sync ever. I run either chrony (same problem) or ntpd and run a script on startup to restart guest ntp/chrony from the host via ssh.
The guest-set-time command from the host works as well (but requires guest agent). I just don't know how to launch it automatically on guest resume.
I don't think serious users suspend vm's much or this would have been fixed long ago.
Interesting answer.
I figured that while interrupting the host for a few minutes, suspending the guest could be a nicer option. I may be wrong.
Anyway, the host shall not be rebooted that often, and I think if I don't find any satisfying answer, I may choose guest shutdown instead of suspend.
In practice, my guests will likely have the same OS version, therefore the same updates and the same reboot needs. There's no point suspending a guest when rebooting the host if the guest must be rebooted anyway.
VMWare has the same problem[1], and as someone else said 'tinker panic 0' should fix it. It's worked for me in the past. See the NTP Recommendations section in: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cm d=displayKC&externalId=1006427

On 23.09.2015 15:03, Jérôme wrote:
Hi all.
When resuming guest after suspend, the time is wrong (because the guest doesn't know it has been suspended).
Apparently, ntp running on the guest doesn't solve this. At least on Linux system. I read it works on Windows guests. I don't understand why, so I'd appreciate a link to an explanation, but I understand it is out of scope for this list.
The HW clock is correct and the guest agent is setup to use kvm-clock.
Using the guest-set-time command does set the clock on the guest according to the host. But this is not triggered automatically on resume.
I found discussions about this, even a patch proposal to call guest-set-time on resume, but all of this is one year old and I can't find any newer information.
http://serverfault.com/questions/334698/how-to-keep-time-on-resumed-kvm-gues... https://www.redhat.com/archives/libvirt-users/2014-October/msg00009.html https://www.redhat.com/archives/libvir-list/2014-February/msg00520.html
Is there any fresher information I have missed ?
You can use "virsh resume $dom && virsh domtime --sync $dom" which will resume and resync the domain's clock from domain RTC. There were some attempts to wrap these into a single API, however, I was persuaded that it's a wrong idea. Wrapping two distinct operations into a single API is always wrong. Michal
participants (5)
-
Bill Kenworthy
-
Dominique Ramaekers
-
Jérôme
-
Mark Clarkson
-
Michal Privoznik