mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>,
	Radim Krcmar <rkrcmar@redhat.com>, kvm list <kvm@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	lkml <linux-kernel@vger.kernel.org>,
	x86@kernel.org, rkagan@virtuozzo.com, den@virtuozzo.com,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v4 00/10] make L2's kvm-clock stable, get rid of pvclock_gtod_copy in KVM
Date: Mon, 28 Aug 2017 10:28:06 +0300	[thread overview]
Message-ID: <ca8c2155-707d-14f0-d818-053e5e57f8bd@virtuozzo.com> (raw)
In-Reply-To: <43d87f0d-62c3-878e-108a-aaf7fb68fcb3@redhat.com>



On 24.08.2017 11:00, Paolo Bonzini wrote:
> On 23/08/2017 18:02, Paolo Bonzini wrote:
>>
>> More duct tape would have been just:
>>
>> -	if (pvclock_gtod_data.clock.vclock_mode != VCLOCK_TSC)
>> +	mode = READ_ONCE(pvclock_gtod_data.clock.vclock_mode);
>> +	if (mode != VCLOCK_TSC &&
>> +	    (mode != VCLOCK_PVCLOCK || !pvclock_nested_virt_magic())
>> 		return false;
>>
>> -	return do_realtime(ts, cycle_now) == VCLOCK_TSC;
>> +	switch (mode) {
>> +	case VCLOCK_TSC:
>> +		return do_realtime_tsc(ts, cycle_now);
>> +	case VCLOCK_PVCLOCK:
>> +		return do_realtime_pvclock(ts, cycle_now);
>> +	}
>>
>> Nested virtualization does need a clocksource change notifier on top,
>> but we can cross that bridge later.  Maybe Denis can post just those
>> patches to begin with.
> 
> For what it's worth, this is all that's needed (with patches 1-2-3-4-5-7)
> to support kvmclock on top of Hyper-V clock.  It's trivial.
> 
> Even if we could add paravirtualization magic to KVM live migration, we
> certainly couldn't do that for other hypervisors.
> 
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 5b882cc0c0e9..3bab935b021a 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -46,10 +46,24 @@ static u64 read_hv_clock_tsc(struct clocksource *arg)
>   	return current_tick;
>   }
>   
> +static bool read_hv_clock_tsc_with_stamp(struct clocksource *arg,
> +					 u64 *cycles, u64 *cycles_stamp)
> +{
> +	*cycles = __hv_read_tsc_page(tsc_pg, &cycles_stamp);
> +
> +	if (*cycles == U64_MAX) {
> +		*cycles = rdmsrl(HV_X64_MSR_TIME_REF_COUNT);
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
>   static struct clocksource hyperv_cs_tsc = {
>   		.name		= "hyperv_clocksource_tsc_page",
>   		.rating		= 400,
>   		.read		= read_hv_clock_tsc,
> +		.read_with_stamp = read_hv_clock_tsc_with_stamp,
>   		.mask		= CLOCKSOURCE_MASK(64),
>   		.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
>   };
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 2b58c8c1eeaa..5aff66e9fff7 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -176,9 +176,9 @@ void hyperv_cleanup(void);
>   #endif
>   #ifdef CONFIG_HYPERV_TSCPAGE
>   struct ms_hyperv_tsc_page *hv_get_tsc_page(void);
> -static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg)
> +static inline u64 __hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg, u64 *cur_tsc)
>   {
> -	u64 scale, offset, cur_tsc;
> +	u64 scale, offset;
>   	u32 sequence;
>   
>   	/*
> @@ -209,7 +209,7 @@ static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg)
>   
>   		scale = READ_ONCE(tsc_pg->tsc_scale);
>   		offset = READ_ONCE(tsc_pg->tsc_offset);
> -		cur_tsc = rdtsc_ordered();
> +		*cur_tsc = rdtsc_ordered();
>   
>   		/*
>   		 * Make sure we read sequence after we read all other values
> @@ -219,9 +219,14 @@ static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg)
>   
>   	} while (READ_ONCE(tsc_pg->tsc_sequence) != sequence);
>   
> -	return mul_u64_u64_shr(cur_tsc, scale, 64) + offset;
> +	return mul_u64_u64_shr(*cur_tsc, scale, 64) + offset;
>   }
>   
> +static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg)
> +{
> +	u64 cur_tsc;
> +	return __hv_read_tsc_page(tsc_pg, &cur_tsc);
> +}
>   #else
>   static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void)
>   {
> 
> 
> Denis, could you try redoing patch 7 to use the pvclock_gtod_notifier
> instead of the new one you're adding, and only send that first part?  I
> think it's a worthwhile cleanup anyway, so let's start with that.
> 
> Paolo
>
Ok, I'll do that

Denis

      reply	other threads:[~2017-08-28  7:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-02 14:38 Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 01/10] timekeeper: introduce extended clocksource reading callback Denis Plotnikov
2017-08-02 17:08   ` John Stultz
2017-08-02 17:21     ` Paolo Bonzini
2017-08-02 14:38 ` [PATCH v4 02/10] timekeeper: introduce boot field in system_time_snapshot Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 03/10] timekeeper: use the extended reading function on snapshot acquiring Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 04/10] tsc: implement the extended tsc reading function Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 05/10] KVM: x86: switch to masterclock update using timekeeper functionality Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 06/10] timekeeper: add clocksource change notifier Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 07/10] KVM: x86: remove not used pvclock_gtod_copy Denis Plotnikov
2017-08-02 23:21   ` Marcelo Tosatti
2017-08-03 12:35     ` Paolo Bonzini
2017-08-11 22:59       ` Marcelo Tosatti
2017-08-02 14:38 ` [PATCH v4 08/10] pvclock: add parameters to store stamp data in pvclock reading function Denis Plotnikov
2017-08-02 14:38 ` [PATCH v4 09/10] pvclock: add clocksource change notification on changing of tsc stable bit Denis Plotnikov
2017-08-02 23:36   ` Marcelo Tosatti
2017-08-02 14:38 ` [PATCH v4 10/10] kvmclock: implement the extended reading function Denis Plotnikov
2017-08-02 16:10 ` [PATCH v4 00/10] make L2's kvm-clock stable, get rid of pvclock_gtod_copy in KVM Paolo Bonzini
2017-08-02 16:49 ` John Stultz
2017-08-02 17:11   ` Paolo Bonzini
2017-08-21  8:40     ` Denis Plotnikov
2017-08-22 19:50       ` John Stultz
2017-08-22 21:00         ` Paolo Bonzini
2017-08-23 12:45           ` Thomas Gleixner
2017-08-23 16:02             ` Paolo Bonzini
2017-08-24  8:00               ` Paolo Bonzini
2017-08-28  7:28                 ` Denis Plotnikov [this message]

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=ca8c2155-707d-14f0-d818-053e5e57f8bd@virtuozzo.com \
    --to=dplotnikov@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rkagan@virtuozzo.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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®