summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2021-07-24 22:41:10 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2021-07-24 22:41:10 +0000
commitdf6eded9346cd76f9609ee91798c37fd914f3a17 (patch)
treeed6d89011e8632dea95a4a64d2bff4f9b1398561 /lib
parentc014fc69ca403223b4db4eeddcaac61a3832ea2d (diff)
riscv64 userland timecounter support
ok kettenis@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/arch/riscv64/gen/usertc.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/libc/arch/riscv64/gen/usertc.c b/lib/libc/arch/riscv64/gen/usertc.c
index 2274976a08f..f0f36b6fa38 100644
--- a/lib/libc/arch/riscv64/gen/usertc.c
+++ b/lib/libc/arch/riscv64/gen/usertc.c
@@ -1,6 +1,7 @@
-/* $OpenBSD: usertc.c,v 1.1 2021/04/29 18:33:36 drahn Exp $ */
+/* $OpenBSD: usertc.c,v 1.2 2021/07/24 22:41:09 jca Exp $ */
/*
* Copyright (c) 2020 Paul Irofti <paul@irofti.net>
+ * Copyright (c) 2021 Jeremie Courreges-Anglas <jca@wxcvbn.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,4 +19,26 @@
#include <sys/types.h>
#include <sys/timetc.h>
-int (*const _tc_get_timecount)(struct timekeep *, u_int *) = NULL;
+static inline u_int
+rdtime(void)
+{
+ uint64_t ret;
+
+ __asm volatile("rdtime %0" : "=r"(ret));
+
+ return ret;
+}
+
+static int
+tc_get_timecount(struct timekeep *tk, u_int *tc)
+{
+ switch (tk->tk_user) {
+ case TC_TB:
+ *tc = rdtime();
+ return 0;
+ }
+
+ return -1;
+}
+
+int (*const _tc_get_timecount)(struct timekeep *, u_int *) = tc_get_timecount;