From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Suleiman Souhlal <suleiman@google.com>
Cc: John Stultz <john.stultz@linaro.org>,
sboyd@kernel.org, Linux Kernel <linux-kernel@vger.kernel.org>,
kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
rkrcmar@redhat.com, Thomas Gleixner <tglx@linutronix.de>,
Tomasz Figa <tfiga@google.com>
Subject: Re: [RFC 2/2] x86/kvmclock: Use host timekeeping.
Date: Tue, 24 Sep 2019 13:14:35 +0200 [thread overview]
Message-ID: <87ftkm7xpg.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <CABCjUKDPa1wrvp5zrjCa0tAQUO5UuFNgc00Z5kt_7rgakjApDw@mail.gmail.com>
Suleiman Souhlal <suleiman@google.com> writes:
> On Fri, Sep 20, 2019 at 10:33 PM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>>
>> Suleiman Souhlal <suleiman@google.com> writes:
>>
>> > When CONFIG_KVMCLOCK_HOST_TIMEKEEPING is enabled, and the host
>> > supports it, update our timekeeping parameters to be the same as
>> > the host. This lets us have our time synchronized with the host's,
>> > even in the presence of host NTP or suspend.
>> >
>> > When enabled, kvmclock uses raw tsc instead of pvclock.
>> >
>> > When enabled, syscalls that can change time, such as settimeofday(2)
>> > or adj_timex(2) are disabled in the guest.
>> >
>> > Signed-off-by: Suleiman Souhlal <suleiman@google.com>
>> > ---
>> > arch/x86/Kconfig | 9 +++
>> > arch/x86/include/asm/kvmclock.h | 2 +
>> > arch/x86/kernel/kvmclock.c | 127 +++++++++++++++++++++++++++++++-
>> > kernel/time/timekeeping.c | 21 ++++++
>> > 4 files changed, 155 insertions(+), 4 deletions(-)
>> >
>> > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>> > index 4195f44c6a09..37299377d9d7 100644
>> > --- a/arch/x86/Kconfig
>> > +++ b/arch/x86/Kconfig
>> > @@ -837,6 +837,15 @@ config PARAVIRT_TIME_ACCOUNTING
>> > config PARAVIRT_CLOCK
>> > bool
>> >
>> > +config KVMCLOCK_HOST_TIMEKEEPING
>> > + bool "kvmclock uses host timekeeping"
>> > + depends on KVM_GUEST
>> > + ---help---
>> > + Select this option to make the guest use the same timekeeping
>> > + parameters as the host. This means that time will be almost
>> > + exactly the same between the two. Only works if the host uses "tsc"
>> > + clocksource.
>> > +
>>
>> I'd also like to speak up against this config, it is confusing. In case
>> the goal is to come up with a TSC-based clock for guests which will
>> return the same as clock_gettime() on the host (or, is the goal to just
>> have the same reading for all guests on the host?) I'd suggest we create
>> a separate (from KVMCLOCK) clocksource (mirroring host timekeeper) and
>> guests will be free to pick the one they like.
>
> Fair enough. I'll do that in the next version of the patch.
>
> The goal is to have a guest clock that gives the same
> clock_gettime(CLOCK_MONOTONIC) as the host.
>
KVMCLOCK has lots of legacy derived from times when TSC synchronization
was not a given (I heard that this is still sometimes problematic with
multi-socket systems but oh well). If I was to design a new clock I'd
probably mirror Hyper-V's TSC page clocksource invalidating the page
when host timekeeper values are updated (and making guest spin).
The tricky part with this approach is probably tsc scaling/tsc
offsetting which is still going to be controlled by kvmclock (so the
guest has no option to read 'pure TSC'). As an alternative, you can make
kvmclock un-pluggable so when it's not enabled TSC frequency/offset can
remain intact. You can, of course, try to update timekeeper values to
match the new frequency/offset every time they change but rounding
errors may bite.
--
Vitaly
next prev parent reply other threads:[~2019-09-24 11:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-20 6:27 [RFC 0/2] kvm: Use host timekeeping in guest Suleiman Souhlal
2019-09-20 6:27 ` [RFC 1/2] kvm: Mechanism to copy host timekeeping parameters into guest Suleiman Souhlal
2019-09-20 6:27 ` [RFC 2/2] x86/kvmclock: Use host timekeeping Suleiman Souhlal
2019-09-20 13:33 ` Vitaly Kuznetsov
2019-09-24 8:10 ` Suleiman Souhlal
2019-09-24 11:14 ` Vitaly Kuznetsov [this message]
2019-09-20 7:48 ` [RFC 0/2] kvm: Use host timekeeping in guest Paolo Bonzini
2019-09-20 10:23 ` Thomas Gleixner
2019-09-24 8:08 ` Suleiman Souhlal
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=87ftkm7xpg.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=john.stultz@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=sboyd@kernel.org \
--cc=suleiman@google.com \
--cc=tfiga@google.com \
--cc=tglx@linutronix.de \
/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.