[Openmp-commits] [openmp] r298314 - Minor improvement of KMP_YIELD_NOW() macro.

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Mon Mar 20 15:11:32 PDT 2017


Author: jlpeyton
Date: Mon Mar 20 17:11:31 2017
New Revision: 298314

URL: http://llvm.org/viewvc/llvm-project?rev=298314&view=rev
Log:
Minor improvement of KMP_YIELD_NOW() macro.

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

Patch by Hansang Bae

Differential Revision: https://reviews.llvm.org/D31008

Modified:
    openmp/trunk/runtime/src/kmp.h
    openmp/trunk/runtime/src/z_Linux_util.cpp

Modified: openmp/trunk/runtime/src/kmp.h
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp.h?rev=298314&r1=298313&r2=298314&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp.h (original)
+++ openmp/trunk/runtime/src/kmp.h Mon Mar 20 17:11:31 2017
@@ -894,10 +894,14 @@ extern int __kmp_place_num_threads_per_c
 #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.

Modified: openmp/trunk/runtime/src/z_Linux_util.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/z_Linux_util.cpp?rev=298314&r1=298313&r2=298314&view=diff
==============================================================================
--- openmp/trunk/runtime/src/z_Linux_util.cpp (original)
+++ openmp/trunk/runtime/src/z_Linux_util.cpp Mon Mar 20 17:11:31 2017
@@ -90,7 +90,7 @@ static pthread_mutexattr_t __kmp_suspend
 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,7 +2157,7 @@ __kmp_now_nsec()
 }
 
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
-/* Measure clock tick per nanosecond */
+/* Measure clock ticks per millisecond */
 void
 __kmp_initialize_system_tick()
 {
@@ -2166,7 +2166,7 @@ __kmp_initialize_system_tick()
     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
 




More information about the Openmp-commits mailing list