[ntp:questions] three questions about ntpd, kvm-clock and clock speeds
brontolinux at gmail.com
Thu Oct 30 15:06:03 UTC 2014
Apologies for this question not being 100% pertinent to ntpd, but I'd
need an authoritative answer and there is no place like this list to
find real expert of computer clocks and time synchronization. Too many
wannabes and professed experts out there.
I have some empirical experience about clock synchronization in KVM
environments on Linux that can definitely use the scrutiny of
knowledgeable eyes to be properly confirmed or refuted.
On the web many (supposedly) authoritative sources disagree about how
clocks should be synced on KVM hosts and VMs. You can find both those
who say that ntpd should run on both sides and others that advise for
having ntpd just on the host and have the VMs use the kvm-clock
clocksource to "follow" the host's clock (but they don't say what
"follow" exactly means). I am part of the latter current of thought and
that's how we usually set our VMs.
However, we saw a number of VMs that, once set to use kvm-clock set,
didn't correct their offset, which seemed to stay more or less constant
compared to the host's clock. A further check showed how the system
clock on the VM was also offset from the VM's "hardware clock". This
latter finding is no surprise: it's quite normal that the hardware clock
and the system clock can drift apart if there is no external
intervention to keep them in sync.
In turn, the VM's hardware clock could be offset from the host's
hardware clock (which is in sync with the host system clock via ntpd). I
don't know why it is but that can make sense, too, since you want the
two clocks to evolve in the same way over time (have the same "speed")
while they must be able to sport different times (e.g.: the hw clock on
the host may be set to UTC while the one on the VM could be set to
localtime). This accounts for a first question:
Q1: is this what happens when using the kvm-clock clocksource? That is:
does it sync the speed of the two hardware clocks leaving the time on
the clocks independent?
In that case, "follow" would mean "run at the same speed, may have a
I didn't collect any data but so far it turned out that, once syncing
the VM's system clock to a reliable source via ntpdate, and then syncing
the VM's hardware clock with the system clock via hwclock --systohc,
everything seems to stay in sync, which makes for the second question:
Q2: when using the kvm-clock clocksource and assuming that the answer
for Q1 is positive, is the "speed" of the VM's system clock also synced
with the hardware clocks'?
If so, then everything is cut and dry: with the kvm-clock clocksource
host hw clock speed == VM hw clock speed == VM sys clock speed
And putting ntp and ntpd in the picture:
time from ntpd --> host sys clock --> host hw clock
so that if we align the time on the VM's clock with the time from an NTP
NTP time --[ntpdate]-> VM sys clock --[hwclock --systohc]-> VM hw clock
then we'd have
VM sys clock ~~ host sys clock
Q3: how correct, or how wrong, is all this?
Thanks in advance for your wisdom
More information about the questions