lkml.org 
[lkml]   [2016]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH 1/2] pvclock: introduce seqcount-like API
I think you forget to pass -v3 to git format-patch :)

On Mon, Jun 27, 2016 at 7:19 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> The version field in struct pvclock_vcpu_time_info basically implements
> a seqcount. Wrap it with the usual read_begin and read_retry functions,
> and use these APIs instead of peppering the code with smp_rmb()s.
> While at it, change it to the more pedantically correct virt_rmb().
>
> With this change, __pvclock_read_cycles can be simplified noticeably.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> v2->v3: add unlikely() around read_retry check.
>
> arch/x86/entry/vdso/vclock_gettime.c | 9 ++-------
> arch/x86/include/asm/pvclock.h | 39 +++++++++++++++++++++---------------
> arch/x86/kernel/pvclock.c | 17 ++++++----------
> 3 files changed, 31 insertions(+), 34 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
> index 2f02d23a05ef..db1e3b4c3693 100644
> --- a/arch/x86/entry/vdso/vclock_gettime.c
> +++ b/arch/x86/entry/vdso/vclock_gettime.c
> @@ -123,9 +123,7 @@ static notrace cycle_t vread_pvclock(int *mode)
> */
>
> do {
> - version = pvti->version;
> -
> - smp_rmb();
> + version = pvclock_read_begin(pvti);
>
> if (unlikely(!(pvti->flags & PVCLOCK_TSC_STABLE_BIT))) {
> *mode = VCLOCK_NONE;
> @@ -137,10 +135,7 @@ static notrace cycle_t vread_pvclock(int *mode)
> pvti_tsc_shift = pvti->tsc_shift;
> pvti_system_time = pvti->system_time;
> pvti_tsc = pvti->tsc_timestamp;
> -
> - /* Make sure that the version double-check is last. */
> - smp_rmb();
> - } while (unlikely((version & 1) || version != pvti->version));
> + } while (pvclock_read_retry(pvti, version));
>
> delta = tsc - pvti_tsc;
> ret = pvti_system_time +
> diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h
> index 7c1c89598688..d019f0cc80ec 100644
> --- a/arch/x86/include/asm/pvclock.h
> +++ b/arch/x86/include/asm/pvclock.h
> @@ -25,6 +25,24 @@ void pvclock_resume(void);
>
> void pvclock_touch_watchdogs(void);
>
> +static __always_inline
> +unsigned pvclock_read_begin(const struct pvclock_vcpu_time_info *src)
> +{
> + unsigned version = src->version & ~1;

I see your cute optimization here....

> + /* Make sure that the version is read before the data. */
> + virt_rmb();
> + return version;
> +}
> +
> +static __always_inline
> +bool pvclock_read_retry(const struct pvclock_vcpu_time_info *src,
> + unsigned version)
> +{
> + /* Make sure that the version is re-read after the data. */
> + virt_rmb();
> + return unlikely(version != src->version);

...and here.

LGTM.

\
 
 \ /
  Last update: 2016-07-06 16:01    [W:0.112 / U:1.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site