5

I'm having trouble keeping the system clocks sync'd on a number of kvm guests. I've googled a fair bit, and found a lot of different options, many of which I've tried, to no avail. So here I am.

ntpd is out of the question (the host system runs it and the clock is always correct, but if you run it on the guests, the clock goes way out of whack).

The host is Ubuntu 9.04, kernel is 2.6.28-11-server The guests are Ubuntu 8.04, kernel 2.6.24-24-virtual

Here's the clocksource situation on the host:

# cat /sys/devices/system/clocksource/clocksource0/available_clocksource 
tsc hpet acpi_pm jiffies 
# cat /sys/devices/system/clocksource/clocksource0/current_clocksource 
tsc

And on the guest:

# cat /sys/devices/system/clocksource/clocksource0/available_clocksource 
tsc pit jiffies 
# cat /sys/devices/system/clocksource/clocksource0/current_clocksource 
pit 

I've got "clock=pit divider=10" in the kernel boot parameters on the guest. It still drifts. We're not talking massive drifts, but there is some.

Any suggestions? Has anyone had this problem and dealt with it?

DictatorBob
  • 1,614
  • 11
  • 15

3 Answers3

2

The best option for a precise clock on the guest is to use the kvm-clock source (pvclock) which is synchronized with clock's host.

nicob
  • 84
  • 2
  • This is a good answer for newer systems, but is not available on older ones. – mattdm Dec 07 '10 at 15:46
  • When does the guest sync with the hardware clock, isn't it only on boot? I don't think the clock source affects drift. –  Jun 06 '15 at 05:48
2

Fundamentally the clock is going to drift some, I think there is a limit to what can be done at this time. You say that you don't run NTP in the guests but I think that is what you should do, just make sure that you aren't referencing the local clock (comment out server 127.x.x.x) and that tinker panic 0 is set so that it won't freak out if there are large jumps it has to correct for. Thats basically the guidelines from the VMWare timekeeping paper and I would guess largely applicable to a KVM setup as well.

mtinberg
  • 1,803
  • 10
  • 9
  • Hmm... I vaguely remember being told that when we did put ntp on the guests (pointing to a real ntp server, not localhost), the clock occasionally went completely haywire, setting the time backwards something like 20 years... That's all anecdotal though... maybe I'll give it another try myself and see what happens. – DictatorBob Oct 13 '09 at 17:08
1

Here is a link to the VMware paper "Timekeeping in VMware Virtual Machines" (2008): http://www.vmware.com/pdf/vmware_timekeeping.pdf

Ted
  • 159
  • 4