All of lore.kernel.org
 help / color / mirror / Atom feed
From: Haozhong Zhang <haozhong.zhang@intel.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Kevin Tian <kevin.tian@intel.com>, Keir Fraser <keir@xen.org>,
	Jun Nakajima <jun.nakajima@intel.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	xen-devel@lists.xen.org,
	Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>
Subject: Re: [PATCH v5 2/6] x86/hvm: Setup TSC scaling ratio
Date: Wed, 24 Feb 2016 23:42:47 +0800	[thread overview]
Message-ID: <20160224154247.GB14964@hz-desktop.sh.intel.com> (raw)
In-Reply-To: <56CDD3DB02000078000D5BED@prv-mh.provo.novell.com>

On 02/24/16 08:01, Jan Beulich wrote:
> >>> On 23.02.16 at 03:05, <haozhong.zhang@intel.com> wrote:
> > --- a/xen/arch/x86/hvm/hvm.c
> > +++ b/xen/arch/x86/hvm/hvm.c
> > @@ -298,6 +298,29 @@ int hvm_set_guest_pat(struct vcpu *v, u64 guest_pat)
> >      return 1;
> >  }
> >  
> > +/*
> > + * Get the ratio to scale host TSC frequency to gtsc_khz. zero will be
> > + * returned if TSC scaling is unavailable or ratio cannot be handled
> > + * by host CPU. Otherwise, a non-zero ratio will be returned.
> > + */
> > +u64 hvm_get_tsc_scaling_ratio(u32 gtsc_khz)
> > +{
> > +    u64 ratio = gtsc_khz;
> > +    u64 dummy = 0;
> 
> "dummy" suggests it is unused, which it isn't. "tmp" or "hi" might be
> a little better, but since the meanings of the variables (also "ratio")
> differ for their roles an inputs and outputs, splitting inputs and
> outputs below would seem even better. In which case "dummy"
> become would an appropriate name again.
>

Yes, I'll split input and outputs for dummy and ratio.

> > +    if ( !hvm_tsc_scaling_supported )
> > +        return 0;
> > +
> > +    /* ratio = (gtsc_khz << hvm_funcs.tsc_scaling.ratio_frac_bits) / cpu_khz */
> > +    asm (
> > +        "shldq %2,%1,%0; salq %2,%1; divq %3"
> > +        : "+&d" (dummy), "+&a" (ratio)
> > +        : "c" (hvm_funcs.tsc_scaling.ratio_frac_bits),
> > +          "rm" ((u64) cpu_khz) );
> 
> And this DIVQ can't possibly #DE, e.g. when gtsc_khz is much larger
> than cpu_khz?
>

Oops, it could. Following check should be added before asm():
        /* the quotient is too large to fit in the integral part of TSC scaling ratio */
        if ( gtsc_khz / cpu_khz >
             (hvm_funcs.tsc_scaling.max_ratio >> hvm_funcs.tsc_scaling.ratio_frac_bits )
            return 0;

> I'd also prefer if the instruction got put on the same line as the
> "asm (". Considering that we're dealing with unsigned quantities
> here I'd further prefer if SHLQ was used instead of SALQ. And
> finally I'd suggest using named rather than numbered asm()
> arguments.
>

I'll make all these three changes.

> > --- a/xen/include/asm-x86/hvm/hvm.h
> > +++ b/xen/include/asm-x86/hvm/hvm.h
> > @@ -272,6 +272,14 @@ u64 hvm_get_guest_tsc_fixed(struct vcpu *v, u64 at_tsc);
> >  #define hvm_tsc_scaling_supported \
> >      (!!hvm_funcs.tsc_scaling.ratio_frac_bits)
> >  
> > +#define hvm_default_tsc_scaling_ratio \
> > +    (1ULL << hvm_funcs.tsc_scaling.ratio_frac_bits)
> > +
> > +#define hvm_vcpu_tsc_scaling_ratio(v) \
> > +    ((v)->domain->arch.hvm_domain.tsc_scaling_ratio)
> 
> Since this is now a per-domain property I think it is misleading (and
> potentially hindering) for the called to pass in a struct vcpu * here.
> Please make this a struct domain *.
>

I'll change to struct domain *, and also remove _vcpu in the name.

Thanks,
Haozhong

  reply	other threads:[~2016-02-24 15:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-23  2:04 [PATCH v5 0/6] Add VMX TSC scaling support Haozhong Zhang
2016-02-23  2:04 ` [PATCH v5 1/6] x86/hvm: Collect information of TSC scaling ratio Haozhong Zhang
2016-02-23 14:00   ` Boris Ostrovsky
2016-02-23 14:10     ` Jan Beulich
2016-02-23 14:16       ` Boris Ostrovsky
2016-02-23 15:37         ` Jan Beulich
2016-02-24  6:00           ` Haozhong Zhang
2016-02-24 13:46             ` Haozhong Zhang
2016-02-24 14:49               ` Boris Ostrovsky
2016-02-24 14:36   ` Jan Beulich
2016-02-24 15:03     ` Haozhong Zhang
2016-02-26  4:27   ` Tian, Kevin
2016-02-23  2:05 ` [PATCH v5 2/6] x86/hvm: Setup " Haozhong Zhang
2016-02-24 15:01   ` Jan Beulich
2016-02-24 15:42     ` Haozhong Zhang [this message]
2016-02-24 15:51       ` Jan Beulich
2016-02-24 16:05         ` Haozhong Zhang
2016-02-23  2:05 ` [PATCH v5 3/6] x86/hvm: Replace architecture TSC scaling by a common function Haozhong Zhang
2016-02-24 15:07   ` Jan Beulich
2016-02-26  4:30   ` Tian, Kevin
2016-02-23  2:05 ` [PATCH v5 4/6] x86/hvm: Move saving/loading vcpu's TSC to common code Haozhong Zhang
2016-02-23  2:05 ` [PATCH v5 5/6] vmx: Add VMX RDTSC(P) scaling support Haozhong Zhang
2016-02-24 15:09   ` Jan Beulich
2016-02-26  4:31   ` Tian, Kevin
2016-02-23  2:05 ` [PATCH v5 6/6] docs: Add descriptions of TSC scaling in xl.cfg and tscmode.txt Haozhong Zhang
2016-02-26  4:37   ` Tian, Kevin
2016-02-26  4:44     ` Zhang, Haozhong
2016-02-26  8:01     ` Jan Beulich
2016-02-26  8:05       ` Haozhong Zhang
2016-02-29  2:02       ` Tian, Kevin
2016-02-29  2:45         ` Zhang, Haozhong
2016-02-29  9:04           ` Jan Beulich

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=20160224154247.GB14964@hz-desktop.sh.intel.com \
    --to=haozhong.zhang@intel.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jun.nakajima@intel.com \
    --cc=keir@xen.org \
    --cc=kevin.tian@intel.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=xen-devel@lists.xen.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.