All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wei Liu <wl@xen.org>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Wei Liu" <liuwe@microsoft.com>, "Wei Liu" <wl@xen.org>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Paul Durrant" <pdurrant@amazon.com>,
	"Michael Kelley" <mikelley@microsoft.com>,
	"Xen Development List" <xen-devel@lists.xenproject.org>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH v2 6/6] x86: implement Hyper-V clock source
Date: Fri, 20 Dec 2019 17:43:13 +0000	[thread overview]
Message-ID: <20191220174313.dbfdkngqfb2hpozq@debian> (raw)
In-Reply-To: <6cb667f8-0ace-75f5-e0b0-c35f8900952d@suse.com>

On Fri, Dec 20, 2019 at 05:05:24PM +0100, Jan Beulich wrote:
> On 18.12.2019 15:42, Wei Liu wrote:
> > --- a/xen/arch/x86/time.c
> > +++ b/xen/arch/x86/time.c
> > @@ -31,6 +31,7 @@
> >  #include <asm/processor.h>
> >  #include <asm/fixmap.h>
> >  #include <asm/guest.h>
> > +#include <asm/guest/hyperv-tlfs.h>
> 
> Can this please move ...
> 
> > @@ -644,6 +645,103 @@ static struct platform_timesource __initdata plt_xen_timer =
> >  };
> >  #endif
> >  
> > +#ifdef CONFIG_HYPERV_GUEST
> 
> ... here, to avoid the dependency on the header when the option is
> off?
> 
> > +/************************************************************
> > + * HYPER-V REFERENCE TSC
> > + */
> > +
> > +static struct ms_hyperv_tsc_page *hyperv_tsc;
> > +static struct page_info *hyperv_tsc_page;
> > +
> > +static int64_t __init init_hyperv_timer(struct platform_timesource *pts)
> > +{
> > +    paddr_t maddr;
> > +    uint64_t tsc_msr, freq;
> > +
> > +    if ( !(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE) )
> > +        return 0;
> > +
> > +    hyperv_tsc_page = alloc_domheap_page(NULL, 0);
> > +    if ( !hyperv_tsc_page )
> > +        return 0;
> > +
> > +    hyperv_tsc = __map_domain_page_global(hyperv_tsc_page);
> > +    if ( !hyperv_tsc )
> > +    {
> > +        free_domheap_page(hyperv_tsc_page);
> > +        hyperv_tsc_page = NULL;
> > +        return 0;
> > +    }
> > +
> > +    maddr = page_to_maddr(hyperv_tsc_page);
> > +
> > +    /*
> > +     * Per Hyper-V TLFS:
> > +     *   1. Read existing MSR value
> > +     *   2. Preserve bits [11:1]
> > +     *   3. Set bits [63:12] to be guest physical address of tsc page
> > +     *   4. Set enabled bit (0)
> > +     *   5. Write back new MSR value
> > +     */
> > +    rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
> > +    tsc_msr &= 0xffeULL;
> 
> There's no real need for the ULL suffix.
> 
> > +    tsc_msr |=  maddr | 1 /* enabled */;
> 
> Stray double blank after |= ?
> 
> > +    wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr);
> > +
> > +    /* Get TSC frequency from Hyper-V */
> > +    rdmsrl(HV_X64_MSR_TSC_FREQUENCY, freq);
> > +    pts->frequency = freq;
> > +
> > +    return freq;
> > +}
> > +
> > +static inline uint64_t read_hyperv_timer(void)
> > +{
> > +    uint64_t scale, offset, ret, tsc;
> > +    uint32_t seq;
> > +    const struct ms_hyperv_tsc_page *tsc_page = hyperv_tsc;
> > +
> > +    do {
> > +        seq = tsc_page->tsc_sequence;
> > +
> > +        /* Seq 0 is special. It means the TSC enlightenment is not
> > +         * available at the moment. The reference time can only be
> > +         * obtained from the Reference Counter MSR.
> > +         */
> > +        if ( seq == 0 )
> > +        {
> > +            rdmsrl(HV_X64_MSR_TIME_REF_COUNT, ret);
> > +            return ret;
> > +        }
> > +
> > +        /* rdtsc_ordered already contains a load fence */
> > +        tsc = rdtsc_ordered();
> > +        scale = tsc_page->tsc_scale;
> > +        offset = tsc_page->tsc_offset;
> > +
> > +        smp_rmb();
> > +
> > +    } while (tsc_page->tsc_sequence != seq);
> > +
> > +    /* ret = ((tsc * scale) >> 64) + offset; */
> > +    asm ( "mul %[scale]; add %[offset], %[ret]"
> > +          : "+a" (tsc), [ret] "=d" (ret)
> 
> This needs to be "=&d", or else %rdx may be used to address
> %[offset] (when in memory).
> 
> With these taken care of
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> 

Thanks. I have addressed yours, Andrew's and Paul's comment (checking
HV_X64_ACCESS_FREQUENCY_MSRS) and will push patches that are needed for
this clock source to work (patch 1, 5 and 6).

Patches for cleaning up viridian code (2-4) will be posted separately
with Paul's comments addressed.

Wei.

> Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

      parent reply	other threads:[~2019-12-20 17:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 14:42 [Xen-devel] [PATCH v2 0/6] Implement Hyper-V reference TSC based clock source Wei Liu
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 1/6] x86: import hyperv-tlfs.h from Linux Wei Liu
2019-12-18 14:56   ` Durrant, Paul
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 2/6] x86/viridian: drop duplicate defines from private.h and viridian.c Wei Liu
2019-12-18 14:49   ` Durrant, Paul
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 3/6] x86/viridian: drop private copy of definitions from synic.c Wei Liu
2019-12-18 14:57   ` Durrant, Paul
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 4/6] x86/viridian: drop private copy of HV_REFERENCE_TSC_PAGE in time.c Wei Liu
2019-12-18 15:06   ` Durrant, Paul
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 5/6] x86/hyperv: extract more information from Hyper-V Wei Liu
2019-12-18 14:42 ` [Xen-devel] [PATCH v2 6/6] x86: implement Hyper-V clock source Wei Liu
2019-12-18 15:24   ` Durrant, Paul
2019-12-18 20:24     ` Michael Kelley
2019-12-18 22:20       ` Wei Liu
2019-12-19  8:37         ` Durrant, Paul
2019-12-20 16:05   ` Jan Beulich
2019-12-20 16:07     ` Andrew Cooper
2019-12-20 17:43     ` Wei Liu [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=20191220174313.dbfdkngqfb2hpozq@debian \
    --to=wl@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=liuwe@microsoft.com \
    --cc=mikelley@microsoft.com \
    --cc=pdurrant@amazon.com \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.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 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.