]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Tue, 26 Apr 2011 21:20:13 +0000 (14:20 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 26 Apr 2011 21:20:13 +0000 (14:20 -0700)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/vm_basic_asm.h

index d0b270ee14b186e88bd28b3095291dcc7af4b909..76547c065195cee923b85f6d5e67124b6b88aae6 100644 (file)
@@ -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__
+
 /*
  *-----------------------------------------------------------------------------
  *