2014-09-20 14:54:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Artem Polyakov <artpol84@gmail.com>
|
|
|
|
* Copyright (c) 2014 Intel, Inc. All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2014-09-20 14:54:24 +00:00
|
|
|
* Additional copyrights may follow
|
2015-06-23 20:59:57 -07:00
|
|
|
*
|
2014-09-20 14:54:24 +00:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2014-09-23 12:59:54 +00:00
|
|
|
#include "opal_config.h"
|
|
|
|
|
2014-09-15 18:00:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "opal/constants.h"
|
|
|
|
#include "opal/runtime/opal_params.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "opal/class/opal_pointer_array.h"
|
|
|
|
#include "opal/class/opal_list.h"
|
|
|
|
#include "opal/util/timings.h"
|
|
|
|
#include "opal/util/output.h"
|
2014-12-08 14:52:37 +06:00
|
|
|
#include "opal/util/basename.h"
|
|
|
|
#include "opal/mca/timer/timer.h"
|
2014-09-15 18:00:46 +00:00
|
|
|
|
2014-12-08 14:52:37 +06:00
|
|
|
#include MCA_timer_IMPLEMENTATION_HEADER
|
|
|
|
|
2017-03-29 02:47:06 +07:00
|
|
|
static opal_mutex_t tm_lock;
|
2014-12-08 14:52:37 +06:00
|
|
|
|
|
|
|
static double get_ts_gettimeofday(void)
|
|
|
|
{
|
|
|
|
double ret;
|
|
|
|
/* Use gettimeofday() if we opal wasn't initialized */
|
2014-09-15 18:00:46 +00:00
|
|
|
struct timeval tv;
|
2014-12-08 14:52:37 +06:00
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
ret = tv.tv_sec;
|
|
|
|
ret += (double)tv.tv_usec / 1000000.0;
|
2014-09-15 18:00:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-08 14:52:37 +06:00
|
|
|
#if OPAL_TIMER_CYCLE_NATIVE
|
|
|
|
static double get_ts_cycle(void)
|
|
|
|
{
|
|
|
|
return ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
|
|
|
|
}
|
2015-04-17 11:14:52 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if OPAL_TIMER_USEC_NATIVE
|
2014-12-08 14:52:37 +06:00
|
|
|
static double get_ts_usec(void)
|
|
|
|
{
|
|
|
|
return ((double) opal_timer_base_get_usec()) / 1000000.0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-29 02:47:06 +07:00
|
|
|
opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type)
|
2014-12-08 14:52:37 +06:00
|
|
|
{
|
2015-04-17 11:14:52 +03:00
|
|
|
switch (type) {
|
|
|
|
case OPAL_TIMING_GET_TIME_OF_DAY:
|
|
|
|
return get_ts_gettimeofday;
|
|
|
|
|
|
|
|
case OPAL_TIMING_CYCLE_NATIVE:
|
2014-12-08 14:52:37 +06:00
|
|
|
#if OPAL_TIMER_CYCLE_NATIVE
|
2015-04-17 11:14:52 +03:00
|
|
|
return get_ts_cycle;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif // OPAL_TIMER_CYCLE_NATIVE
|
|
|
|
case OPAL_TIMING_USEC_NATIVE:
|
|
|
|
#if OPAL_TIMER_USEC_NATIVE
|
|
|
|
return get_ts_usec;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif // OPAL_TIMER_USEC_NATIVE
|
|
|
|
default:
|
|
|
|
if( !opal_initialized ){
|
|
|
|
return get_ts_gettimeofday;
|
|
|
|
}
|
|
|
|
#if OPAL_TIMER_CYCLE_NATIVE
|
|
|
|
return get_ts_cycle;
|
2014-12-08 14:52:37 +06:00
|
|
|
#elif OPAL_TIMER_USEC_NATIVE
|
2015-04-17 11:14:52 +03:00
|
|
|
return get_ts_usec;
|
2014-12-08 14:52:37 +06:00
|
|
|
#endif
|
2015-04-17 11:14:52 +03:00
|
|
|
return get_ts_gettimeofday;
|
|
|
|
}
|
2014-12-08 14:52:37 +06:00
|
|
|
}
|
|
|
|
|