|
26 | 26 | #include "opal/mca/timer/linux/timer_linux.h" |
27 | 27 | #include "opal/constants.h" |
28 | 28 |
|
| 29 | +static opal_timer_t opal_timer_base_get_cycles_sys_timer(void); |
| 30 | +static opal_timer_t opal_timer_base_get_usec_sys_timer(void); |
| 31 | + |
| 32 | +#if OPAL_HAVE_CLOCK_GETTIME |
| 33 | +static opal_timer_t opal_timer_base_get_cycles_clock_gettime(void); |
| 34 | +static opal_timer_t opal_timer_base_get_usec_clock_gettime(void); |
| 35 | +opal_timer_t *opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime; |
| 36 | +opal_timer_t *opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime; |
| 37 | +#else |
| 38 | +opal_timer_t *opal_timer_base_get_cycles = opal_timer_base_get_cycles_sys_timer; |
| 39 | +opal_timer_t *opal_timer_base_get_usec = opal_timer_base_get_usec_sys_timer; |
| 40 | +#endif /* OPAL_HAVE_CLOCK_GETTIME */ |
| 41 | + |
29 | 42 | opal_timer_t opal_timer_linux_freq; |
30 | 43 |
|
31 | 44 | static int opal_timer_linux_open(void); |
@@ -73,8 +86,7 @@ find_info(FILE* fp, char *str, char *buf, size_t buflen) |
73 | 86 | return NULL; |
74 | 87 | } |
75 | 88 |
|
76 | | -int |
77 | | -opal_timer_linux_open(void) |
| 89 | +static int opal_timer_linux_find_freq(void) |
78 | 90 | { |
79 | 91 | FILE *fp; |
80 | 92 | char *loc; |
@@ -130,3 +142,71 @@ opal_timer_linux_open(void) |
130 | 142 |
|
131 | 143 | return OPAL_SUCCESS; |
132 | 144 | } |
| 145 | + |
| 146 | +int opal_timer_linux_open(void) |
| 147 | +{ |
| 148 | + int ret = OPAL_SUCCESS; |
| 149 | +#if !OPAL_HAVE_CLOCK_GETTIME |
| 150 | + ret = opal_timer_linux_find_freq(); |
| 151 | +#endif |
| 152 | + |
| 153 | + if(mca_timer_base_monotonic) { |
| 154 | +#if OPAL_HAVE_CLOCK_GETTIME |
| 155 | + struct timespec *res; |
| 156 | + if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) { |
| 157 | + opal_timer_linux_freq = res.tv_nsec; |
| 158 | + return ret; |
| 159 | + } |
| 160 | +#else |
| 161 | +#if (0 == OPAL_TIMER_MONOTONIC) |
| 162 | + /* Monotonic time requested but cannot be found. Complain! */ |
| 163 | + opal_show_help("help-opal-timer-linux.txt", "monotonic not supported", 1); |
| 164 | +#endif /* (0 == OPAL_TIMER_MONOTONIC) */ |
| 165 | +#endif |
| 166 | + } |
| 167 | + return ret; |
| 168 | +} |
| 169 | + |
| 170 | +#if OPAL_HAVE_CLOCK_GETTIME |
| 171 | +opal_timer_t opal_timer_base_get_usec_clock_gettime(void) |
| 172 | +{ |
| 173 | + struct timespec *tp; |
| 174 | + |
| 175 | + if( 0 == clock_gettime(CLOCK_MONOTONIC, &tp) ) { |
| 176 | + return (tp.tv_sec * 1e9 + tp.tv_nsec); |
| 177 | + } |
| 178 | + return 0; |
| 179 | +} |
| 180 | + |
| 181 | +opal_timer_t opal_timer_base_get_cycles_clock_gettime(void) |
| 182 | +{ |
| 183 | + return opal_timer_base_get_usec_clock_gettime() * opal_timer_linux_freq; |
| 184 | +} |
| 185 | +#endif /* OPAL_HAVE_CLOCK_GETTIME */ |
| 186 | + |
| 187 | +opal_timer_t opal_timer_base_get_cycles_sys_timer(void) |
| 188 | +{ |
| 189 | +#if OPAL_HAVE_SYS_TIMER_GET_CYCLES |
| 190 | + return opal_sys_timer_get_cycles(); |
| 191 | +#else |
| 192 | + return 0; |
| 193 | +#endif |
| 194 | +} |
| 195 | + |
| 196 | + |
| 197 | +opal_timer_t opal_timer_base_get_usec_sys_timer(void) |
| 198 | +{ |
| 199 | +#if OPAL_HAVE_SYS_TIMER_GET_CYCLES |
| 200 | + /* freq is in Hz, so this gives usec */ |
| 201 | + return opal_sys_timer_get_cycles() * 1000000 / opal_timer_linux_freq; |
| 202 | +#else |
| 203 | + return 0; |
| 204 | +#endif |
| 205 | +} |
| 206 | + |
| 207 | +opal_timer_t opal_timer_base_get_freq(void) |
| 208 | +{ |
| 209 | + return opal_timer_linux_freq; |
| 210 | +} |
| 211 | + |
| 212 | + |
0 commit comments