From: Marcelo Tosatti <mtosatti@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock
Date: Thu, 11 Feb 2016 16:23:10 +0100 [thread overview]
Message-ID: <20160211152309.GA9588@amt.cnet> (raw)
In-Reply-To: <1454944711-33022-3-git-send-email-pbonzini@redhat.com>
On Mon, Feb 08, 2016 at 04:18:29PM +0100, Paolo Bonzini wrote:
> This is the same as before:
>
> kvm_scale_tsc(tgt_tsc_khz)
> = tgt_tsc_khz * ratio
> = tgt_tsc_khz * user_tsc_khz / tsc_khz (see set_tsc_khz)
> = user_tsc_khz (see kvm_guest_time_update)
> = vcpu->arch.virtual_tsc_khz (see kvm_set_tsc_khz)
>
> However, computing it through kvm_scale_tsc makes it possible
> to include the NTP correction in tgt_tsc_khz, as done in the
> next patch.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/x86.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 1ca2b44f70bb..6db3c219795b 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -1713,7 +1713,7 @@ static void kvm_gen_update_masterclock(struct kvm *kvm)
>
> static int kvm_guest_time_update(struct kvm_vcpu *v)
> {
> - unsigned long flags, this_tsc_khz, tgt_tsc_khz;
> + unsigned long flags, tgt_tsc_khz;
> struct kvm_vcpu_arch *vcpu = &v->arch;
> struct kvm_arch *ka = &v->kvm->arch;
> s64 kernel_ns;
> @@ -1739,8 +1739,8 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
>
> /* Keep irq disabled to prevent changes to the clock */
> local_irq_save(flags);
> - this_tsc_khz = __this_cpu_read(cpu_tsc_khz);
> - if (unlikely(this_tsc_khz == 0)) {
> + tgt_tsc_khz = __this_cpu_read(cpu_tsc_khz);
> + if (unlikely(tgt_tsc_khz == 0)) {
> local_irq_restore(flags);
> kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);
> return 1;
> @@ -1775,13 +1775,14 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
> if (!vcpu->pv_time_enabled)
> return 0;
>
> - if (unlikely(vcpu->hw_tsc_khz != this_tsc_khz)) {
> - tgt_tsc_khz = kvm_has_tsc_control ?
> - vcpu->virtual_tsc_khz : this_tsc_khz;
> + if (kvm_has_tsc_control)
> + tgt_tsc_khz = kvm_scale_tsc(v, tgt_tsc_khz);
> +
> + if (unlikely(vcpu->hw_tsc_khz != tgt_tsc_khz)) {
> kvm_get_time_scale(NSEC_PER_SEC / 1000, tgt_tsc_khz,
> &vcpu->hv_clock.tsc_shift,
> &vcpu->hv_clock.tsc_to_system_mul);
> - vcpu->hw_tsc_khz = this_tsc_khz;
> + vcpu->hw_tsc_khz = tgt_tsc_khz;
> }
>
> /* With all the info we got, fill in the values */
> --
> 1.8.3.1
>
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
next prev parent reply other threads:[~2016-02-11 15:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-08 15:18 [PATCH 0/4] kvmclock: improve accuracy Paolo Bonzini
2016-02-08 15:18 ` [PATCH 1/4] KVM: x86: rename argument to kvm_set_tsc_khz Paolo Bonzini
2016-02-11 15:01 ` Marcelo Tosatti
2016-02-08 15:18 ` [PATCH 2/4] KVM: x86: rewrite handling of scaled TSC for kvmclock Paolo Bonzini
2016-02-11 15:23 ` Marcelo Tosatti [this message]
2016-02-08 15:18 ` [PATCH 3/4] KVM: x86: pass kvm_get_time_scale arguments in hertz Paolo Bonzini
2016-02-08 15:18 ` [PATCH 4/4] KVM: x86: track actual TSC frequency from the timekeeper struct Paolo Bonzini
2016-02-09 18:41 ` Owen Hofmann
2016-02-10 13:57 ` Paolo Bonzini
2016-02-16 13:48 ` Marcelo Tosatti
2016-02-16 14:25 ` Marcelo Tosatti
2016-02-16 16:59 ` Paolo Bonzini
2016-02-19 14:12 ` Marcelo Tosatti
2016-02-19 15:53 ` Paolo Bonzini
2016-02-16 14:00 ` [PATCH 0/4] kvmclock: improve accuracy Marcelo Tosatti
-- strict thread matches above, loose matches on Subject: below --
2016-01-28 14:04 [PATCH kvm-unit-tests] KVM: x86: add hyperv clock test case Paolo Bonzini
2016-01-28 14:04 ` Paolo Bonzini
2016-01-28 14:25 ` Andrey Smetanin
2016-01-28 14:50 ` Paolo Bonzini
2016-01-28 15:53 ` Paolo Bonzini
2016-01-28 18:45 ` Roman Kagan
2016-01-28 18:53 ` Roman Kagan
2016-01-28 21:28 ` Paolo Bonzini
2016-01-28 16:22 ` Roman Kagan
2016-02-03 16:37 ` Paolo Bonzini
2016-02-04 9:33 ` Roman Kagan
2016-02-04 10:13 ` Paolo Bonzini
2016-02-04 11:12 ` Roman Kagan
2016-04-21 17:01 ` Roman Kagan
2016-04-22 13:32 ` Roman Kagan
2016-04-22 18:08 ` Paolo Bonzini
2016-04-25 8:47 ` Roman Kagan
2016-04-26 10:34 ` Roman Kagan
2016-05-25 18:33 ` Roman Kagan
2016-05-26 14:47 ` Roman Kagan
2016-05-29 22:34 ` 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=20160211152309.GA9588@amt.cnet \
--to=mtosatti@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@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 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.