[OpenMP] Add upper limit to TPAUSE exponential backoff time
authorNawrin Sultana <nawrin.sultana@intel.com>
Fri, 30 Sep 2022 21:10:43 +0000 (16:10 -0500)
committerNawrin Sultana <nawrin.sultana@intel.com>
Mon, 17 Oct 2022 15:22:11 +0000 (10:22 -0500)
Differential Revision: https://reviews.llvm.org/D135003

openmp/runtime/src/kmp.h

index 6aeb495..df02f40 100644 (file)
@@ -1472,6 +1472,7 @@ static inline void __kmp_x86_pause(void) { _mm_pause(); }
 // requested. Uses a timed TPAUSE, and exponential backoff. If TPAUSE isn't
 // available, fall back to the regular CPU pause and yield combination.
 #if KMP_HAVE_UMWAIT
+#define KMP_TPAUSE_MAX_MASK ((kmp_uint64)0xFFFF)
 #define KMP_YIELD_OVERSUB_ELSE_SPIN(count, time)                               \
   {                                                                            \
     if (__kmp_tpause_enabled) {                                                \
@@ -1480,7 +1481,7 @@ static inline void __kmp_x86_pause(void) { _mm_pause(); }
       } else {                                                                 \
         __kmp_tpause(__kmp_tpause_hint, (time));                               \
       }                                                                        \
-      (time) *= 2;                                                             \
+      (time) = (time << 1 | 1) & KMP_TPAUSE_MAX_MASK;                          \
     } else {                                                                   \
       KMP_CPU_PAUSE();                                                         \
       if ((KMP_TRY_YIELD_OVERSUB)) {                                           \