Skip to content

Commit ce0e1cd

Browse files
authored
Merge pull request #3201 from hppritcha/jjhursey-topic/timer-gettimeofday
Jjhursey topic/timer gettimeofday
2 parents 19b2454 + b933152 commit ce0e1cd

File tree

4 files changed

+67
-22
lines changed

4 files changed

+67
-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"
@@ -40,6 +46,11 @@ double MPI_Wtick(void)
4046
{
4147
OPAL_CR_NOOP_PROGRESS();
4248

49+
/*
50+
* See https://github.com/open-mpi/ompi/issues/3003
51+
* to get an idea what's going on here.
52+
*/
53+
#if 0
4354
#if OPAL_TIMER_CYCLE_NATIVE
4455
{
4556
opal_timer_t freq = opal_timer_base_get_freq();
@@ -52,8 +63,21 @@ double MPI_Wtick(void)
5263
}
5364
#elif OPAL_TIMER_USEC_NATIVE
5465
return 0.000001;
66+
#endif
67+
#else
68+
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
69+
struct timespec spec;
70+
double wtick = 0.0;
71+
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
72+
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
73+
} else {
74+
/* guess */
75+
wtick = 1.0e-09;
76+
}
77+
return wtick;
5578
#else
5679
/* Otherwise, we already return usec precision. */
5780
return 0.000001;
5881
#endif
82+
#endif
5983
}

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
OPAL_CR_NOOP_PROGRESS();

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: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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) 2016 Broadcom Limited. All rights reserved.
1919
* $COPYRIGHT$
2020
*
@@ -33,23 +33,28 @@
3333
#include "opal/constants.h"
3434
#include "opal/util/show_help.h"
3535

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);
36+
static opal_timer_t opal_timer_linux_get_cycles_sys_timer(void);
37+
static opal_timer_t opal_timer_linux_get_usec_sys_timer(void);
3838

3939
/**
4040
* Define some sane defaults until we call the _init function.
4141
*/
4242
#if OPAL_HAVE_CLOCK_GETTIME
43-
static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void);
44-
static opal_timer_t opal_timer_base_get_usec_clock_gettime(void);
45-
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_clock_gettime;
46-
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_clock_gettime;
43+
static opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void);
44+
static opal_timer_t opal_timer_linux_get_usec_clock_gettime(void);
45+
46+
opal_timer_t (*opal_timer_base_get_cycles)(void) =
47+
opal_timer_linux_get_cycles_clock_gettime;
48+
opal_timer_t (*opal_timer_base_get_usec)(void) =
49+
opal_timer_linux_get_usec_clock_gettime;
4750
#else
48-
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer;
49-
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer;
51+
opal_timer_t (*opal_timer_base_get_cycles)(void) =
52+
opal_timer_linux_get_cycles_sys_timer;
53+
opal_timer_t (*opal_timer_base_get_usec)(void) =
54+
opal_timer_linux_get_usec_sys_timer;
5055
#endif /* OPAL_HAVE_CLOCK_GETTIME */
5156

52-
opal_timer_t opal_timer_linux_freq = {0};
57+
static opal_timer_t opal_timer_linux_freq = {0};
5358

5459
static int opal_timer_linux_open(void);
5560

@@ -171,8 +176,8 @@ int opal_timer_linux_open(void)
171176
struct timespec res;
172177
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
173178
opal_timer_linux_freq = 1.e3;
174-
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
175-
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
179+
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime;
180+
opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime;
176181
return ret;
177182
}
178183
#else
@@ -181,13 +186,13 @@ int opal_timer_linux_open(void)
181186
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */
182187
}
183188
ret = opal_timer_linux_find_freq();
184-
opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer;
185-
opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer;
189+
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer;
190+
opal_timer_base_get_usec = opal_timer_linux_get_usec_sys_timer;
186191
return ret;
187192
}
188193

189194
#if OPAL_HAVE_CLOCK_GETTIME
190-
opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
195+
opal_timer_t opal_timer_linux_get_usec_clock_gettime(void)
191196
{
192197
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
193198

@@ -196,7 +201,7 @@ opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
196201
return (tp.tv_sec * 1e6 + tp.tv_nsec/1000);
197202
}
198203

199-
opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
204+
opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void)
200205
{
201206
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
202207

@@ -206,7 +211,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
206211
}
207212
#endif /* OPAL_HAVE_CLOCK_GETTIME */
208213

209-
opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
214+
opal_timer_t opal_timer_linux_get_cycles_sys_timer(void)
210215
{
211216
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
212217
return opal_sys_timer_get_cycles();
@@ -216,7 +221,7 @@ opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
216221
}
217222

218223

219-
opal_timer_t opal_timer_base_get_usec_sys_timer(void)
224+
opal_timer_t opal_timer_linux_get_usec_sys_timer(void)
220225
{
221226
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
222227
/* freq is in MHz, so this gives usec */
@@ -230,5 +235,3 @@ opal_timer_t opal_timer_base_get_freq(void)
230235
{
231236
return opal_timer_linux_freq * 1000000;
232237
}
233-
234-

0 commit comments

Comments
 (0)