File: timings.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (113 lines) | stat: -rw-r--r-- 2,547 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (C) 2014      Artem Polyakov <artpol84@gmail.com>
 * Copyright (c) 2014      Intel, Inc. All rights reserved.
 * Copyright (c) 2017      Mellanox Technologies Ltd. All rights reserved.
 * Copyright (c) 2023      Triad National Security, LLC. All rights
 *                         reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.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_list.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/mca/timer/timer.h"
#include "opal/util/basename.h"
#include "opal/util/output.h"
#include "opal/util/timings.h"

#include MCA_timer_IMPLEMENTATION_HEADER

static bool opal_timer_native_timers_avail = false;

static double get_ts_gettimeofday(void)
{
    double ret;
    /* Use gettimeofday() if we opal wasn't initialized */
    struct timeval tv;
    gettimeofday(&tv, NULL);
    ret = tv.tv_sec;
    ret += (double) tv.tv_usec / 1000000.0;
    return ret;
}

#if OPAL_TIMER_CYCLE_NATIVE
static double get_ts_cycle(void)
{
    return ((double) opal_timer_base_get_cycles()) / opal_timer_base_get_freq();
}
#endif

#if OPAL_TIMER_USEC_NATIVE
static double get_ts_usec(void)
{
    return ((double) opal_timer_base_get_usec()) / 1000000.0;
}
#endif

void opal_timing_enable_native_timers(void)
{
    opal_timer_native_timers_avail = true;
}

void opal_timing_disable_native_timers(void)
{
    opal_timer_native_timers_avail = false;
}


opal_timing_ts_func_t opal_timing_ts_func(opal_timer_type_t type)
{
    switch (type) {
    case OPAL_TIMING_GET_TIME_OF_DAY:
        return get_ts_gettimeofday;

    case OPAL_TIMING_CYCLE_NATIVE:
#if OPAL_TIMER_CYCLE_NATIVE
        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( false == opal_timer_native_timers_avail ){
            return get_ts_gettimeofday;
        }
#if OPAL_TIMER_CYCLE_NATIVE
        return get_ts_cycle;
#elif OPAL_TIMER_USEC_NATIVE
        return get_ts_usec;
#endif
        return get_ts_gettimeofday;
    }
}