summaryrefslogtreecommitdiff
path: root/sys
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
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')
-rw-r--r--sys/kern/kern_tc.c26
-rw-r--r--sys/sys/time.h5
2 files changed, 29 insertions, 2 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;
diff --git a/sys/sys/time.h b/sys/sys/time.h
index d4736c97cb6..20bfba4cbb8 100644
--- a/sys/sys/time.h
+++ b/sys/sys/time.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -318,6 +318,9 @@ void nanoboottime(struct timespec *);
void binruntime(struct bintime *);
void nanoruntime(struct timespec *);
+void getbinruntime(struct bintime *);
+uint64_t getnsecruntime(void);
+
time_t gettime(void);
time_t getuptime(void);