From: VMware, Inc <> Date: Tue, 26 Apr 2011 21:20:13 +0000 (-0700) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2011.04.25-402641~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0c6dd9fd73bbb4d1498faf66149c01a7d503015;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/vm_basic_asm.h b/open-vm-tools/lib/include/vm_basic_asm.h index d0b270ee1..76547c065 100644 --- a/open-vm-tools/lib/include/vm_basic_asm.h +++ b/open-vm-tools/lib/include/vm_basic_asm.h @@ -107,6 +107,10 @@ void _WriteBarrier(void); void _ReadWriteBarrier(void); #pragma intrinsic(_ReadBarrier, _WriteBarrier, _ReadWriteBarrier) +void _mm_mfence(void); +void _mm_lfence(void); +#pragma intrinsic(_mm_mfence, _mm_lfence) + #ifdef VM_X86_64 /* * intrinsic functions only supported by x86-64 windows as of 2k3sp1 @@ -879,6 +883,56 @@ RDTSC(void) #error No compiler defined for RDTSC #endif /* __GNUC__ */ +#if defined(__i386__) || defined(__x86_64__) +/* + *----------------------------------------------------------------------------- + * + * RDTSC_BARRIER -- + * + * Implements an RDTSC fence. Instructions executed prior to the + * fence will have completed before the fence and all stores to + * memory are flushed from the store buffer. + * + * On AMD, MFENCE is sufficient. On Intel, only LFENCE is + * documented to fence RDTSC, but LFENCE won't drain the store + * buffer. So, use MFENCE;LFENCE, which will work on both AMD and + * Intel. + * + * It is the callers' responsibility to check for SSE2 before + * calling this function. + * + * Results: + * None. + * + * Side effects: + * Cause loads and stores prior to this to be globally visible, and + * RDTSC will not pass. + * + *----------------------------------------------------------------------------- + */ + +static INLINE void +RDTSC_BARRIER(void) +{ +#ifdef __GNUC__ + __asm__ __volatile__( + "mfence \n\t" + "lfence \n\t" + ::: "memory" + ); +#elif defined _MSC_VER + /* Prevent compiler from moving code across mfence/lfence. */ + _ReadWriteBarrier(); + _mm_mfence(); + _mm_lfence(); + _ReadWriteBarrier(); +#else +#error No compiler defined for RDTSC_BARRIER +#endif +} + +#endif // __i386 || __x86_64__ + /* *----------------------------------------------------------------------------- *