Skip to content

Commit d4a7b8d

Browse files
Daniel DouglasJonathan Peyton
authored andcommitted
[OpenMP][libomp] avoid spin wait and yield on arm64 macOS
This patch changes the default behavior to avoid spin waiting and yielding. (See “Don’t Keep Threads Active And Idle” section here: https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon) We verified using instruments traces that the changes improve scheduling behavior on macOS. We also collected results using EPCC schedbench (https://github.com/LangdalP/EPCC-OpenMP-micro-benchmarks) that are attached here that show a reduction in standard deviation and max test run time across all scheduling types. Static scheduling sees dramatic improvements with these changes, we see a 2-4x average runtime improvement in the benchmark. Differential Revision: https://reviews.llvm.org/D126510
1 parent 42bb88e commit d4a7b8d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

openmp/runtime/src/kmp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,8 @@ extern int __kmp_storage_map_verbose_specified;
30613061
#if KMP_ARCH_X86 || KMP_ARCH_X86_64
30623062
extern kmp_cpuinfo_t __kmp_cpuinfo;
30633063
static inline bool __kmp_is_hybrid_cpu() { return __kmp_cpuinfo.flags.hybrid; }
3064+
#elif KMP_OS_DARWIN && KMP_ARCH_AARCH64
3065+
static inline bool __kmp_is_hybrid_cpu() { return true; }
30643066
#else
30653067
static inline bool __kmp_is_hybrid_cpu() { return false; }
30663068
#endif

openmp/runtime/src/kmp_global.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,13 @@ int __kmp_env_consistency_check = FALSE; /* KMP_CONSISTENCY_CHECK specified? */
425425
// 0 = never yield;
426426
// 1 = always yield (default);
427427
// 2 = yield only if oversubscribed
428+
#if KMP_OS_DARWIN && KMP_ARCH_AARCH64
429+
// Set to 0 for environments where yield is slower
430+
kmp_int32 __kmp_use_yield = 0;
431+
#else
428432
kmp_int32 __kmp_use_yield = 1;
433+
#endif
434+
429435
// This will be 1 if KMP_USE_YIELD environment variable was set explicitly
430436
kmp_int32 __kmp_use_yield_exp_set = 0;
431437

openmp/runtime/src/kmp_runtime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8300,7 +8300,7 @@ void __kmp_aux_set_library(enum library_type arg) {
83008300
break;
83018301
case library_throughput:
83028302
if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME)
8303-
__kmp_dflt_blocktime = 200;
8303+
__kmp_dflt_blocktime = KMP_DEFAULT_BLOCKTIME;
83048304
break;
83058305
default:
83068306
KMP_FATAL(UnknownLibraryType, arg);

0 commit comments

Comments
 (0)