[flang-commits] [flang] 3d0e0e1 - [flang][runtime] Prefer process time over thread time in CPU_TIME

Mats Petersson via flang-commits flang-commits at lists.llvm.org
Mon Apr 11 02:45:00 PDT 2022


Author: Mats Petersson
Date: 2022-04-11T10:44:33+01:00
New Revision: 3d0e0e1027203fe5e89104ad81ee7bb53e525f95

URL: https://github.com/llvm/llvm-project/commit/3d0e0e1027203fe5e89104ad81ee7bb53e525f95
DIFF: https://github.com/llvm/llvm-project/commit/3d0e0e1027203fe5e89104ad81ee7bb53e525f95.diff

LOG: [flang][runtime] Prefer process time over thread time in CPU_TIME

Most Fortran compilers appear to return the process time
for calls to CPU_TIME, where the flang implementation
prior to this change was returning the time used by the
current thread. This would cause incorrect time being
reported when for example OpenMP is used to share work
across multiple CPUs.

This patch changes the order so the selection of "what
time to return" so that if there is a process time to
report, that is the reported value, and only if that is
not available, the thread time is considerd instead.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D123416

Added: 
    

Modified: 
    flang/runtime/time-intrinsic.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/time-intrinsic.cpp b/flang/runtime/time-intrinsic.cpp
index 83ba370c0a7d3..502a94ade75c0 100644
--- a/flang/runtime/time-intrinsic.cpp
+++ b/flang/runtime/time-intrinsic.cpp
@@ -56,10 +56,10 @@ template <typename Unused = void> double GetCpuTime(fallback_implementation) {
   return -1.0;
 }
 
-#if defined CLOCK_THREAD_CPUTIME_ID
-#define CLOCKID CLOCK_THREAD_CPUTIME_ID
-#elif defined CLOCK_PROCESS_CPUTIME_ID
+#if defined CLOCK_PROCESS_CPUTIME_ID
 #define CLOCKID CLOCK_PROCESS_CPUTIME_ID
+#elif defined CLOCK_THREAD_CPUTIME_ID
+#define CLOCKID CLOCK_THREAD_CPUTIME_ID
 #elif defined CLOCK_MONOTONIC
 #define CLOCKID CLOCK_MONOTONIC
 #else


        


More information about the flang-commits mailing list