diff options
author | Terry Wilmarth <terry.l.wilmarth@intel.com> | 2023-08-10 14:29:51 -0500 |
---|---|---|
committer | Terry Wilmarth <terry.l.wilmarth@intel.com> | 2023-08-18 14:01:13 -0500 |
commit | f0221fb1d7a9dd9af67018494db1999d251be067 (patch) | |
tree | 465b49efb052a881286394127ec0a0301c1491af /openmp/runtime/src/z_Linux_util.cpp | |
parent | bbbb93eb48debcebe8fffbc845c8794740e2ebd3 (diff) | |
download | llvm-f0221fb1d7a9dd9af67018494db1999d251be067.zip llvm-f0221fb1d7a9dd9af67018494db1999d251be067.tar.gz llvm-f0221fb1d7a9dd9af67018494db1999d251be067.tar.bz2 |
[OpenMP] Add option to use different units for blocktime
This change adds the option of using different units for blocktimes specified via the KMP_BLOCKTIME environment variable. The parsing of the environment now recognizes units suffixes: ms and us. If a units suffix is not specified, the default unit is ms. Thus default behavior is still the same, and any previous usage still works the same. Internally, blocktime is now converted to microseconds everywhere, so settings that exceed INT_MAX in microseconds are considered "infinite".
kmp_set/get_blocktime are updated to use the units the user specified with KMP_BLOCKTIME, and if not specified, ms are used.
Added better range checking and inform messages for the two time units. Large values of blocktime for default (ms) case (beyond INT_MAX/1000) are no longer allowed, but will autocorrect with an INFORM message.
The delay for determining ticks per usec was lowered. It is now 1 million ticks which was calculated as ~450us based on 2.2GHz clock which is pretty typical base clock frequency on X86:
(1e6 Ticks) / (2.2e9 Ticks/sec) * (1e6 usec/sec) = 454 usec
Really short benchmarks can be affected by longer delay.
Update KMP_BLOCKTIME docs.
Portions of this commit were authored by Johnny Peyton.
Differential Revision: https://reviews.llvm.org/D157646
Diffstat (limited to 'openmp/runtime/src/z_Linux_util.cpp')
-rw-r--r-- | openmp/runtime/src/z_Linux_util.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp index 56022e1..db69da2 100644 --- a/openmp/runtime/src/z_Linux_util.cpp +++ b/openmp/runtime/src/z_Linux_util.cpp @@ -93,6 +93,7 @@ static kmp_cond_align_t __kmp_wait_cv; static kmp_mutex_align_t __kmp_wait_mx; kmp_uint64 __kmp_ticks_per_msec = 1000000; +kmp_uint64 __kmp_ticks_per_usec = 1000; #ifdef DEBUG_SUSPEND static void __kmp_print_cond(char *buffer, kmp_cond_align_t *cond) { @@ -2002,7 +2003,7 @@ kmp_uint64 __kmp_now_nsec() { /* 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 delay = 1000000; // ~450 usec on most machines. kmp_uint64 nsec = __kmp_now_nsec(); kmp_uint64 goal = __kmp_hardware_timestamp() + delay; while ((now = __kmp_hardware_timestamp()) < goal) @@ -2010,9 +2011,11 @@ void __kmp_initialize_system_tick() { 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; + double tpus = 1000.0 * (double)(delay + (now - goal)) / (double)diff; + if (tpus > 0.0) { + __kmp_ticks_per_msec = (kmp_uint64)(tpus * 1000.0); + __kmp_ticks_per_usec = (kmp_uint64)tpus; + } } } #endif |