summaryrefslogtreecommitdiff
path: root/libhw/host_bootclock.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-28 23:51:15 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-28 23:51:15 -0600
commit4d185da010aea1d307c8ff7807ef3d4359083ed0 (patch)
tree0eef6621e8cadfb827e35cc0f426fdebb6096d10 /libhw/host_bootclock.c
parent52d48b9ea39a990295fdaf53dea492637051bd10 (diff)
wip host net timeout
Diffstat (limited to 'libhw/host_bootclock.c')
-rw-r--r--libhw/host_bootclock.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libhw/host_bootclock.c b/libhw/host_bootclock.c
new file mode 100644
index 0000000..ca9565c
--- /dev/null
+++ b/libhw/host_bootclock.c
@@ -0,0 +1,20 @@
+/* libhw/host_bootclock.c - <libhw/generic/bootclock.h> implementation for POSIX hosts
+ *
+ * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#include <assert.h>
+#include <time.h> /* for clock_gettime(), CLOCK_MONOTONIC, struct timespec */
+
+#include <libhw/generic/bootclock.h>
+
+uint64_t bootclock_get_ns(void) {
+ struct timespec ts;
+ int r;
+
+ r = clock_gettime(CLOCK_MONOTONIC, &ts);
+ assert(r == 0);
+
+ return (((uint64_t)ts.tv_sec) * NS_PER_S) + (uint64_t)ts.tv_nsec;
+}