public inbox for kvm@vger.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 again
Date: Tue, 5 Apr 2016 22:25:24 +0200	[thread overview]
Message-ID: <20160405202524.GB29308@potion.brq.redhat.com> (raw)
In-Reply-To: <B84047ECBD981D4B93EAE5A6245AA3619A52C1@lhreml501-mbb>

2016-04-05 15:07+0000, Avi Cohen:
> What do you think about this simple solution:
>  Currently  the KVM updates the system-time in the structure pvclock_vcpu_time_info  in the guest memory  with the MONOTONIC time 
> struct pvclock_vcpu_time_info {
>         u32   version;
>         u32   pad0;
>         u64   tsc_timestamp;
>         u64   system_time;
>         u32   tsc_to_system_mul;
>         s8    tsc_shift;
>         u8    flags;
>         u8    pad[2];
> } __attribute__((__packed__));
> 
> This is the default kvm-clcok.
> I think to add another clock source named - kvm-clock-realtime, and to update system_time with host's REAL_TIME clock.
> What is your opinion ?

Would you be ok with a wall_time entry in pvclock_vcpu_time_info that
would tell the host real time at system_time?
struct pvclock_wall_clock should say the host real time when system_time
was 0, so it's the same.  wallclock = CLOCK_REALTIME, most likely.

Creating a new clock would allow us to get rid of many other problems,
but your goal might be achievable with existing interfaces.

> I want to enter the KVM  code and try to make a REAL_TIME and accurate synchronization between the host and  guest  clocks .
> Currently I don’t see that KVM  updates the guest’s clock when I manually set the host’s clock. I don’t see any impact on the guest’s clock Also after booting the guest I see a  diff-time of ~1ms between the 2 clocks. 
> Questions:
> - What can you tell about the feasibility of this task ?

Doable.

> - Can you give me a reference/guides  for this task’s  design ? where to start ? potential problems ? pvclock ? when to update , when reentering the VM ? etc..

Start by using kvm_get_wallclock to pass the host CLOCK_REALTIME into
the guest and turn wallclock into guest CLOCK_REALTIME.

A reasonable solution would be to create a thread that periodically
synchronizes CLOCK_REALTIME with wallclock.  The wallclock thread would
behave like PTP/NTP, so it should be easy to do.
(A notification from the host that the wallclock has changed would
 be better, but needs new interface.)

I think that using wallclock directly as CLOCK_REALTIME would cause more
complications:
- many guest interfaces expect that they can touch CLOCK_REALTIME, but
  that shouldn't be allowed
- changes in wallclock should trigger guest notifiers as if the change
  was done by the guest
- wallclock is updated only when the guest writes to the MSR, which
  would be wasteful for frequent reads and not possible in userspace

We'll have enough experience to decide on followup if no solution using
the existing framework is acceptable.

  reply	other threads:[~2016-04-05 20:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-05 15:07 kvm-clock again Avi Cohen
2016-04-05 20:25 ` Radim Krčmář [this message]
2016-04-06 13:51   ` Avi Cohen
2016-04-06 14:17     ` Radim Krčmář
2016-04-07  7:09   ` Avi Cohen
2016-04-07 14:20     ` Radim Krčmář
2016-04-08 15:00       ` Avi Cohen
2016-04-13 12:46       ` Avi Cohen
2016-04-14 18:23         ` Radim Krčmář
  -- strict thread matches above, loose matches on Subject: below --
2016-04-05 11:12 Avi Cohen

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=20160405202524.GB29308@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox