From 8ac184633b64db60ba3712146af3b76a9b6d933e Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Sat, 5 Dec 2020 16:40:48 +0800 Subject: [PATCH] clock/time: add CLOCK_BOOTTIME definition Change-Id: I1adc0445dcdd8284d11aec44bd67b447b2b0490f Signed-off-by: chao.an --- include/time.h | 6 ++++++ sched/clock/clock_getres.c | 4 +++- sched/clock/clock_gettime.c | 2 +- sched/timer/timer_create.c | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/time.h b/include/time.h index e78ded7332..d8c08d1795 100644 --- a/include/time.h +++ b/include/time.h @@ -90,6 +90,12 @@ # define CLOCK_MONOTONIC 1 #endif +/* Monotonic system-wide clock that includes time spent in suspension. */ + +#ifdef CONFIG_CLOCK_MONOTONIC +# define CLOCK_BOOTTIME 2 +#endif + /* This is a flag that may be passed to the timer_settime() and * clock_nanosleep() functions. */ diff --git a/sched/clock/clock_getres.c b/sched/clock/clock_getres.c index 8e80a83d13..165851ce8e 100644 --- a/sched/clock/clock_getres.c +++ b/sched/clock/clock_getres.c @@ -74,6 +74,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res) #ifdef CONFIG_CLOCK_MONOTONIC case CLOCK_MONOTONIC: + case CLOCK_BOOTTIME: #endif case CLOCK_REALTIME: @@ -82,7 +83,8 @@ int clock_getres(clockid_t clock_id, struct timespec *res) res->tv_sec = 0; res->tv_nsec = NSEC_PER_TICK; - sinfo("Returning res=(%d,%d)\n", (int)res->tv_sec, (int)res->tv_nsec); + sinfo("Returning res=(%d,%d)\n", (int)res->tv_sec, + (int)res->tv_nsec); break; } diff --git a/sched/clock/clock_gettime.c b/sched/clock/clock_gettime.c index 6c3c35cef9..d35086207c 100644 --- a/sched/clock/clock_gettime.c +++ b/sched/clock/clock_gettime.c @@ -88,7 +88,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp) * is invoked with a clock_id argument of CLOCK_MONOTONIC." */ - if (clock_id == CLOCK_MONOTONIC) + if (clock_id == CLOCK_MONOTONIC || clock_id == CLOCK_BOOTTIME) { /* The the time elapsed since the timer was initialized at power on * reset. diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 9e4762294c..85449faa9a 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -161,6 +161,7 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, if (timerid == NULL || (clockid != CLOCK_REALTIME #ifdef CONFIG_CLOCK_MONOTONIC && clockid != CLOCK_MONOTONIC + && clockid != CLOCK_BOOTTIME #endif /* CONFIG_CLOCK_MONOTONIC */ )) {