Fix a problem in clock_systimer64 that occurs when (1) the 64-bit system time is enabled, and (2) the value of CONFIG_USEC_PER_TICK is less than 1 millisconds (such as when using the tickless mode of operation). In that case, the convertion of time to 64-bit millisecond value in clock_systmer64() causes some bad times to be returned. Time was converted to milliseconds, then to configured ticks. Precision was lost in the millisecond convertion.

The fix is to first convert time to a 64-bit microsecond value, then to the configured tick value.

Noted by David Sidrane.
This commit is contained in:
Gregory Nutt 2015-02-13 06:13:47 -06:00
parent e7470e0834
commit d9f960e97b
1 changed files with 3 additions and 4 deletions

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/clock/clock_systimer.c * sched/clock/clock_systimer.c
* *
* Copyright (C) 2011, 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2011, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -135,10 +135,9 @@ uint64_t clock_systimer64(void)
(void)up_timer_gettime(&ts); (void)up_timer_gettime(&ts);
/* Convert to a 64-bit value */ /* Convert to a 64-bit value in microseconds, then in clock tick units */
return MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000);
return USEC2TICK(1000000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000);
#else #else
/* Return the current system time */ /* Return the current system time */