mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Roman Kagan <rkagan@virtuozzo.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	peterhornyack@google.com, rkrcmar@redhat.com, den@openvz.org
Subject: Re: [PATCH 3/4] KVM: x86: introduce get_kvmclock_ns
Date: Fri, 2 Sep 2016 18:37:59 +0200	[thread overview]
Message-ID: <9a02e696-f9ac-8caa-5acd-d820374e6773@redhat.com> (raw)
In-Reply-To: <20160902145123.v53bthe64qvj7ris@rkaganb.sw.ru>



On 02/09/2016 16:51, Roman Kagan wrote:
> On Fri, Sep 02, 2016 at 04:09:42PM +0200, Paolo Bonzini wrote:
>> On 02/09/2016 15:52, Roman Kagan wrote:
>> vs. using a single offset as in the TSC ref page is one nanosecond---and
>> the ref page only has a resolution of 100 ns.
> 
> AFAICS it's not a matter of resolution.  If one calculation flips from
> value T to T+1 at tsc1, while the other at tsc2, during the window
> between tsc1 and tsc2 we can have monotonicity violation.

Ok, tried "empirically" (throw numbers in a spreadsheet :)) and indeed
the maximum error is not 1 ns but 100 ns (1 unit in the time reference
count MSR).

You can get a flip between T/T+1 because the time reference counter may
be more precise with its rounding due to the separation between
tsc_timestamp and system_time.  This separation provides some extra
decimal digits to the offset, which the TSC page lacks.  For example:

51256391	tsc_timestamp
3311474323	tsc_to_system_mul
254246		system_time
-1		shift
-195054.1816	offset (computed exactly)

So the flip happens when the nanoseconds are around 81/82:

	tsc	   kvmclock	refcount  TSC page
	51256391   254246	2542	  2542
	51256483   254281	2542	  2542
	51256484   254281	2542	  2543
	51256486   254282	2542	  2543
	51256746   254382	2543	  2544

I'll change patch 4 to store the parameters and use them when accessing
the time reference counter MSR.  I'll still keep the procedure that goes
through kvmclock.  It's a bit more involved for the scale, but
vcpu->last_guest_tsc only provides a part of the offset computation; the
other half is vcpu->hv_clock.system_time and it's not stored anywhere.

Paolo

  reply	other threads:[~2016-09-02 16:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01 15:26 [PATCH 0/4] KVM: x86: kvmclock cleanups for Hyper-V TSC page Paolo Bonzini
2016-09-01 15:26 ` [PATCH 1/4] KVM: x86: always fill in vcpu->arch.hv_clock Paolo Bonzini
2016-09-02 13:31   ` Roman Kagan
2016-09-02 13:48     ` Paolo Bonzini
2016-09-01 15:26 ` [PATCH 2/4] KVM: x86: initialize kvmclock_offset Paolo Bonzini
2016-09-02 13:32   ` Roman Kagan
2016-09-01 15:26 ` [PATCH 3/4] KVM: x86: introduce get_kvmclock_ns Paolo Bonzini
2016-09-02 13:52   ` Roman Kagan
2016-09-02 14:09     ` Paolo Bonzini
2016-09-02 14:51       ` Roman Kagan
2016-09-02 16:37         ` Paolo Bonzini [this message]
2016-09-02 16:55           ` Roman Kagan
2016-09-02 16:57             ` Paolo Bonzini
2016-09-02 17:07               ` Roman Kagan
2016-09-02 15:24   ` Roman Kagan
2016-09-05 13:59     ` Paolo Bonzini
2016-09-01 15:26 ` [PATCH 4/4] KVM: x86: Hyper-V tsc page setup Paolo Bonzini
2016-09-02 14:17   ` Roman Kagan
2016-09-19 11:39 [PATCH v2 0/4] KVM: x86: kvmclock cleanups for Hyper-V TSC page Paolo Bonzini
2016-09-19 11:39 ` [PATCH 3/4] KVM: x86: introduce get_kvmclock_ns Paolo Bonzini
2016-09-19 16:33   ` Roman Kagan

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=9a02e696-f9ac-8caa-5acd-d820374e6773@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=den@openvz.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhornyack@google.com \
    --cc=rkagan@virtuozzo.com \
    --cc=rkrcmar@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

all inboxes | Powered by JetHome®