[Openmp-commits] [PATCH] D55300: Fix transient divide by zero bug in 32-bit code

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Dec 13 15:22:15 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rOMP349090: [OpenMP] Fix transient divide by zero bug in 32-bit code (authored by jlpeyton, committed by ).

Repository:
  rOMP OpenMP

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55300/new/

https://reviews.llvm.org/D55300

Files:
  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
@@ -1935,20 +1935,27 @@
 kmp_uint64 __kmp_now_nsec() {
   struct timeval t;
   gettimeofday(&t, NULL);
-  return KMP_NSEC_PER_SEC * t.tv_sec + 1000 * t.tv_usec;
+  kmp_uint64 nsec = (kmp_uint64)KMP_NSEC_PER_SEC * (kmp_uint64)t.tv_sec +
+                    (kmp_uint64)1000 * (kmp_uint64)t.tv_usec;
+  return nsec;
 }
 
 #if KMP_ARCH_X86 || KMP_ARCH_X86_64
 /* Measure clock ticks per millisecond */
 void __kmp_initialize_system_tick() {
+  kmp_uint64 now, nsec2, diff;
   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_msec =
-      (kmp_uint64)(1e6 * (delay + (now - goal)) / (__kmp_now_nsec() - nsec));
+  nsec2 = __kmp_now_nsec();
+  diff = nsec2 - nsec;
+  if (diff > 0) {
+    kmp_uint64 tpms = (kmp_uint64)(1e6 * (delay + (now - goal)) / diff);
+    if (tpms > 0)
+      __kmp_ticks_per_msec = tpms;
+  }
 }
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55300.178148.patch
Type: text/x-patch
Size: 1203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20181213/b69b9963/attachment.bin>


More information about the Openmp-commits mailing list