Skip to content

mpi/c: Force wtick/wtime to use gettimeofday #3184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ompi/mpi/c/wtick.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Copyright (c) 2007-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -40,6 +41,12 @@ double MPI_Wtick(void)
{
OPAL_CR_NOOP_PROGRESS();

/*
* See https://github.com/open-mpi/ompi/issues/3003
* For now we are forcing the use of gettimeofday() until we find a
* more portable solution.
*/
#if 0
#if OPAL_TIMER_CYCLE_NATIVE
{
opal_timer_t freq = opal_timer_base_get_freq();
Expand All @@ -52,6 +59,7 @@ double MPI_Wtick(void)
}
#elif OPAL_TIMER_USEC_NATIVE
return 0.000001;
#endif
#else
/* Otherwise, we already return usec precision. */
return 0.000001;
Expand Down
8 changes: 8 additions & 0 deletions ompi/mpi/c/wtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Copyright (c) 2006-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -40,10 +41,17 @@ double MPI_Wtime(void)
{
double wtime;

/*
* See https://github.com/open-mpi/ompi/issues/3003
* For now we are forcing the use of gettimeofday() until we find a
* more portable solution.
*/
#if 0
#if OPAL_TIMER_CYCLE_NATIVE
wtime = ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
#elif OPAL_TIMER_USEC_NATIVE
wtime = ((double) opal_timer_base_get_usec()) / 1000000.0;
#endif
#else
/* Fall back to gettimeofday() if we have nothing else */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hjelmn + me suggest putting something like:

#if _LINUX_ && OPAL_HAVE_CLOCK_GETTIME
// ... use clock_gettime(..) ...
#else
// ... use gettimeofday(..) ...
#endif

That way, we don't need a new configure test -- we only use clock_gettime if a) we're on Linux, and b) our existing configure test says that we have clock_gettime (i.e., we sidestep the whole OS X problem).

struct timeval tv;
Expand Down
3 changes: 1 addition & 2 deletions opal/mca/timer/linux/timer_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2017 Cisco Systems, Inc. All rights reserved
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand All @@ -22,8 +23,6 @@
#include "opal_config.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_usec)(void);

Expand Down
43 changes: 23 additions & 20 deletions opal/mca/timer/linux/timer_linux_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* and Technology (RIST). All rights reserved.
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
* 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$
*
Expand All @@ -33,23 +33,28 @@
#include "opal/constants.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_base_get_usec_sys_timer(void);
static opal_timer_t opal_timer_linux_get_cycles_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.
*/
#if OPAL_HAVE_CLOCK_GETTIME
static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void);
static opal_timer_t opal_timer_base_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;
static opal_timer_t opal_timer_linux_get_cycles_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_linux_get_cycles_clock_gettime;
opal_timer_t (*opal_timer_base_get_usec)(void) =
opal_timer_linux_get_usec_clock_gettime;
#else
opal_timer_t (*opal_timer_base_get_cycles)(void) = opal_timer_base_get_cycles_sys_timer;
opal_timer_t (*opal_timer_base_get_usec)(void) = opal_timer_base_get_usec_sys_timer;
opal_timer_t (*opal_timer_base_get_cycles)(void) =
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 */

opal_timer_t opal_timer_linux_freq = {0};
static opal_timer_t opal_timer_linux_freq = {0};

static int opal_timer_linux_open(void);

Expand Down Expand Up @@ -171,8 +176,8 @@ int opal_timer_linux_open(void)
struct timespec res;
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
opal_timer_linux_freq = 1.e3;
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_clock_gettime;
opal_timer_base_get_usec = opal_timer_linux_get_usec_clock_gettime;
return ret;
}
#else
Expand All @@ -181,13 +186,13 @@ int opal_timer_linux_open(void)
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC) */
}
ret = opal_timer_linux_find_freq();
opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer;
opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer;
opal_timer_base_get_cycles = opal_timer_linux_get_cycles_sys_timer;
opal_timer_base_get_usec = opal_timer_linux_get_usec_sys_timer;
return ret;
}

#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};

Expand All @@ -196,7 +201,7 @@ opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
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};

Expand All @@ -206,7 +211,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
}
#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
return opal_sys_timer_get_cycles();
Expand All @@ -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
/* freq is in MHz, so this gives usec */
Expand All @@ -230,5 +235,3 @@ opal_timer_t opal_timer_base_get_freq(void)
{
return opal_timer_linux_freq * 1000000;
}