The networking people want a fast, monotonic clock that only advances
while the system is not suspended. The runtime clock satisfies most
of these requirements, so introduce getnsecruntime() to provide a fast
means for reading it.
Based on patches from jca@ and claudio@.
ok yasuoka@
-/* $OpenBSD: kern_tc.c,v 1.80 2022/12/05 23:18:37 deraadt Exp $ */
+/* $OpenBSD: kern_tc.c,v 1.81 2022/12/13 17:30:36 cheloha Exp $ */
/*
* Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
BINTIME_TO_TIMESPEC(&bt, ts);
}
+void
+getbinruntime(struct bintime *bt)
+{
+ struct timehands *th;
+ u_int gen;
+
+ do {
+ th = timehands;
+ gen = th->th_generation;
+ membar_consumer();
+ bintimesub(&th->th_offset, &th->th_naptime, bt);
+ membar_consumer();
+ } while (gen == 0 || gen != th->th_generation);
+}
+
+uint64_t
+getnsecruntime(void)
+{
+ struct bintime bt;
+
+ getbinruntime(&bt);
+ return BINTIME_TO_NSEC(&bt);
+}
+
void
bintime(struct bintime *bt)
{
-/* $OpenBSD: time.h,v 1.62 2022/07/23 22:58:51 cheloha Exp $ */
+/* $OpenBSD: time.h,v 1.63 2022/12/13 17:30:36 cheloha Exp $ */
/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft Exp $ */
/*
void binruntime(struct bintime *);
void nanoruntime(struct timespec *);
+void getbinruntime(struct bintime *);
+uint64_t getnsecruntime(void);
+
time_t gettime(void);
time_t getuptime(void);