Skip to content

Commit

Permalink
Support non-monotonic assembly timers.
Browse files Browse the repository at this point in the history
If monotonic support has been required by the runtime and the
assembly timers are unable to provide it, fall back to clock_gettime.
  • Loading branch information
bosilca committed Sep 24, 2016
1 parent 45dcf1f commit 0663702
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions opal/mca/timer/linux/timer_linux_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* Copyright (c) 2004-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
Expand Down Expand Up @@ -31,19 +31,23 @@
#include "opal/mca/timer/base/base.h"
#include "opal/mca/timer/linux/timer_linux.h"
#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);

#if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES)
/**
* 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;
#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;
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES) */
#endif /* OPAL_HAVE_CLOCK_GETTIME */

opal_timer_t opal_timer_linux_freq = {0};

Expand Down Expand Up @@ -159,7 +163,7 @@ int opal_timer_linux_open(void)
int ret = OPAL_SUCCESS;

if(mca_timer_base_monotonic) {
#if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES)
#if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC)
struct timespec res;
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
opal_timer_linux_freq = 1.e9;
Expand All @@ -170,17 +174,17 @@ int opal_timer_linux_open(void)
#else
#if (0 == OPAL_TIMER_MONOTONIC)
/* Monotonic time requested but cannot be found. Complain! */
opal_show_help("help-opal-timer-linux.txt", "monotonic not supported", 1);
opal_show_help("help-opal-timer-linux.txt", "monotonic not supported", true);
#endif /* (0 == OPAL_TIMER_MONOTONIC) */
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES) */
#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;
return ret;
}

#if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES)
#if OPAL_HAVE_CLOCK_GETTIME
opal_timer_t opal_timer_base_get_usec_clock_gettime(void)
{
struct timespec tp;
Expand All @@ -200,7 +204,7 @@ opal_timer_t opal_timer_base_get_cycles_clock_gettime(void)
}
return 0;
}
#endif /* OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_HAVE_SYS_TIMER_GET_CYCLES) */
#endif /* OPAL_HAVE_CLOCK_GETTIME */

opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
{
Expand Down

0 comments on commit 0663702

Please sign in to comment.