diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index fc8f6c78899a..e2be60391b63 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -207,9 +207,13 @@ kern_clock_gettime(struct thread *td, clockid_t clock_id, struct timespec *ats) p = td->td_proc; switch (clock_id) { - case CLOCK_REALTIME: + case CLOCK_REALTIME: /* Default to precise. */ + case CLOCK_REALTIME_PRECISE: nanotime(ats); break; + case CLOCK_REALTIME_FAST: + getnanotime(ats); + break; case CLOCK_VIRTUAL: PROC_LOCK(p); calcru(p, &user, &sys); @@ -223,10 +227,20 @@ kern_clock_gettime(struct thread *td, clockid_t clock_id, struct timespec *ats) timevaladd(&user, &sys); TIMEVAL_TO_TIMESPEC(&user, ats); break; - case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC: /* Default to precise. */ + case CLOCK_MONOTONIC_PRECISE: case CLOCK_UPTIME: + case CLOCK_UPTIME_PRECISE: nanouptime(ats); break; + case CLOCK_UPTIME_FAST: + case CLOCK_MONOTONIC_FAST: + getnanouptime(ats); + break; + case CLOCK_SECOND: + ats->tv_sec = time_second; + ats->tv_nsec = 0; + break; default: return (EINVAL); } @@ -307,8 +321,14 @@ kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts) ts->tv_sec = 0; switch (clock_id) { case CLOCK_REALTIME: + case CLOCK_REALTIME_FAST: + case CLOCK_REALTIME_PRECISE: case CLOCK_MONOTONIC: + case CLOCK_MONOTONIC_FAST: + case CLOCK_MONOTONIC_PRECISE: case CLOCK_UPTIME: + case CLOCK_UPTIME_FAST: + case CLOCK_UPTIME_PRECISE: /* * Round up the result of the division cheaply by adding 1. * Rounding up is especially important if rounding down @@ -321,6 +341,10 @@ kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts) /* Accurately round up here because we can do so cheaply. */ ts->tv_nsec = (1000000000 + hz - 1) / hz; break; + case CLOCK_SECOND: + ts->tv_sec = 1; + ts->tv_nsec = 0; + break; default: return (EINVAL); } diff --git a/sys/sys/time.h b/sys/sys/time.h index 60f9543db0a1..657f0d49b409 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -238,7 +238,14 @@ struct clockinfo { #define CLOCK_VIRTUAL 1 #define CLOCK_PROF 2 #define CLOCK_MONOTONIC 4 -#define CLOCK_UPTIME 5 +#define CLOCK_UPTIME 5 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_PRECISE 7 /* FreeBSD-specific. */ +#define CLOCK_UPTIME_FAST 8 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_PRECISE 9 /* FreeBSD-specific. */ +#define CLOCK_REALTIME_FAST 10 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_PRECISE 11 /* FreeBSD-specific. */ +#define CLOCK_MONOTONIC_FAST 12 /* FreeBSD-specific. */ +#define CLOCK_SECOND 13 /* FreeBSD-specific. */ #endif #ifndef TIMER_ABSTIME