From e8358031666c5d6036c702da0dcf3c82ad94d946 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Wed, 26 Apr 2017 10:38:15 -0600 Subject: [PATCH] yslog: use monotonic clock for timestamp when available --- drivers/syslog/vsyslog.c | 20 +++++++++++++++++--- sched/clock/clock_initialize.c | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index 27fab399ec..ba0d3726f8 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/syslog/vsyslog.c * - * Copyright (C) 2007-2009, 2011-2014, 2016 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011-2014, 2016-2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -70,15 +70,29 @@ int _vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) struct lib_outstream_s stream; #ifdef CONFIG_SYSLOG_TIMESTAMP struct timespec ts; + int ret = -1; /* Get the current time. Since debug output may be generated very early * in the start-up sequence, hardware timer support may not yet be * available. */ - if (!OSINIT_HW_READY() || clock_systimespec(&ts) < 0) + if (OSINIT_HW_READY()) { - /* Timer hardware is not available, or clock_systimespec failed */ + /* Prefer monotonic when enabled, as it can be synchronized to + * RTC with clock_resynchronize. + */ + +#ifdef CONFIG_CLOCK_MONOTONIC + ret = clock_gettime(CLOCK_MONOTONIC, &ts); +#else + ret = clock_systimespec(&ts); +#endif + } + + if (ret < 0) + { + /* Timer hardware is not available, or clock function failed */ ts.tv_sec = 0; ts.tv_nsec = 0; diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c index d8a7b13497..ca565c9c8a 100644 --- a/sched/clock/clock_initialize.c +++ b/sched/clock/clock_initialize.c @@ -68,7 +68,8 @@ #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) +#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.