Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 62b0ba3

Browse files
author
rhc54
committed
Merge pull request #1181 from rhc54/cmr10/timer
Update the Linux timer per the master and George's patch on the devel mailing list.
2 parents d23dda8 + 9f2a6da commit 62b0ba3

File tree

9 files changed

+162
-49
lines changed

9 files changed

+162
-49
lines changed

configure.ac

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,10 @@ OPAL_SEARCH_LIBS_CORE([dirname], [gen])
841841
# Darwin doesn't need -lm, as it's a symlink to libSystem.dylib
842842
OPAL_SEARCH_LIBS_CORE([ceil], [m])
843843

844-
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty getpwuid fork waitpid execve pipe ptsname setsid mmap tcgetpgrp posix_memalign strsignal sysconf syslog vsyslog regcmp regexec regfree _NSGetEnviron socketpair strncpy_s usleep mkfifo dbopen dbm_open statfs statvfs setpgid setenv])
844+
# -lrt might be needed for clock_gettime
845+
OPAL_SEARCH_LIBS_CORE([clock_gettime], [rt])
846+
847+
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf openpty isatty getpwuid fork waitpid execve pipe ptsname setsid mmap tcgetpgrp posix_memalign strsignal sysconf syslog vsyslog regcmp regexec regfree _NSGetEnviron socketpair strncpy_s usleep mkfifo dbopen dbm_open statfs statvfs setpgid setenv])
845848

846849
# Sanity check: ensure that we got at least one of statfs or statvfs.
847850
if test $ac_cv_func_statfs = no -a $ac_cv_func_statvfs = no; then

opal/include/opal/sys/amd64/timer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
typedef uint64_t opal_timer_t;
2424

25+
/* Using RDTSC(P) results in non-monotonic timers across cores */
26+
#undef OPAL_TIMER_MONOTONIC
27+
#define OPAL_TIMER_MONOTONIC 0
2528

2629
#if OMPI_GCC_INLINE_ASSEMBLY
2730

opal/include/opal/sys/timer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
*
7171
*********************************************************************/
7272

73+
/* By default we suppose all timers are monotonic per node. */
74+
#define OPAL_TIMER_MONOTONIC 1
75+
7376
BEGIN_C_DECLS
7477

7578
/* If you update this list, you probably also want to update

opal/mca/timer/base/base.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ BEGIN_C_DECLS
3535
* Framework structure declaration
3636
*/
3737
OPAL_DECLSPEC extern mca_base_framework_t opal_timer_base_framework;
38-
38+
39+
/**
40+
* MCA param to force monotonic timers.
41+
*/
42+
OPAL_DECLSPEC extern int mca_timer_base_monotonic;
43+
3944
END_C_DECLS
4045

4146
/* include implementation to call */

opal/mca/timer/base/timer_base_open.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "opal/constants.h"
2323
#include "opal/mca/timer/base/base.h"
2424

25+
int mca_timer_base_monotonic = 1;
2526

2627
/*
2728
* The following file was created by configure. It contains extern
@@ -30,9 +31,23 @@
3031
*/
3132
#include "opal/mca/timer/base/static-components.h"
3233

34+
static int mca_timer_base_register(mca_base_register_flag_t flags)
35+
{
36+
/* figure out which bcol and sbgp components will actually be used */
37+
/* get list of sub-grouping functions to use */
38+
(void) mca_base_var_register("opal", "timer", "require", "monotonic",
39+
"Node-level monotonic timer required (default yes)",
40+
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
41+
OPAL_INFO_LVL_9,
42+
MCA_BASE_VAR_SCOPE_LOCAL,
43+
&mca_timer_base_monotonic);
44+
45+
return OPAL_SUCCESS;
46+
}
47+
3348
/*
3449
* Globals
3550
*/
3651
/* Use default register/open/close functions */
37-
MCA_BASE_FRAMEWORK_DECLARE(opal, timer, NULL, NULL, NULL, NULL,
52+
MCA_BASE_FRAMEWORK_DECLARE(opal, timer, "OPAL OS timer", mca_timer_base_register, NULL, NULL,
3853
mca_timer_base_static_components, 0);

opal/mca/timer/linux/Makefile.am

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
# University Research and Technology
44
# Corporation. All rights reserved.
5-
# Copyright (c) 2004-2005 The University of Tennessee and The University
5+
# Copyright (c) 2004-2014 The University of Tennessee and The University
66
# of Tennessee Research Foundation. All rights
77
# reserved.
8-
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
8+
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
99
# University of Stuttgart. All rights reserved.
1010
# Copyright (c) 2004-2005 The Regents of the University of California.
1111
# All rights reserved.
1212
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
1313
# $COPYRIGHT$
14-
#
14+
#
1515
# Additional copyrights may follow
16-
#
16+
#
1717
# $HEADER$
1818
#
1919

20+
dist_ompidata_DATA = help-opal-timer-linux.txt
21+
2022
noinst_LTLIBRARIES = libmca_timer_linux.la
2123

2224
libmca_timer_linux_la_SOURCES = \
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- text -*-
2+
#
3+
# Copyright (c) 2014 The University of Tennessee and The University
4+
# of Tennessee Research Foundation. All rights
5+
# reserved.
6+
# $COPYRIGHT$
7+
#
8+
# Additional copyrights may follow
9+
#
10+
# $HEADER$
11+
#
12+
# This is the US/English help file for Open MPI's Linux timer support.
13+
#
14+
[monotonic not supported]
15+
A monotonic timer has been requested by the user, but could not be found on the
16+
system. Falling back to a non-monotonic timer (such as RDTSC).
17+

opal/mca/timer/linux/timer_linux.h

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2014 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
8-
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
8+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* $COPYRIGHT$
13-
*
13+
*
1414
* Additional copyrights may follow
15-
*
15+
*
1616
* $HEADER$
1717
*/
1818

@@ -24,39 +24,14 @@
2424

2525
OPAL_DECLSPEC extern opal_timer_t opal_timer_linux_freq;
2626

27-
static inline opal_timer_t
28-
opal_timer_base_get_cycles(void)
29-
{
30-
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
31-
return opal_sys_timer_get_cycles();
32-
#else
33-
return 0;
34-
#endif
35-
}
36-
37-
38-
static inline opal_timer_t
39-
opal_timer_base_get_usec(void)
40-
{
41-
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
42-
/* freq is in Hz, so this gives usec */
43-
return opal_sys_timer_get_cycles() * 1000000 / opal_timer_linux_freq;
44-
#else
45-
return 0;
46-
#endif
47-
}
48-
49-
50-
static inline opal_timer_t
51-
opal_timer_base_get_freq(void)
52-
{
53-
return opal_timer_linux_freq;
54-
}
27+
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_cycles)(void);
28+
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void);
5529

30+
OPAL_DECLSPEC extern opal_timer_t opal_timer_base_get_freq(void);
5631

5732
#define OPAL_TIMER_CYCLE_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES
5833
#define OPAL_TIMER_CYCLE_SUPPORTED OPAL_HAVE_SYS_TIMER_GET_CYCLES
59-
#define OPAL_TIMER_USEC_NATIVE 0
34+
#define OPAL_TIMER_USEC_NATIVE OPAL_HAVE_SYS_TIMER_GET_CYCLES
6035
#define OPAL_TIMER_USEC_SUPPORTED OPAL_HAVE_SYS_TIMER_GET_CYCLES
6136

6237
#endif

opal/mca/timer/linux/timer_linux_component.c

Lines changed: 99 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
34
* University Research and Technology
45
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
6+
* Copyright (c) 2004-2014 The University of Tennessee and The University
67
* of Tennessee Research Foundation. All rights
78
* reserved.
8-
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9+
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
910
* University of Stuttgart. All rights reserved.
1011
* Copyright (c) 2004-2005 The Regents of the University of California.
1112
* All rights reserved.
@@ -15,23 +16,35 @@
1516
* reserved.
1617
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
1718
* $COPYRIGHT$
18-
*
19+
*
1920
* Additional copyrights may follow
20-
*
21+
*
2122
* $HEADER$
2223
*/
2324

2425
#include "opal_config.h"
2526

26-
#ifdef HAVE_STRING_H
2727
#include <string.h>
28-
#endif
2928

3029
#include "opal/mca/timer/timer.h"
30+
#include "opal/mca/timer/base/base.h"
3131
#include "opal/mca/timer/linux/timer_linux.h"
3232
#include "opal/constants.h"
3333

34-
opal_timer_t opal_timer_linux_freq;
34+
static opal_timer_t opal_timer_base_get_cycles_sys_timer(void);
35+
static opal_timer_t opal_timer_base_get_usec_sys_timer(void);
36+
37+
#if OPAL_HAVE_CLOCK_GETTIME
38+
static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void);
39+
static opal_timer_t opal_timer_base_get_usec_clock_gettime(void);
40+
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_clock_gettime;
41+
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_clock_gettime;
42+
#else
43+
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer;
44+
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer;
45+
#endif /* OPAL_HAVE_CLOCK_GETTIME */
46+
47+
opal_timer_t opal_timer_linux_freq = {0};
3548

3649
static int opal_timer_linux_open(void);
3750

@@ -68,6 +81,9 @@ find_info(FILE* fp, char *str, char *buf, size_t buflen)
6881
/* we found the line. Now eat everything up to,
6982
including, and one past the : */
7083
for (tmp = buf ; (*tmp != '\0') && (*tmp != ':') ; ++tmp) ;
84+
if (*tmp == '\0') {
85+
continue;
86+
}
7187
for ( ++tmp ; *tmp == ' ' ; ++tmp);
7288
if ('\0' != *tmp) {
7389
return tmp;
@@ -78,8 +94,7 @@ find_info(FILE* fp, char *str, char *buf, size_t buflen)
7894
return NULL;
7995
}
8096

81-
int
82-
opal_timer_linux_open(void)
97+
static int opal_timer_linux_find_freq(void)
8398
{
8499
FILE *fp;
85100
char *loc;
@@ -135,3 +150,78 @@ opal_timer_linux_open(void)
135150

136151
return OPAL_SUCCESS;
137152
}
153+
154+
int opal_timer_linux_open(void)
155+
{
156+
int ret = OPAL_SUCCESS;
157+
158+
if(mca_timer_base_monotonic) {
159+
#if OPAL_HAVE_CLOCK_GETTIME
160+
struct timespec res;
161+
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
162+
opal_timer_linux_freq = 1.e9;
163+
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
164+
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
165+
return ret;
166+
}
167+
#else
168+
#if (0 == OPAL_TIMER_MONOTONIC)
169+
/* Monotonic time requested but cannot be found. Complain! */
170+
opal_show_help("help-opal-timer-linux.txt", "monotonic not supported", 1);
171+
#endif /* (0 == OPAL_TIMER_MONOTONIC) */
172+
#endif
173+
}
174+
ret = opal_timer_linux_find_freq();
175+
opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer;
176+
opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer;
177+
return ret;
178+
}
179+
180+
#if OPAL_HAVE_CLOCK_GETTIME
181+
opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
182+
{
183+
struct timespec tp;
184+
185+
if( 0 == clock_gettime(CLOCK_MONOTONIC, &tp) ) {
186+
return (tp.tv_sec * 1e6 + tp.tv_nsec/1000);
187+
}
188+
return 0;
189+
}
190+
191+
opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
192+
{
193+
struct timespec tp;
194+
195+
if( 0 == clock_gettime(CLOCK_MONOTONIC, &tp) ) {
196+
return (tp.tv_sec * 1e9 + tp.tv_nsec);
197+
}
198+
return 0;
199+
}
200+
#endif /* OPAL_HAVE_CLOCK_GETTIME */
201+
202+
opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
203+
{
204+
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
205+
return opal_sys_timer_get_cycles();
206+
#else
207+
return 0;
208+
#endif
209+
}
210+
211+
212+
opal_timer_t opal_timer_base_get_usec_sys_timer(void)
213+
{
214+
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
215+
/* freq is in Hz, so this gives usec */
216+
return opal_sys_timer_get_cycles() * 1000000 / opal_timer_linux_freq;
217+
#else
218+
return 0;
219+
#endif
220+
}
221+
222+
opal_timer_t opal_timer_base_get_freq(void)
223+
{
224+
return opal_timer_linux_freq;
225+
}
226+
227+

0 commit comments

Comments
 (0)