From d9f960e97bcf2ee65ba3db8e723e7064ec76beeb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 13 Feb 2015 06:13:47 -0600 Subject: [PATCH] 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. --- sched/clock/clock_systimer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sched/clock/clock_systimer.c b/sched/clock/clock_systimer.c index c316b8c08e..a87f36a0af 100644 --- a/sched/clock/clock_systimer.c +++ b/sched/clock/clock_systimer.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * 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); - /* Convert to a 64-bit value */ - - return MSEC2TICK(1000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000000); + /* Convert to a 64-bit value in microseconds, then in clock tick units */ + return USEC2TICK(1000000 * (uint64_t)ts.tv_sec + (uint64_t)ts.tv_nsec / 1000); #else /* Return the current system time */