From cc7af2b0d024e9ca62a6280aea43e65a30c682fa Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Fri, 10 Nov 2017 07:51:17 -0600 Subject: [PATCH] procfs: Fix uptime being close to maximum 32-bit value in certain config --- fs/procfs/fs_procfsuptime.c | 2 +- include/nuttx/clock.h | 13 +++++++++++++ sched/clock/clock_initialize.c | 13 ------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fs/procfs/fs_procfsuptime.c b/fs/procfs/fs_procfsuptime.c index c39ade34074..4e836e7e5db 100644 --- a/fs/procfs/fs_procfsuptime.c +++ b/fs/procfs/fs_procfsuptime.c @@ -240,7 +240,7 @@ static ssize_t uptime_read(FAR struct file *filep, FAR char *buffer, { /* System time */ - ticktime = clock_systimer(); + ticktime = clock_systimer() - INITIAL_SYSTEM_TIMER_TICKS; #if defined(CONFIG_HAVE_DOUBLE) && defined(CONFIG_LIBC_FLOATINGPOINT) /* Convert the system up time to a seconds + hundredths of seconds string */ diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 2c679deb735..d05d49a50eb 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -178,6 +178,19 @@ #define TICK2HSEC(tick) (((tick)+(TICK_PER_HSEC/2))/TICK_PER_HSEC) /* Rounds */ #define TICK2SEC(tick) (((tick)+(TICK_PER_SEC/2))/TICK_PER_SEC) /* Rounds */ +#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_SYSTEM_TIME64) && \ + defined(CONFIG_CLOCK_MONOTONIC) +/* Initial system timer ticks value close to maximum 32-bit value, to test + * 64-bit system-timer after going over 32-bit value. This is to make errors + * of casting 64-bit system-timer to 32-bit variables more visible. + */ + +# define INITIAL_SYSTEM_TIMER_TICKS \ + ((uint64_t)(UINT32_MAX - (TICK_PER_SEC * 5))) +#else +# define INITIAL_SYSTEM_TIMER_TICKS 0 +#endif + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index 4d41071f475..6edf41d90de 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -68,19 +68,6 @@ #define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) #define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) -#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_SYSTEM_TIME64) && \ - defined(CONFIG_CLOCK_MONOTONIC) -/* Initial system timer ticks value close to maximum 32-bit value, to test - * 64-bit system-timer after going over 32-bit value. This is to make errors - * of casting 64-bit system-timer to 32-bit variables more visible. - */ - -# define INITIAL_SYSTEM_TIMER_TICKS \ - ((uint64_t)(UINT32_MAX - (TICK_PER_SEC * 5))) -#else -# define INITIAL_SYSTEM_TIMER_TICKS 0 -#endif - /**************************************************************************** * Public Data ****************************************************************************/