summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorScott Soule Cheloha <cheloha@cvs.openbsd.org>2022-12-13 17:30:37 +0000
committerScott Soule Cheloha <cheloha@cvs.openbsd.org>2022-12-13 17:30:37 +0000
commit8fda787441e114b3f331fda79e94278fa88a345e (patch)
tree443c589099118b135b48c219eceec7f740c0c120 /sys/kern
parent875d73640e3ec1c92cb10cae20272a1ee8c03f06 (diff)
timecounting: add getbinruntime(), getnsecruntime()
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@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_tc.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c
index e8cc25b02d6..16cf1fa70b7 100644
--- a/sys/kern/kern_tc.c
+++ b/sys/kern/kern_tc.c
@@ -1,4 +1,4 @@
-/* $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>
@@ -295,6 +295,30 @@ nanoruntime(struct timespec *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)
{
struct timehands *th;