public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, pbonzini@redhat.com, den@virtuozzo.com,
	rkagan@virtuozzo.com
Subject: Re: [RFC PATCH 1/2] timekeeper: change interface of clocksource reding functions
Date: Fri, 21 Jul 2017 17:00:11 +0300	[thread overview]
Message-ID: <be375ed3-45df-7765-ef0c-6af29d43138f@virtuozzo.com> (raw)
In-Reply-To: <20170710130050.GD30880@potion>



On 10.07.2017 16:00, Radim Krčmář wrote:
> 2017-06-28 13:55+0300, Denis Plotnikov:
>> When using timekeepeing API in some cases it is useful to return
>> timestamp value used along with the time calculated to use that
>> timestamp value for other purpuses (e.g. in KVM master clock timestamp)
> 
> Makes sense.  What I don't like about this interface is the TSC centric
> approach in a code that isn't even x86 specific -- other architectures
> might have a similar counter they'd like to use.
> 
> Could we get it a bit more generic?
Yes, sure
> 
> At least returning the type of the clock and its counter value.
> (kvmclock is a bit problematic for the generic solution, because it is
>   TSC based, but should pass through the kvmclock value if we were going
>   to make it clean ...)
> 
> ---
> Actually, we might be overengineering it.  With the master clock we have
> now, I'm thinking that the gtod is not crucial and we could as well be
> using something like:
> 
>    static bool kvm_get_time_and_clockread(s64 *kernel_ns, u64 *cycle_now)
>    {
>    	local_irq_save(flags);
>    	*cycle_now = rdtsc();
>    	*kernel_ns = ktime_get_boot_ns();
>    	local_irq_restore(flags);
> 
>    	return todo_tsc_hardware_is_good_enough();
>    }
> 
> because kvmclock is shifted when master clock is recomputed or disabled,
> so it should never happen. (And if it happens, then this bit of
> imprecision doesn't matter much.)
> The host doesn't need to use TSC either, because master clock uses TSC
> frequency that differs from boot_ns -- we only need to be sure that the
> TSC hardware doesn't change its frequency.
> 
> The small delta introduced with this (rdtsc <-> ktime_get_boot_ns) is
> the same that the guest would see if we didn't enable master clock.
> kvmclock updates are then normally using the same cycle_now/kernel_ns
> pair to remain stable.
> 
I thought about that (and actually tried that first). The concern is 
about L2 guests running over L1 KVM where the margin between cycle_now 
and kernel_ns is unpredictable because L1 KVM can be scheduled at any 
time for relatively long period.
That's why I decided to rework timekeeper and get kernel_time
and corresponding cycle value from there

-- 
Best,
Denis

  reply	other threads:[~2017-07-21 14:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-28 10:54 [RFC PATCH 0/2] make L2 kvm-clock stable Denis Plotnikov
2017-06-28 10:55 ` [RFC PATCH 1/2] timekeeper: change interface of clocksource reding functions Denis Plotnikov
2017-07-10 13:00   ` Radim Krčmář
2017-07-21 14:00     ` Denis Plotnikov [this message]
2017-06-28 10:55 ` [RFC PATCH 2/2] KVM: x86: add support of kvm-clock stablity in L2 Denis Plotnikov
2017-07-10 13:25   ` Radim Krčmář
2017-07-10 13:32     ` Radim Krčmář
2017-07-21 14:01       ` Denis Plotnikov
2017-07-03 16:12 ` [RFC PATCH 0/2] make L2 kvm-clock stable Denis Plotnikov
2017-07-03 16:27   ` Paolo Bonzini
2017-07-10  7:56   ` Denis Plotnikov

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=be375ed3-45df-7765-ef0c-6af29d43138f@virtuozzo.com \
    --to=dplotnikov@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.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