Skip to content

Commit 5cb802b

Browse files
authored
Merge pull request #3203 from jsquyres/pr/v2.0.x/fix-wtick-wtime
v2.0.x/fix wtick wtime
2 parents f09a7a6 + 43ab707 commit 5cb802b

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

ompi/mpi/c/wtick.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015-2016 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17+
* reserved.
1518
* $COPYRIGHT$
1619
*
1720
* Additional copyrights may follow
@@ -24,6 +27,9 @@
2427
#include <sys/time.h>
2528
#endif
2629
#include <stdio.h>
30+
#ifdef HAVE_TIME_H
31+
#include <time.h>
32+
#endif
2733

2834
#include MCA_timer_IMPLEMENTATION_HEADER
2935
#include "ompi/mpi/c/bindings.h"
@@ -38,6 +44,11 @@
3844

3945
double MPI_Wtick(void)
4046
{
47+
/*
48+
* See https://github.com/open-mpi/ompi/issues/3003
49+
* to get an idea what's going on here.
50+
*/
51+
#if 0
4152
#if OPAL_TIMER_CYCLE_NATIVE
4253
{
4354
opal_timer_t freq = opal_timer_base_get_freq();
@@ -50,8 +61,21 @@ double MPI_Wtick(void)
5061
}
5162
#elif OPAL_TIMER_USEC_NATIVE
5263
return 0.000001;
64+
#endif
65+
#else
66+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
67+
struct timespec spec;
68+
double wtick = 0.0;
69+
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
70+
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
71+
} else {
72+
/* guess */
73+
wtick = 1.0e-09;
74+
}
75+
return wtick;
5376
#else
5477
/* Otherwise, we already return usec precision. */
5578
return 0.000001;
5679
#endif
80+
#endif
5781
}

ompi/mpi/c/wtime.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2017 IBM Corporation. All rights reserved.
16+
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
17+
* reserved.
1518
* $COPYRIGHT$
1619
*
1720
* Additional copyrights may follow
@@ -24,6 +27,9 @@
2427
#include <sys/time.h>
2528
#endif
2629
#include <stdio.h>
30+
#ifdef HAVE_TIME_H
31+
#include <time.h>
32+
#endif /* HAVE_TIME_H */
2733

2834
#include MCA_timer_IMPLEMENTATION_HEADER
2935
#include "ompi/mpi/c/bindings.h"
@@ -40,16 +46,29 @@ double MPI_Wtime(void)
4046
{
4147
double wtime;
4248

49+
/*
50+
* See https://github.com/open-mpi/ompi/issues/3003 to find out
51+
* what's happening here.
52+
*/
53+
#if 0
4354
#if OPAL_TIMER_CYCLE_NATIVE
4455
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
4556
#elif OPAL_TIMER_USEC_NATIVE
4657
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
58+
#endif
59+
#else
60+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
61+
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
62+
(void) clock_gettime(CLOCK_MONOTONIC, &tp);
63+
wtime = tp.tv_sec;
64+
wtime += tp.tv_nsec/1.0e+9;
4765
#else
4866
/* Fall back to gettimeofday() if we have nothing else */
4967
struct timeval tv;
5068
gettimeofday(&tv, NULL);
5169
wtime = tv.tv_sec;
5270
wtime += (double)tv.tv_usec / 1000000.0;
71+
#endif
5372
#endif
5473

5574
return wtime;

opal/mca/timer/linux/timer_linux.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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) 2017 Cisco Systems, Inc. All rights reserved
1213
* $COPYRIGHT$
1314
*
1415
* Additional copyrights may follow
@@ -22,8 +23,6 @@
2223
#include "opal_config.h"
2324
#include <opal/sys/timer.h>
2425

25-
OPAL_DECLSPEC extern opal_timer_t opal_timer_linux_freq;
26-
2726
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_cycles)(void);
2827
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void);
2928

opal/mca/timer/linux/timer_linux_component.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
1616
* reserved.
17-
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
17+
* Copyright (c) 2015-2017 Cisco Systems, Inc. All rights reserved
1818
* Copyright (c) 2017 IBM Corporation. All rights reserved.
19+
* Copyright (c) 2016 Broadcom Limited. All rights reserved.
1920
* $COPYRIGHT$
2021
*
2122
* Additional copyrights may follow
@@ -33,20 +34,25 @@
3334
#include "opal/constants.h"
3435
#include "opal/util/show_help.h"
3536

36-
static opal_timer_t opal_timer_base_get_cycles_sys_timer(void);
37-
static opal_timer_t opal_timer_base_get_usec_sys_timer(void);
37+
static opal_timer_t opal_timer_linux_get_cycles_sys_timer(void);
38+
static opal_timer_t opal_timer_linux_get_usec_sys_timer(void);
3839

3940
#if OPAL_HAVE_CLOCK_GETTIME
40-
static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void);
41-
static opal_timer_t opal_timer_base_get_usec_clock_gettime(void);
42-
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_clock_gettime;
43-
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_clock_gettime;
41+
static opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void);
42+
static opal_timer_t opal_timer_linux_get_usec_clock_gettime(void);
43+
44+
opal_timer_t (*opal_timer_base_get_cycles)(void) =
45+
opal_timer_linux_get_cycles_clock_gettime;
46+
opal_timer_t (*opal_timer_base_get_usec)(void) =
47+
opal_timer_linux_get_usec_clock_gettime;
4448
#else
45-
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer;
46-
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer;
49+
opal_timer_t (*opal_timer_base_get_cycles)(void) =
50+
opal_timer_linux_get_cycles_sys_timer;
51+
opal_timer_t (*opal_timer_base_get_usec)(void) =
52+
opal_timer_linux_get_usec_sys_timer;
4753
#endif /* OPAL_HAVE_CLOCK_GETTIME */
4854

49-
opal_timer_t opal_timer_linux_freq = {0};
55+
static opal_timer_t opal_timer_linux_freq = {0};
5056

5157
static int opal_timer_linux_open(void);
5258

@@ -164,8 +170,8 @@ int opal_timer_linux_open(void)
164170
struct timespec res;
165171
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
166172
opal_timer_linux_freq = 1.e3;
167-
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
168-
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
173+
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime;
174+
opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime;
169175
return ret;
170176
}
171177
#else
@@ -174,13 +180,13 @@ int opal_timer_linux_open(void)
174180
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */
175181
}
176182
ret = opal_timer_linux_find_freq();
177-
opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer;
178-
opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer;
183+
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer;
184+
opal_timer_base_get_usec = opal_timer_linux_get_usec_sys_timer;
179185
return ret;
180186
}
181187

182188
#if OPAL_HAVE_CLOCK_GETTIME
183-
opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
189+
opal_timer_t opal_timer_linux_get_usec_clock_gettime(void)
184190
{
185191
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
186192

@@ -189,7 +195,7 @@ opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
189195
return (tp.tv_sec * 1e6 + tp.tv_nsec/1000);
190196
}
191197

192-
opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
198+
opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void)
193199
{
194200
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
195201

@@ -199,7 +205,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
199205
}
200206
#endif /* OPAL_HAVE_CLOCK_GETTIME */
201207

202-
opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
208+
opal_timer_t opal_timer_linux_get_cycles_sys_timer(void)
203209
{
204210
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
205211
return opal_sys_timer_get_cycles();
@@ -209,7 +215,7 @@ opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
209215
}
210216

211217

212-
opal_timer_t opal_timer_base_get_usec_sys_timer(void)
218+
opal_timer_t opal_timer_linux_get_usec_sys_timer(void)
213219
{
214220
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
215221
/* freq is in MHz, so this gives usec */
@@ -223,5 +229,3 @@ opal_timer_t opal_timer_base_get_freq(void)
223229
{
224230
return opal_timer_linux_freq * 1000000;
225231
}
226-
227-

0 commit comments

Comments
 (0)