syslog: CONFIG_CLOCK_MONOTONIC

This commit is contained in:
Jussi Kivilinna 2017-08-04 08:02:52 -06:00 committed by Gregory Nutt
parent 0113b0db95
commit 9fc5f44ef6
2 changed files with 18 additions and 1 deletions

View File

@ -116,6 +116,15 @@ config SYSLOG_TIMESTAMP
---help---
Prepend timestamp to syslog message.
config SYSLOG_TIMESTAMP_REALTIME
bool "Use wall-clock for syslog timestamp"
default n
depends on SYSLOG_TIMESTAMP
---help---
Use wall-clock (CLOCK_REALTIME) for timestamp. By default,
CLOCK_MONOTONIC, if enabled, will be used or the system timer
is not.
config SYSLOG_SERIAL_CONSOLE
bool
default n

View File

@ -82,13 +82,21 @@ int _vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
ret = -EAGAIN;
if (OSINIT_HW_READY())
{
#if defined(CONFIG_SYSLOG_TIMESTAMP_REALTIME)
/* Use CLOCK_REALTIME if so configured */
ret = clock_gettime(CLOCK_REALTIME, &ts);
#elif defined(CONFIG_CLOCK_MONOTONIC)
/* 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
/* Otherwise, fall back to the system timer */
ret = clock_systimespec(&ts);
#endif
}