All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Avi Cohen <avi.cohen@huawei.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: KVM-Clock
Date: Tue, 23 Feb 2016 18:51:31 +0100	[thread overview]
Message-ID: <20160223175130.GA3164@potion.brq.redhat.com> (raw)
In-Reply-To: <B84047ECBD981D4B93EAE5A6245AA361995D20@lhreml501-mbb>

Please read https://en.wikipedia.org/wiki/Posting_style or related
documents on email quoting.

2016-02-23 07:11+0000, Avi Cohen:
>> 2016-02-21 16:57+0000, Avi Cohen:
>>> Hello,
>>> 
>>> Last week I've sent a mail regarding the kvm-clock accuracy.
>>> Now I try to draw-up my question again, any answer/partial/hint  is 
>>> greatly appreciated
>>> 
>>> Our application is running in  a Tenant's Virtual Machine in a data-centre.
>>> We have some OAM functions running in  the VMs.
>>> One OAM function is to measure one-way delay between VMa and VMb. 
>>> One way delay measurement requires that all machines should be synchronized to a common central clock.
>>> Accuracy requirement is in order of 10s nano-seconds, hence only the 1588v2/PTP is suitable here.
>>> Since we cannot use HW timestamping in a virtual machine (we cannot force using SR-IOV), I thought to run PTP on the physical machines and to sync the VMs to the host by the kvm-clock.
>> 
>> kvmclock doesn't do synchronization with host clock or UTC.
>> kvmclock bases on host's notion of *passed* time.
>> kvmclock allows the guest to measure a flow of time.
>> 
>> It is another layer's job to translate kvmclock result into a timestamp that can be compared.  kvmclock was designed like that, because KVM wants to make a guest independent on hosts.
> 
> I see the system time written by KVM  whenever the VM is entered  - in  kvm_guest_time_update()
> 
> How can  the guest  (or  another layer's job ) - translate kvmclock result into a timestamp that can be compared ?

If the layer has a good idea about the number of ticks the second takes
on both clocks, then the layer is synchronized with a
  (time on one clock, time on second clock) pair.
You get a timestamp comparable with the other clock by providing a
timestamp from one of synchronized clocks.

The hard part is getting the pair.  (A duration of the second is pretty
stable and the pair needs to be renewed on a change anyway.)

>> > In Theory  - Is it possible to achieve 10s ns accuracy between VM clock and the host clock ? 
>> 
>> It is.
> 
> How ? this is the only question

Look at last paragraph of my previous email.
(That one has 1 ns accuracy if KVM is using the masterclock.)

Note that it is impossible to confirm the accuracy with your measurement
because delay between sending and receiving a packet is normally *far*
longer that 100 ns.

>> > its system_time and the VM_TSC @ current time to the pvclock page , then the guest OS can calculate its current time by:
>> 
>> KVM doesn't write its (= host's) system_time.
>> KVM writes *guest's* system_time.  Guest's system_time at VM_TSC.
>> 
>> (system_time is 0 when the VM starts.  sytem_time can store ~584 years  worth of nanoseconds, but using an arbitrary offset makes everything  simpler.  This part of kvmclock is pretty confusing, so system_time is  likely the source of misunderstanding.)
>> 
>> Have you read that kvmclock does synchronization with host time somewhere?
>> 
> Yes - see - in  vcpu_enter_guest() there is a call to   kvm_guest_time_update()
> 
> Which update  the pvclock paget   for the guest - see that it updates the system_time  with the host system-time 

I think you misunderstand the code, see kvmclock_offset.

system_time is incremented by a second if the host thinks that a second
has passed since last update, but that doesn't allow the guest to tell
host time.

  parent reply	other threads:[~2016-02-23 17:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <B84047ECBD981D4B93EAE5A6245AA361995B00@lhreml501-mbb>
2016-02-21 16:57 ` KVM-Clock Avi Cohen
2016-02-22 20:08   ` KVM-Clock Radim Krčmář
2016-02-23  7:11     ` KVM-Clock Avi Cohen
2016-02-23  8:04       ` KVM-Clock Wanpeng Li
2016-02-23  8:18         ` KVM-Clock Avi Cohen
2016-02-23  8:38         ` KVM-Clock Avi Cohen
2016-02-23 17:51       ` Radim Krčmář [this message]
2016-02-24 10:32         ` KVM-Clock Avi Cohen
2016-02-24 12:20           ` KVM-Clock Radim Krčmář
2016-02-24 15:31             ` KVM-Clock Avi Cohen
2016-02-24  4:09   ` KVM-Clock Marcelo Tosatti
2016-02-24  8:15     ` KVM-Clock Avi Cohen
2016-02-24 11:33       ` KVM-Clock Marcelo Tosatti
2016-02-24 11:51         ` KVM-Clock Avi Cohen
2016-02-24 12:23           ` KVM-Clock Marcelo Tosatti
2016-02-24 15:27             ` KVM-Clock Avi Cohen
2016-02-24 18:08               ` KVM-Clock Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160223175130.GA3164@potion.brq.redhat.com \
    --to=rkrcmar@redhat.com \
    --cc=avi.cohen@huawei.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.