From 4f59bc58782a11814bb0439b6bb48601c5ad3c3b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 31 Mar 2014 10:01:03 -0600 Subject: [PATCH] Add CONFIG_CLOCK_MONTONIC --- ChangeLog | 3 +++ include/time.h | 4 +++- sched/Kconfig | 14 ++++++++++++++ sched/clock_gettime.c | 7 +++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50e4f7be56..744214a97d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7095,3 +7095,6 @@ * libc/stdio/lib_ftell.c: Fix a logic error in ftell(). It was simply using the file offset and did not take into account data buffered in memory. From Macs N (2013-3-31). + * Add CONFIG_CLOCK_MONOTONIC that case used to disable CLOCK_MONOTONIC + for a smaller footprint (2013-3-31). + diff --git a/include/time.h b/include/time.h index a3b5731e2e..e8853ef898 100644 --- a/include/time.h +++ b/include/time.h @@ -99,7 +99,9 @@ * system time-of-day clock. */ -#define CLOCK_MONOTONIC 2 +#ifdef CLOCK_MONOTONIC +# define CLOCK_MONOTONIC 2 +#endif /* This is a flag that may be passed to the timer_settime() function */ diff --git a/sched/Kconfig b/sched/Kconfig index cd6b200e78..eb98f2f155 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -53,6 +53,20 @@ config SYSTEM_TIME64 and/or if a very long "uptime" is required, then this option can be selected to support a 64-bit wide timer. +config CLOCK_MONOTONIC + bool "Support CLOCK_MONOTONIC" + default n + ---help--- + CLOCK_MONOTONIC is an optional standard POSIX clock. Unlike + CLOCK_REALTIME which can move forward and backward when the + time-of-day changes, CLOCK_MONOTONIC is the elapsed time since some + arbitrary point in the post (the system start-up time for NuttX) + and, hence, is always monotonically increasing. CLOCK_MONOTONIC + is, hence, the more appropriate clock for determining time + differences. + + The value of the CLOCK_MONOTONIC clock cannot be set via clock_settime(). + config RR_INTERVAL int "Round robin timeslice (MSEC)" default 0 diff --git a/sched/clock_gettime.c b/sched/clock_gettime.c index 6aa8b44d16..e4b9385398 100644 --- a/sched/clock_gettime.c +++ b/sched/clock_gettime.c @@ -107,6 +107,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) sdbg("clock_id=%d\n", clock_id); DEBUGASSERT(tp != NULL); +#ifdef CLOCK_MONOTONIC /* CLOCK_MONOTONIC is an optional under POSIX: "If the Monotonic Clock * option is supported, all implementations shall support a clock_id * of CLOCK_MONOTONIC defined in . This clock represents the @@ -139,6 +140,8 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) tp->tv_sec = (time_t)secs; tp->tv_nsec = (long)nsecs; } + else +#endif /* CLOCK_REALTIME - POSIX demands this to be present. CLOCK_REALTIME * represents the machine's best-guess as to the current wall-clock, @@ -152,9 +155,9 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) */ #ifdef CONFIG_RTC - else if (clock_id == CLOCK_REALTIME || clock_id == CLOCK_ACTIVETIME) + if (clock_id == CLOCK_REALTIME || clock_id == CLOCK_ACTIVETIME) #else - else if (clock_id == CLOCK_REALTIME) + if (clock_id == CLOCK_REALTIME) #endif { /* Do we have a high-resolution RTC that can provide us with the time? */