[Openmp-commits] [PATCH] D31008: Minor improvement of KMP_YIELD_NOW() macro.

Hansang Bae via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Mar 15 15:51:25 PDT 2017


hbae created this revision.

This change slightly improves performance of KMP_YIELD_NOW() macro, by using _rdtsc() intrinsic function if possible.


Repository:
  rL LLVM

https://reviews.llvm.org/D31008

Files:
  runtime/src/kmp.h
  runtime/src/z_Linux_util.cpp


Index: runtime/src/z_Linux_util.cpp
===================================================================
--- runtime/src/z_Linux_util.cpp
+++ runtime/src/z_Linux_util.cpp
@@ -90,7 +90,7 @@
 static kmp_cond_align_t    __kmp_wait_cv;
 static kmp_mutex_align_t   __kmp_wait_mx;
 
-double __kmp_ticks_per_nsec;
+kmp_uint64 __kmp_ticks_per_msec = 1000000;
 
 /* ------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------ */
@@ -2157,16 +2157,16 @@
 }
 
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
-/* Measure clock tick per nanosecond */
+/* Measure clock ticks per millisecond */
 void
 __kmp_initialize_system_tick()
 {
     kmp_uint64 delay = 100000; // 50~100 usec on most machines.
     kmp_uint64 nsec = __kmp_now_nsec();
     kmp_uint64 goal = __kmp_hardware_timestamp() + delay;
     kmp_uint64 now;
     while ((now = __kmp_hardware_timestamp()) < goal);
-    __kmp_ticks_per_nsec = 1.0 * (delay + (now - goal)) / (__kmp_now_nsec() - nsec);
+    __kmp_ticks_per_msec = (kmp_uint64)(1e6 * (delay + (now - goal)) / (__kmp_now_nsec() - nsec));
 }
 #endif
 
Index: runtime/src/kmp.h
===================================================================
--- runtime/src/kmp.h
+++ runtime/src/kmp.h
@@ -894,10 +894,14 @@
 #else
 # if KMP_OS_UNIX && (KMP_ARCH_X86 || KMP_ARCH_X86_64)
    // HW TSC is used to reduce overhead (clock tick instead of nanosecond).
-   extern double __kmp_ticks_per_nsec;
-#  define KMP_NOW() __kmp_hardware_timestamp()
-#  define KMP_NOW_MSEC() ((kmp_uint64)(KMP_NOW()/__kmp_ticks_per_nsec)/KMP_USEC_PER_SEC)
-#  define KMP_BLOCKTIME_INTERVAL() (__kmp_dflt_blocktime * KMP_USEC_PER_SEC * __kmp_ticks_per_nsec)
+   extern kmp_uint64 __kmp_ticks_per_msec;
+#  if KMP_COMPILER_ICC
+#   define KMP_NOW() _rdtsc()
+#  else
+#   define KMP_NOW() __kmp_hardware_timestamp()
+#  endif
+#  define KMP_NOW_MSEC() (KMP_NOW()/__kmp_ticks_per_msec)
+#  define KMP_BLOCKTIME_INTERVAL() (__kmp_dflt_blocktime * __kmp_ticks_per_msec)
 #  define KMP_BLOCKING(goal, count) ((goal) > KMP_NOW())
 # else
    // System time is retrieved sporadically while blocking.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31008.91948.patch
Type: text/x-patch
Size: 2156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20170315/4e9f36cd/attachment.bin>


More information about the Openmp-commits mailing list