Skip to content

Commit 88c2708

Browse files
author
Ralph Castain
authored
Merge pull request #2721 from hjelmn/v1.10_timer_overflow
timer/linux: prevent 64-bit overflow
2 parents f3e7fce + 91ae257 commit 88c2708

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

opal/mca/timer/linux/timer_linux_component.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15-
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
15+
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2015-2017 Cisco Systems, Inc. All rights reserved.
1818
* $COPYRIGHT$
@@ -149,6 +149,10 @@ static int opal_timer_linux_find_freq(void)
149149

150150
fclose(fp);
151151

152+
/* convert the timer frequency to MHz to avoid an extra operation when
153+
* converting from cycles to usec */
154+
opal_timer_linux_freq /= 1000000;
155+
152156
return OPAL_SUCCESS;
153157
}
154158

@@ -160,7 +164,7 @@ int opal_timer_linux_open(void)
160164
#if OPAL_HAVE_CLOCK_GETTIME && (0 == OPAL_TIMER_MONOTONIC)
161165
struct timespec res;
162166
if( 0 == clock_getres(CLOCK_MONOTONIC, &res)) {
163-
opal_timer_linux_freq = 1.e9;
167+
opal_timer_linux_freq = 1.e3;
164168
opal_timer_base_get_cycles = opal_timer_base_get_cycles_clock_gettime;
165169
opal_timer_base_get_usec = opal_timer_base_get_usec_clock_gettime;
166170
return ret;
@@ -209,16 +213,16 @@ opal_timer_t opal_timer_base_get_cycles_sys_timer(void)
209213
opal_timer_t opal_timer_base_get_usec_sys_timer(void)
210214
{
211215
#if OPAL_HAVE_SYS_TIMER_GET_CYCLES
212-
/* freq is in Hz, so this gives usec */
213-
return opal_sys_timer_get_cycles() * 1000000 / opal_timer_linux_freq;
216+
/* freq is in MHz, so this gives usec */
217+
return opal_sys_timer_get_cycles() / opal_timer_linux_freq;
214218
#else
215219
return 0;
216220
#endif
217221
}
218222

219223
opal_timer_t opal_timer_base_get_freq(void)
220224
{
221-
return opal_timer_linux_freq;
225+
return opal_timer_linux_freq * 1000000;
222226
}
223227

224228

0 commit comments

Comments
 (0)