From: "Jan Beulich" Subject: Re: [PATCH] x86: Adjust rdtsc inline assembly Date: Wed, 18 Feb 2015 13:11:37 +0000 Message-ID: <54E49D99020000780006114E@mail.emea.novell.com> References: <1424262318-3405-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1424262318-3405-1-git-send-email-andrew.cooper3@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Keir Fraser , Xen-devel List-Id: xen-devel@lists.xenproject.org >>> On 18.02.15 at 13:25, wrote: > The single use of the old rdtsc() in emulate_privileged_op() is altered to use > the new rdtsc() and the rdmsr_writeback path to set eax/edx appropriately. I'm not entirely sure about this one - the current code surely is slightly faster than the replacement. Question is how much this matters. I'd suggest to be on the safe side and simply open-code the asm() there. If you decide to follow that, there are a few more cosmetic things which otherwise I would adjust while committing: > @@ -1426,13 +1426,13 @@ static void __init tsc_check_writability(void) > if ( boot_cpu_has(X86_FEATURE_TSC_RELIABLE) ) > return; > > - rdtscll(tsc); > + tsc = rdtsc(); > if ( wrmsr_safe(MSR_IA32_TSC, 0) == 0 ) > { > uint64_t tmp, tmp2; > - rdtscll(tmp2); > + tmp2 = rdtsc(); Blank line between declaration and statements. And perhaps the assignment could become the variable's initializer. > @@ -1973,8 +1973,7 @@ void tsc_set_info(struct domain *d, > else { > /* when using native TSC, offset is nsec relative to power-on > * of physical machine */ > - uint64_t tsc = 0; > - rdtscll(tsc); > + uint64_t tsc = rdtsc(); > d->arch.vtsc_offset = scale_delta(tsc,&d->arch.vtsc_to_ns) - Blank line missing again. > --- a/xen/include/asm-x86/msr.h > +++ b/xen/include/asm-x86/msr.h > @@ -71,17 +71,14 @@ static inline int wrmsr_safe(unsigned int msr, uint64_t val) > return _rc; > } > > -#define rdtsc(low,high) \ > - __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) > +static inline uint64_t rdtsc(void) > +{ > + uint32_t low, high; > > -#define rdtscl(low) \ > - __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx") > + __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)); > > -#define rdtscll(val) do { \ > - unsigned int _eax, _edx; \ > - asm volatile("rdtsc" : "=a" (_eax), "=d" (_edx)); \ > - (val) = ((unsigned long)_eax) | (((unsigned long)_edx)<<32); \ > -} while(0) > + return (uint64_t)high << 32 | low; Parentheses around the << please. Jan