yslog: use monotonic clock for timestamp when available

This commit is contained in:
Jussi Kivilinna 2017-04-26 10:38:15 -06:00 committed by Gregory Nutt
parent 2f9028b547
commit e835803166
2 changed files with 19 additions and 4 deletions

View File

@ -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 <gnutt@nuttx.org>
*
* 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;

View File

@ -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.