99 * University of Stuttgart. All rights reserved.
1010 * Copyright (c) 2004-2005 The Regents of the University of California.
1111 * All rights reserved.
12- * Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
12+ * Copyright (c) 2006-2022 Cisco Systems, Inc. All rights reserved
1313 * Copyright (c) 2015 Research Organization for Information Science
1414 * and Technology (RIST). All rights reserved.
1515 * Copyright (c) 2017 IBM Corporation. All rights reserved.
3131#include <time.h>
3232#endif /* HAVE_TIME_H */
3333
34- #include MCA_timer_IMPLEMENTATION_HEADER
3534#include "ompi/mpi/c/bindings.h"
3635#include "ompi/runtime/mpiruntime.h"
3736#include "ompi/runtime/ompi_spc.h"
3837
38+ #include "opal/util/clock_gettime.h"
39+
3940#if OMPI_BUILD_MPI_PROFILING
4041#if OPAL_HAVE_WEAK_SYMBOLS
4142#pragma weak MPI_Wtime = PMPI_Wtime
4647 * and accuracy of the user visible timer.
4748 * More info: https://github.com/mpi-forum/mpi-issues/issues/77#issuecomment-369663119
4849 */
49- #if defined(__linux__ ) && OPAL_HAVE_CLOCK_GETTIME
5050struct timespec ompi_wtime_time_origin = {.tv_sec = 0 };
51- #else
52- struct timeval ompi_wtime_time_origin = {.tv_sec = 0 };
53- #endif
5451#else /* OMPI_BUILD_MPI_PROFILING */
55- #if defined(__linux__ ) && OPAL_HAVE_CLOCK_GETTIME
5652extern struct timespec ompi_wtime_time_origin ;
57- #else
58- extern struct timeval ompi_wtime_time_origin ;
59- #endif
6053#endif
6154
6255double MPI_Wtime (void )
@@ -65,36 +58,15 @@ double MPI_Wtime(void)
6558
6659 SPC_RECORD (OMPI_SPC_WTIME , 1 );
6760
68- /*
69- * See https://github.com/open-mpi/ompi/issues/3003 to find out
70- * what's happening here.
71- */
72- #if 0
73- #if OPAL_TIMER_CYCLE_NATIVE
74- wtime = ((double ) opal_timer_base_get_cycles ()) / opal_timer_base_get_freq ();
75- #elif OPAL_TIMER_USEC_NATIVE
76- wtime = ((double ) opal_timer_base_get_usec ()) / 1000000.0 ;
77- #endif
78- #else
79- #if defined(__linux__ ) && OPAL_HAVE_CLOCK_GETTIME
61+ // We intentionally don't use the OPAL timer framework here. See
62+ // https://github.com/open-mpi/ompi/issues/3003 for more details.
8063 struct timespec tp ;
81- (void ) clock_gettime ( CLOCK_MONOTONIC , & tp );
82- if ( OPAL_UNLIKELY (0 == ompi_wtime_time_origin .tv_sec ) ) {
64+ (void ) opal_clock_gettime ( & tp );
65+ if ( OPAL_UNLIKELY (0 == ompi_wtime_time_origin .tv_sec )) {
8366 ompi_wtime_time_origin = tp ;
8467 }
8568 wtime = (double )(tp .tv_nsec - ompi_wtime_time_origin .tv_nsec )/1.0e+9 ;
8669 wtime += (tp .tv_sec - ompi_wtime_time_origin .tv_sec );
87- #else
88- /* Fall back to gettimeofday() if we have nothing else */
89- struct timeval tv ;
90- gettimeofday (& tv , NULL );
91- if ( OPAL_UNLIKELY (0 == ompi_wtime_time_origin .tv_sec ) ) {
92- ompi_wtime_time_origin = tv ;
93- }
94- wtime = (double )(tv .tv_usec - ompi_wtime_time_origin .tv_usec ) / 1.0e+6 ;
95- wtime += (tv .tv_sec - ompi_wtime_time_origin .tv_sec );
96- #endif
97- #endif
9870
9971 return wtime ;
10072}
0 commit comments