Question: Timekeeping between Host and Guest with NTP
Hello,
I'm planning to configure timekeeping between KVM host and guest, but I'm confused by different suggestions.
The point is whether NTP should be working on guest or not.
Here are the suggestions I found.
Red Hat document:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/chap-Virtualization_Host_Configuration_and_Guest_Installation_Guide-KVM_guest_timing_management.html
kvmclock : recommended if available
NTP on host : recommended
NTP on guest : recommended
Suse document:
http://doc.opensuse.org/documentation/html/openSUSE/opensuse-kvm/cha.libvirt.config.html#sec.kvm.managing.clock
kvmclock : recommended if available
NTP on host : recommended
NTP on guest : NOT recommended when using kvmclock
Ubuntu document:
https://help.ubuntu.com/community/KVM/FAQ#Should_ntp_be_used_for_time_synchronisation.3F
kvmclock : not mentioned
NTP on host : not mentioned
NTP on guest : NOT recommended
Previous discussions I found on [email protected]:
Dor Laor from Red Hat says the same as the Red Hat document.
http://marc.info/?l=kvm&m=130881067913835&w=4
John Buswell and Athanasius discussed another technique, which uses not NTP but RTC from guest to keep guest syncing to host, but they say it isn't the best way.
http://marc.info/?l=kvm&m=127230166532133&w=4
I just tried with CentOS 6.3 as both host and guest OS, whose kernels were replaced with 3.5.2 from upstream.
I found the guest has a little delay when booted,
which is about one or two seconds.
Without NTP on the guest, the delay seemed
constant while running.
I think NTP on the guest will fix the delay,
but I'm afraid there would be some reasons
that NTP should not be on the guest.
If you know why NTP should (not) be running on
guest, please let me know.
Thank you in advance,
--
Aritoki TAKADA
[email protected]
Hitachi, Ltd., Yokohama Research Laboratory
Quoted 47 lines · Aritoki TAKADA
Hello,
I'm planning to configure timekeeping between KVM host and guest, but I'm confused by different suggestions.
The point is whether NTP should be working on guest or not.Here are the suggestions I found.
Red Hat document:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/chap-Virtualization_Host_Configuration_and_Guest_Installation_Guide-KVM_guest_timing_management.html
kvmclock : recommended if available
NTP on host : recommended
NTP on guest : recommendedSuse document:
http://doc.opensuse.org/documentation/html/openSUSE/opensuse-kvm/cha.libvirt.config.html#sec.kvm.managing.clock
kvmclock : recommended if available
NTP on host : recommended
NTP on guest : NOT recommended when using kvmclockUbuntu document:
https://help.ubuntu.com/community/KVM/FAQ#Should_ntp_be_used_for_time_synchronisation.3F
kvmclock : not mentioned
NTP on host : not mentioned
NTP on guest : NOT recommendedPrevious discussions I found on [email protected]:
Dor Laor from Red Hat says the same as the Red Hat document.
http://marc.info/?l=kvm&m=130881067913835&w=4John Buswell and Athanasius discussed another technique, which uses not NTP but RTC from guest to keep guest syncing to host, but they say it isn't the best way.
http://marc.info/?l=kvm&m=127230166532133&w=4I just tried with CentOS 6.3 as both host and guest OS, whose kernels were replaced with 3.5.2 from upstream.
I found the guest has a little delay when booted,
which is about one or two seconds.
Without NTP on the guest, the delay seemed
constant while running.
Quoted 8 lines
I think NTP on the guest will fix the delay,
but I'm afraid there would be some reasons
that NTP should not be on the guest.If you know why NTP should (not) be running on
guest, please let me know.Thank you in advance,
NTP should be running in the guest so as to synchronize the guest time-of-day clocks to UTC.
kvmclock exposes the monotonic clock from the host. The frequency of the host monotonic clock is corrected by host ntpd. This is probably where the confusion comes from.
That is no guarantee that time-of-day clocks in the guest are synchronized to UTC or even that clock frequency visible to userspace applications in the guest is equal to the monotonic clock frequency of the host.
Thank you for your comment,
(2012/08/24 3:13), Marcelo Tosatti wrote:
<snip>
Quoted 11 lines
NTP should be running in the guest so as to synchronize the guest time-of-day clocks to UTC.
kvmclock exposes the monotonic clock from the host. The frequency of the host monotonic clock is corrected by host ntpd. This is probably where the confusion comes from.
That is no guarantee that time-of-day clocks in the guest are synchronized to UTC or even that clock frequency visible to userspace applications in the guest is equal to the monotonic clock frequency of the host.
I understood your comment except one point.
We know that the frequency of host monotonic clock is kept accurate by host ntpd and that kvmclock shows it to the guest. Doesn't this mean that applications in the guest can see the accurate clock frequency provided by the host?
Sincerely,
Signature · 3 lines
Aritoki TAKADA [email protected] Hitachi, Ltd., Yokohama Research Laboratory
Quoted 16 lines · Aritoki TAKADA
Thank you for your comment,
(2012/08/24 3:13), Marcelo Tosatti wrote:
<snip>Quoted 11 lines
NTP should be running in the guest so as to synchronize the guest time-of-day clocks to UTC.
kvmclock exposes the monotonic clock from the host. The frequency of the host monotonic clock is corrected by host ntpd. This is probably where the confusion comes from.
That is no guarantee that time-of-day clocks in the guest are synchronized to UTC or even that clock frequency visible to userspace applications in the guest is equal to the monotonic clock frequency of the host.
Quoted 5 lines
I understood your comment except one point.
We know that the frequency of host monotonic clock is kept accurate by host ntpd and that kvmclock shows it to the guest. Doesn't this mean that applications in the guest can see the accurate clock frequency provided by the host?
kvmclock driver has access to the ntpd corrected frequency of the host, but:
1) kvmclock time as reported to the guest uses the TSC as an offset in addition to the host monotonic clock, TSC is susceptible to frequency variations.
The guest has its own timekeeping (it accumulates time from kvmclock, at every timer interrupt). The algorithm is not
perfect, and its suspectible to small variations.
These add up over time.
2) Corrections to UTC, such as leap seconds, are not reflected to the host monotonic clock. NTP algorithm in the guest is responsible for synchronization to UTC.
Hello,
(2012/08/25 0:00), Marcelo Tosatti wrote:
<snip>
Quoted 10 lines
kvmclock driver has access to the ntpd corrected frequency of the host, but:
1) kvmclock time as reported to the guest uses the TSC as an offset in addition to the host monotonic clock, TSC is susceptible to frequency variations.
The guest has its own timekeeping (it accumulates time from kvmclock, at every timer interrupt). The algorithm is not
perfect, and its suspectible to small variations.
Quoted 5 lines
These add up over time.
2) Corrections to UTC, such as leap seconds, are not reflected to the host monotonic clock. NTP algorithm in the guest is responsible for synchronization to UTC.
I see, I understood the pitfalls of the guest only syncing to kvmclock, and now NTP on the guest seems simple and reasonable for me. Thank you again for your detailed explanation.
Sincerely,
---
Aritoki TAKADA
[email protected]
Hitachi, Ltd., Yokohama Research Laboratory