kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Question: Timekeeping between Host and Guest with NTP
@ 2012-08-22  8:46 Aritoki TAKADA
  2012-08-23 18:13 ` Marcelo Tosatti
  0 siblings, 1 reply; 5+ messages in thread
From: Aritoki TAKADA @ 2012-08-22  8:46 UTC (permalink / raw)
  To: kvm; +Cc: ltc-kernel

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 kvm@vger.kernel.org:

  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
aritoki.takada.jt@hitachi.com
Hitachi, Ltd., Yokohama Research Laboratory

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Question: Timekeeping between Host and Guest with NTP
  2012-08-22  8:46 Question: Timekeeping between Host and Guest with NTP Aritoki TAKADA
@ 2012-08-23 18:13 ` Marcelo Tosatti
  2012-08-24 11:43   ` Aritoki TAKADA
  0 siblings, 1 reply; 5+ messages in thread
From: Marcelo Tosatti @ 2012-08-23 18:13 UTC (permalink / raw)
  To: Aritoki TAKADA; +Cc: kvm, ltc-kernel

On Wed, Aug 22, 2012 at 05:46:52PM +0900, Aritoki TAKADA wrote:
> 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 kvm@vger.kernel.org:
> 
>   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,

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Question: Timekeeping between Host and Guest with NTP
  2012-08-23 18:13 ` Marcelo Tosatti
@ 2012-08-24 11:43   ` Aritoki TAKADA
  2012-08-24 15:00     ` Marcelo Tosatti
  0 siblings, 1 reply; 5+ messages in thread
From: Aritoki TAKADA @ 2012-08-24 11:43 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm, ltc-kernel

Thank you for your comment,

(2012/08/24 3:13), Marcelo Tosatti wrote:
<snip>
> 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,

-- 
Aritoki TAKADA
aritoki.takada.jt@hitachi.com
Hitachi, Ltd., Yokohama Research Laboratory

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Question: Timekeeping between Host and Guest with NTP
  2012-08-24 11:43   ` Aritoki TAKADA
@ 2012-08-24 15:00     ` Marcelo Tosatti
  2012-08-27  9:37       ` Aritoki TAKADA
  0 siblings, 1 reply; 5+ messages in thread
From: Marcelo Tosatti @ 2012-08-24 15:00 UTC (permalink / raw)
  To: Aritoki TAKADA; +Cc: kvm, ltc-kernel

On Fri, Aug 24, 2012 at 08:43:49PM +0900, Aritoki TAKADA wrote:
> Thank you for your comment,
> 
> (2012/08/24 3:13), Marcelo Tosatti wrote:
> <snip>
> >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?

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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Question: Timekeeping between Host and Guest with NTP
  2012-08-24 15:00     ` Marcelo Tosatti
@ 2012-08-27  9:37       ` Aritoki TAKADA
  0 siblings, 0 replies; 5+ messages in thread
From: Aritoki TAKADA @ 2012-08-27  9:37 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm, ltc-kernel

Hello,

(2012/08/25 0:00), Marcelo Tosatti wrote:
<snip>

> 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.

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
aritoki.takada.jt@hitachi.com
Hitachi, Ltd., Yokohama Research Laboratory

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-27  9:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-22  8:46 Question: Timekeeping between Host and Guest with NTP Aritoki TAKADA
2012-08-23 18:13 ` Marcelo Tosatti
2012-08-24 11:43   ` Aritoki TAKADA
2012-08-24 15:00     ` Marcelo Tosatti
2012-08-27  9:37       ` Aritoki TAKADA

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).