[Openmp-commits] [PATCH] D21305: Bug fixes in lock code.

Terry Wilmarth via Openmp-commits openmp-commits at lists.llvm.org
Mon Jun 13 13:26:33 PDT 2016


tlwilmar created this revision.
tlwilmar added a reviewer: hbae.
tlwilmar added a subscriber: openmp-commits.
tlwilmar set the repository for this revision to rL LLVM.

(Parts of this change were already applied to LLVM code base.)

This change set fixes two bugs in the lock code.

1. Misplaced switch target in the __kmp_get_user_lock_owner function
   found by LLVM user
2. Use of incorrect time-stamp counter in the __kmp_spin_backoff
   function for non-Intel architecture, found by Jim

A new utility function __kmp_now_nsec() was added for the second item,
and code for handling wrap-around counters (provided by Jim) was also
added for the __kmp_spin_backoff function.

Patch by Hansang Bae


Repository:
  rL LLVM

http://reviews.llvm.org/D21305

Files:
  runtime/src/kmp_lock.cpp
  runtime/src/z_Linux_util.c

Index: runtime/src/z_Linux_util.c
===================================================================
--- runtime/src/z_Linux_util.c
+++ runtime/src/z_Linux_util.c
@@ -2205,14 +2205,16 @@
     *t = 1 / (double) CLOCKS_PER_SEC;
 }
 
+#if KMP_OS_LINUX
 /* Return the current time stamp in nsec */
 kmp_uint64
 __kmp_now_nsec()
 {
-    struct timeval t;
-    gettimeofday(&t, NULL);
-    return KMP_NSEC_PER_SEC*t.tv_sec + 1000*t.tv_usec;
+    struct timespec t;
+    clock_gettime(CLOCK_MONOTONIC, &t);
+    return 1e9*t.tv_sec + t.tv_nsec;
 }
+#endif
 
 /*
     Determine whether the given address is mapped into the current address space.
Index: runtime/src/kmp_lock.cpp
===================================================================
--- runtime/src/kmp_lock.cpp
+++ runtime/src/kmp_lock.cpp
@@ -3021,13 +3021,12 @@
 // Time stamp counter
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
 # define __kmp_tsc() __kmp_hardware_timestamp()
-// Runtime's default backoff parameters
-kmp_backoff_t __kmp_spin_backoff_params = { 1, 4096, 100 };
-#else
-// Use nanoseconds for other platforms
-extern kmp_uint64 __kmp_now_nsec();
-kmp_backoff_t __kmp_spin_backoff_params = { 1, 256, 100 };
+#elif KMP_OS_LINUX
+  // Use nanoseconds for other platforms
+  extern kmp_uint64 __kmp_now_nsec();
 # define __kmp_tsc() __kmp_now_nsec()
+#else
+# error time stamp counter is not supported
 #endif
 
 // A useful predicate for dealing with timestamps that may wrap.
@@ -3043,6 +3042,9 @@
     return ((kmp_int64)b - (kmp_int64)a) > 0;
 }
 
+// Runtime's default backoff parameters
+kmp_backoff_t __kmp_spin_backoff_params = { 1, 4096, 100 };
+
 // Truncated binary exponential backoff function
 void
 __kmp_spin_backoff(kmp_backoff_t *boff)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21305.60594.patch
Type: text/x-patch
Size: 1719 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20160613/e6cc962a/attachment.bin>


More information about the Openmp-commits mailing list