All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Vadim Rozenfeld <vrozenfe@redhat.com>
Cc: kvm@vger.kernel.org, mtosatti@redhat.com, pl@dlhnet.de
Subject: Re: [RFC PATCH v3 2/2] add support for Hyper-V partition reference time enlightenment
Date: Wed, 11 Dec 2013 13:28:34 +0100	[thread overview]
Message-ID: <52A85A72.8000702@redhat.com> (raw)
In-Reply-To: <1386759539.7616.28.camel@localhost>

Il 11/12/2013 11:58, Vadim Rozenfeld ha scritto:
>> > +			curr_time = (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32) + 
>> > +				tsc_ref->tsc_offset;
>> > +			tsc_ref->tsc_offset = kvm->arch.hv_ref_time - curr_time;
>> > 
>> > Why do you need kvm->arch.hv_ref_time at all?  Can you just use
>> > "get_kernel_ns() + kvm->arch.kvmclock_offset - kvm->arch.hv_ref_count"?
>> > Then the same code can set tsc_ref->tsc_offset in both cases.
>> > 
>> > In fact, it's not clear to me what hv_ref_time is for, and how it
>> > is different from 
> OK, let me explain how it works.
> Hyper-V allows guest to use invariant TSC provided by host as a time
> stamp source (KeQueryPerformanceCounter). Guest is calling rdtsc and
> normalizing it to 10MHz frequency, it is why we need "tsc_scale".
> "tsc_offset" is needed for migration or pause/resume cycles.
> When we pause a VM, we need to save the current vTSC value
> ("hv_ref_time"), which is rdtsc * tsc_scale + tsc_offset.
> Then, during resume, we need to recalculate the new tsc_scale
> as well as the new tsc_offset value. 
> tsc_offset = old(saved) vTSC - new vTSC

In practice "save" means KVM_GET_CLOCK, and "restore" means
KVM_SET_CLOCK, right?

> So maybe hv_ref_time is not a good name, but we use it 
> for keeping the old vTSC value, saved before stopping VM.

Ok, this was roughly my understanding as well.

My understanding is also that (((tsc_ref->tsc_scale >> 32) *
native_read_tsc()) >> 32) + tsc_ref->tsc_offset returns exactly the same
value as HV_X64_MSR_TIME_REF_COUNT.  Thus we do not need
kvm->arch.hv_ref_time.  We can use the value of
HV_X64_MSR_TIME_REF_COUNT, which is "(get_kernel_ns() +
kvm->arch.kvmclock_offset - kvm->arch.hv_ref_count) / 100", to compute
tsc_offset, like this:

  curr_time = (((tsc_ref->tsc_scale >> 32) * native_read_tsc()) >> 32);
  tsc_ref->tsc_offset = get_hv_x64_msr_time_ref_count() - curr_time;

This code can be applied always: when the TSC page is initialized and
when KVM_SET_CLOCK is called.  You do not need to do anything for
KVM_GET_CLOCK.

Paolo

  reply	other threads:[~2013-12-11 12:28 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-08 11:33 [RFC PATCH v3 0/2] Hyper-V timers Vadim Rozenfeld
2013-12-08 11:33 ` [RFC PATCH v3 1/2] add support for Hyper-V reference time counter Vadim Rozenfeld
2013-12-09 14:23   ` Paolo Bonzini
2013-12-10 10:46     ` Vadim Rozenfeld
2013-12-11 18:53   ` Marcelo Tosatti
2013-12-11 18:59     ` Marcelo Tosatti
2013-12-12  9:33       ` Paolo Bonzini
2014-01-02 16:52       ` Peter Lieven
2014-01-07  9:36         ` Vadim Rozenfeld
2014-01-07 17:52           ` Peter Lieven
2014-01-08  9:40             ` Vadim Rozenfeld
2014-01-08 10:15               ` Peter Lieven
2014-01-08 10:44                 ` Vadim Rozenfeld
2014-01-08 11:48                   ` Peter Lieven
2014-01-08 12:12                     ` Vadim Rozenfeld
2014-01-08 14:54                       ` Peter Lieven
2014-01-08 20:08                         ` Vadim Rozenfeld
2014-01-08 22:20                           ` Peter Lieven
2014-01-09 11:10                             ` Vadim Rozenfeld
2014-01-12 12:08                             ` Vadim Rozenfeld
2014-01-12 20:35                               ` Peter Lieven
2014-01-02 13:15     ` Peter Lieven
2014-01-02 13:57       ` Marcelo Tosatti
2014-01-02 16:08         ` Peter Lieven
2014-01-02 20:05           ` Marcelo Tosatti
2014-01-13 12:10     ` Vadim Rozenfeld
2013-12-08 11:33 ` [RFC PATCH v3 2/2] add support for Hyper-V partition reference time enlightenment Vadim Rozenfeld
2013-12-09 14:32   ` Paolo Bonzini
2013-12-10 11:23     ` Vadim Rozenfeld
2013-12-10 16:52       ` Paolo Bonzini
2013-12-11 10:58         ` Vadim Rozenfeld
2013-12-11 12:28           ` Paolo Bonzini [this message]
2013-12-11 19:28       ` Marcelo Tosatti
2013-12-11 19:27   ` Marcelo Tosatti
2013-12-12  9:34     ` Paolo Bonzini
2014-01-14  4:11     ` Vadim Rozenfeld
2014-01-14 13:54       ` 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=52A85A72.8000702@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=pl@dlhnet.de \
    --cc=vrozenfe@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.