From 9fc5f44ef6f5152546df1e22c56e9a9cfd0ceebf Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna <jussi.kivilinna@haltian.com> Date: Fri, 4 Aug 2017 08:02:52 -0600 Subject: [PATCH] syslog: CONFIG_CLOCK_MONOTONIC --- drivers/syslog/Kconfig | 9 +++++++++ drivers/syslog/vsyslog.c | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 60c136e5a7..5eddcf337c 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -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 diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index 76ba239968..58123331b0 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -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 }