kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Suleiman Souhlal <suleiman@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: rkrcmar@redhat.com, Thomas Gleixner <tglx@linutronix.de>,
	John Stultz <john.stultz@linaro.org>,
	sboyd@kernel.org, Linux Kernel <linux-kernel@vger.kernel.org>,
	kvm@vger.kernel.org, Suleiman Souhlal <ssouhlal@freebsd.org>,
	tfiga@chromium.org, Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: Re: [RFC v2 2/2] x86/kvmclock: Introduce kvm-hostclock clocksource.
Date: Tue, 15 Oct 2019 17:39:55 +0900	[thread overview]
Message-ID: <CABCjUKAsO9bOW9-VW1gk0O_U=9V6Zhft8LjpcqXVbDVTvWJ5Hw@mail.gmail.com> (raw)
In-Reply-To: <2e6e5b14-fa68-67bd-1436-293659c8d92c@redhat.com>

On Thu, Oct 10, 2019 at 7:55 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/10/19 09:30, Suleiman Souhlal wrote:
> > +kvm_hostclock_enable(struct clocksource *cs)
> > +{
> > +     pv_timekeeper_enabled = 1;
> > +
> > +     old_vclock_mode = kvm_clock.archdata.vclock_mode;
> > +     kvm_clock.archdata.vclock_mode = VCLOCK_TSC;
> > +     return 0;
> > +}
> > +
> > +static void
> > +kvm_hostclock_disable(struct clocksource *cs)
> > +{
> > +     pv_timekeeper_enabled = 0;
> > +     kvm_clock.archdata.vclock_mode = old_vclock_mode;
> > +}
> > +
>
> Why do you poke at kvm_clock?  Instead you should add
>
>         .archdata               = { .vclock_mode = VCLOCK_TSC },
>
> to the kvm_hostclock declaration.

Yeah, what I was doing does not make sense.

> Please also check that the invariant TSC CPUID bit
> CPUID[0x80000007].EDX[8] is set before enabling this feature.

Will do.

>
> Paolo
>
> > +     pvtk = &pv_timekeeper;
> > +     do {
> > +             gen = pvtk_read_begin(pvtk);
> > +             if (!(pv_timekeeper.flags & PVCLOCK_TIMEKEEPER_ENABLED))
> > +                     return;
> > +
> > +             pvclock_copy_into_read_base(pvtk, &tk->tkr_mono,
> > +                 &pvtk->tkr_mono);
> > +             pvclock_copy_into_read_base(pvtk, &tk->tkr_raw, &pvtk->tkr_raw);
> > +
> > +             tk->xtime_sec = pvtk->xtime_sec;
> > +             tk->ktime_sec = pvtk->ktime_sec;
> > +             tk->wall_to_monotonic.tv_sec = pvtk->wall_to_monotonic_sec;
> > +             tk->wall_to_monotonic.tv_nsec = pvtk->wall_to_monotonic_nsec;
> > +             tk->offs_real = pvtk->offs_real;
> > +             tk->offs_boot = pvtk->offs_boot;
> > +             tk->offs_tai = pvtk->offs_tai;
> > +             tk->raw_sec = pvtk->raw_sec;
> > +     } while (pvtk_read_retry(pvtk, gen));
> > +}
> > +
>
> Should you write an "enabled value" (basically the flags) into pvtk as well?

I think we have that already (pvtk->flags).
I'll change the if statement above to use pvtk instead of pv_timekeeper.

> > +kvm_hostclock_init(void)
> > +{
> > +     unsigned long pa;
> > +
> > +     pa = __pa(&pv_timekeeper);
> > +     wrmsrl(MSR_KVM_TIMEKEEPER_EN, pa);
>
>
> As Vitaly said, a new CPUID bit must be defined in
> Documentation/virt/kvm/cpuid.txt, and used here.  Also please make bit 0
> an enable bit.

I think I might not be able to move the enable bit to 0 because we
need the generation count (pvclock_timekeeper.gen) to be the first
word of the struct due to the way we copy the data to userspace,
similarly to how kvm_setup_pvclock_page() does it.

I also noticed the comment in kvm_copy_into_pvtk() references the
wrong function, which I will fix in the next revision.

Thanks for the feedback.

-- Suleiman

  reply	other threads:[~2019-10-15  8:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10  7:30 [RFC v2 0/2] kvm: Use host timekeeping in guest Suleiman Souhlal
2019-10-10  7:30 ` [RFC v2 1/2] kvm: Mechanism to copy host timekeeping parameters into guest Suleiman Souhlal
2019-10-10  8:31   ` Vitaly Kuznetsov
2019-10-10 10:50   ` Paolo Bonzini
2019-10-10  7:30 ` [RFC v2 2/2] x86/kvmclock: Introduce kvm-hostclock clocksource Suleiman Souhlal
2019-10-10  8:37   ` Vitaly Kuznetsov
2019-10-10 10:55   ` Paolo Bonzini
2019-10-15  8:39     ` Suleiman Souhlal [this message]
2019-10-15  8:59       ` Paolo Bonzini
2019-10-10 10:39 ` [RFC v2 0/2] kvm: Use host timekeeping in guest Roman Kagan
2019-10-11 18:50   ` Konrad Rzeszutek Wilk
2019-10-15  5:08   ` Suleiman Souhlal
2019-10-10 10:43 ` Paolo Bonzini

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='CABCjUKAsO9bOW9-VW1gk0O_U=9V6Zhft8LjpcqXVbDVTvWJ5Hw@mail.gmail.com' \
    --to=suleiman@google.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=ssouhlal@freebsd.org \
    --cc=tfiga@chromium.org \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).