Merge pull request #3201 from hppritcha/jjhursey-topic/timer-gettimeofday
Jjhursey topic/timer gettimeofday
Этот коммит содержится в:
Коммит
ce0e1cd32c
@ -12,6 +12,9 @@
|
|||||||
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
|
||||||
* Copyright (c) 2015-2016 Research Organization for Information Science
|
* Copyright (c) 2015-2016 Research Organization for Information Science
|
||||||
* and Technology (RIST). All rights reserved.
|
* and Technology (RIST). All rights reserved.
|
||||||
|
* Copyright (c) 2017 IBM Corporation. All rights reserved.
|
||||||
|
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
|
||||||
|
* reserved.
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -24,6 +27,9 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef HAVE_TIME_H
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include MCA_timer_IMPLEMENTATION_HEADER
|
#include MCA_timer_IMPLEMENTATION_HEADER
|
||||||
#include "ompi/mpi/c/bindings.h"
|
#include "ompi/mpi/c/bindings.h"
|
||||||
@ -40,6 +46,11 @@ double MPI_Wtick(void)
|
|||||||
{
|
{
|
||||||
OPAL_CR_NOOP_PROGRESS();
|
OPAL_CR_NOOP_PROGRESS();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* See https://github.com/open-mpi/ompi/issues/3003
|
||||||
|
* to get an idea what's going on here.
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
#if OPAL_TIMER_CYCLE_NATIVE
|
#if OPAL_TIMER_CYCLE_NATIVE
|
||||||
{
|
{
|
||||||
opal_timer_t freq = opal_timer_base_get_freq();
|
opal_timer_t freq = opal_timer_base_get_freq();
|
||||||
@ -52,8 +63,21 @@ double MPI_Wtick(void)
|
|||||||
}
|
}
|
||||||
#elif OPAL_TIMER_USEC_NATIVE
|
#elif OPAL_TIMER_USEC_NATIVE
|
||||||
return 0.000001;
|
return 0.000001;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec spec;
|
||||||
|
double wtick = 0.0;
|
||||||
|
if (0 == clock_getres(CLOCK_MONOTONIC, &spec)){
|
||||||
|
wtick = spec.tv_sec + spec.tv_nsec * 1.0e-09;
|
||||||
|
} else {
|
||||||
|
/* guess */
|
||||||
|
wtick = 1.0e-09;
|
||||||
|
}
|
||||||
|
return wtick;
|
||||||
#else
|
#else
|
||||||
/* Otherwise, we already return usec precision. */
|
/* Otherwise, we already return usec precision. */
|
||||||
return 0.000001;
|
return 0.000001;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
* Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
|
||||||
* Copyright (c) 2015 Research Organization for Information Science
|
* Copyright (c) 2015 Research Organization for Information Science
|
||||||
* and Technology (RIST). All rights reserved.
|
* and Technology (RIST). All rights reserved.
|
||||||
|
* Copyright (c) 2017 IBM Corporation. All rights reserved.
|
||||||
|
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
|
||||||
|
* reserved.
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -24,6 +27,9 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef HAVE_TIME_H
|
||||||
|
#include <time.h>
|
||||||
|
#endif /* HAVE_TIME_H */
|
||||||
|
|
||||||
#include MCA_timer_IMPLEMENTATION_HEADER
|
#include MCA_timer_IMPLEMENTATION_HEADER
|
||||||
#include "ompi/mpi/c/bindings.h"
|
#include "ompi/mpi/c/bindings.h"
|
||||||
@ -40,16 +46,29 @@ double MPI_Wtime(void)
|
|||||||
{
|
{
|
||||||
double wtime;
|
double wtime;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* See https://github.com/open-mpi/ompi/issues/3003 to find out
|
||||||
|
* what's happening here.
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
#if OPAL_TIMER_CYCLE_NATIVE
|
#if OPAL_TIMER_CYCLE_NATIVE
|
||||||
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
|
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
|
||||||
#elif OPAL_TIMER_USEC_NATIVE
|
#elif OPAL_TIMER_USEC_NATIVE
|
||||||
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
|
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if defined(__linux__) && OPAL_HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
|
||||||
|
(void) clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||||
|
wtime = tp.tv_sec;
|
||||||
|
wtime += tp.tv_nsec/1.0e+9;
|
||||||
#else
|
#else
|
||||||
/* Fall back to gettimeofday() if we have nothing else */
|
/* Fall back to gettimeofday() if we have nothing else */
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
wtime = tv.tv_sec;
|
wtime = tv.tv_sec;
|
||||||
wtime += (double)tv.tv_usec / 1000000.0;
|
wtime += (double)tv.tv_usec / 1000000.0;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
OPAL_CR_NOOP_PROGRESS();
|
OPAL_CR_NOOP_PROGRESS();
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
* University of Stuttgart. All rights reserved.
|
* University of Stuttgart. All rights reserved.
|
||||||
* Copyright (c) 2004-2005 The Regents of the University of California.
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
* Copyright (c) 2017 Cisco Systems, Inc. All rights reserved
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -22,8 +23,6 @@
|
|||||||
#include "opal_config.h"
|
#include "opal_config.h"
|
||||||
#include <opal/sys/timer.h>
|
#include <opal/sys/timer.h>
|
||||||
|
|
||||||
OPAL_DECLSPEC extern opal_timer_t opal_timer_linux_freq;
|
|
||||||
|
|
||||||
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_cycles)(void);
|
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_cycles)(void);
|
||||||
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void);
|
OPAL_DECLSPEC extern opal_timer_t (*opal_timer_base_get_usec)(void);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* and Technology (RIST). All rights reserved.
|
* and Technology (RIST). All rights reserved.
|
||||||
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
|
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
|
* Copyright (c) 2015-2017 Cisco Systems, Inc. All rights reserved
|
||||||
* Copyright (c) 2016 Broadcom Limited. All rights reserved.
|
* Copyright (c) 2016 Broadcom Limited. All rights reserved.
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
@ -33,23 +33,28 @@
|
|||||||
#include "opal/constants.h"
|
#include "opal/constants.h"
|
||||||
#include "opal/util/show_help.h"
|
#include "opal/util/show_help.h"
|
||||||
|
|
||||||
static opal_timer_t opal_timer_base_get_cycles_sys_timer(void);
|
static opal_timer_t opal_timer_linux_get_cycles_sys_timer(void);
|
||||||
static opal_timer_t opal_timer_base_get_usec_sys_timer(void);
|
static opal_timer_t opal_timer_linux_get_usec_sys_timer(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define some sane defaults until we call the _init function.
|
* Define some sane defaults until we call the _init function.
|
||||||
*/
|
*/
|
||||||
#if OPAL_HAVE_CLOCK_GETTIME
|
#if OPAL_HAVE_CLOCK_GETTIME
|
||||||
static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void);
|
static opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void);
|
||||||
static opal_timer_t opal_timer_base_get_usec_clock_gettime(void);
|
static opal_timer_t opal_timer_linux_get_usec_clock_gettime(void);
|
||||||
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_clock_gettime;
|
|
||||||
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_clock_gettime;
|
opal_timer_t (*opal_timer_base_get_cycles)(void) =
|
||||||
|
opal_timer_linux_get_cycles_clock_gettime;
|
||||||
|
opal_timer_t (*opal_timer_base_get_usec)(void) =
|
||||||
|
opal_timer_linux_get_usec_clock_gettime;
|
||||||
#else
|
#else
|
||||||
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer;
|
opal_timer_t (*opal_timer_base_get_cycles)(void) =
|
||||||
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer;
|
opal_timer_linux_get_cycles_sys_timer;
|
||||||
|
opal_timer_t (*opal_timer_base_get_usec)(void) =
|
||||||
|
opal_timer_linux_get_usec_sys_timer;
|
||||||
#endif /* OPAL_HAVE_CLOCK_GETTIME */
|
#endif /* OPAL_HAVE_CLOCK_GETTIME */
|
||||||
|
|
||||||
opal_timer_t opal_timer_linux_freq = {0};
|
static opal_timer_t opal_timer_linux_freq = {0};
|
||||||
|
|
||||||
static int opal_timer_linux_open(void);
|
static int opal_timer_linux_open(void);
|
||||||
|
|
||||||
@ -171,8 +176,8 @@ int opal_timer_linux_open(void)
|
|||||||
struct timespec res;
|
struct timespec res;
|
||||||
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
|
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
|
||||||
opal_timer_linux_freq = 1.e3;
|
opal_timer_linux_freq = 1.e3;
|
||||||
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
|
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime;
|
||||||
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
|
opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -181,13 +186,13 @@ int opal_timer_linux_open(void)
|
|||||||
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */
|
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */
|
||||||
}
|
}
|
||||||
ret = opal_timer_linux_find_freq();
|
ret = opal_timer_linux_find_freq();
|
||||||
opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer;
|
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer;
|
||||||
opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer;
|
opal_timer_base_get_usec = opal_timer_linux_get_usec_sys_timer;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPAL_HAVE_CLOCK_GETTIME
|
#if OPAL_HAVE_CLOCK_GETTIME
|
||||||
opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
|
opal_timer_t opal_timer_linux_get_usec_clock_gettime(void)
|
||||||
{
|
{
|
||||||
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
|
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
|
||||||
|
|
||||||
@ -196,7 +201,7 @@ opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
|
|||||||
return (tp.tv_sec * 1e6 + tp.tv_nsec/1000);
|
return (tp.tv_sec * 1e6 + tp.tv_nsec/1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
|
opal_timer_t opal_timer_linux_get_cycles_clock_gettime(void)
|
||||||
{
|
{
|
||||||
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
|
struct timespec tp = {.tv_sec = 0, .tv_nsec = 0};
|
||||||
|
|
||||||
@ -206,7 +211,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
|
|||||||
}
|
}
|
||||||
#endif /* OPAL_HAVE_CLOCK_GETTIME */
|
#endif /* OPAL_HAVE_CLOCK_GETTIME */
|
||||||
|
|
||||||
opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
|
opal_timer_t opal_timer_linux_get_cycles_sys_timer(void)
|
||||||
{
|
{
|
||||||
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
|
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
|
||||||
return opal_sys_timer_get_cycles();
|
return opal_sys_timer_get_cycles();
|
||||||
@ -216,7 +221,7 @@ opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
opal_timer_t opal_timer_base_get_usec_sys_timer(void)
|
opal_timer_t opal_timer_linux_get_usec_sys_timer(void)
|
||||||
{
|
{
|
||||||
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
|
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
|
||||||
/* freq is in MHz, so this gives usec */
|
/* freq is in MHz, so this gives usec */
|
||||||
@ -230,5 +235,3 @@ opal_timer_t opal_timer_base_get_freq(void)
|
|||||||
{
|
{
|
||||||
return opal_timer_linux_freq * 1000000;
|
return opal_timer_linux_freq * 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user