summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/arch/riscv64/gen/usertc.c27
-rw-r--r--sys/arch/riscv64/include/timetc.h3
-rw-r--r--sys/arch/riscv64/riscv64/clock.c3
3 files changed, 29 insertions, 4 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;
diff --git a/sys/arch/riscv64/include/timetc.h b/sys/arch/riscv64/include/timetc.h
index 5b5bd942162..284749253cf 100644
--- a/sys/arch/riscv64/include/timetc.h
+++ b/sys/arch/riscv64/include/timetc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: timetc.h,v 1.2 2021/05/12 01:20:52 jsg Exp $ */
+/* $OpenBSD: timetc.h,v 1.3 2021/07/24 22:41:09 jca Exp $ */
/*
* Copyright (c) 2020 Paul Irofti <paul@irofti.net>
@@ -19,5 +19,6 @@
#ifndef _MACHINE_TIMETC_H_
#define _MACHINE_TIMETC_H_
+#define TC_TB 1
#endif /* _MACHINE_TIMETC_H_ */
diff --git a/sys/arch/riscv64/riscv64/clock.c b/sys/arch/riscv64/riscv64/clock.c
index 02984bb4ed8..15b2eaf8c5d 100644
--- a/sys/arch/riscv64/riscv64/clock.c
+++ b/sys/arch/riscv64/riscv64/clock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clock.c,v 1.2 2021/06/21 15:19:39 kettenis Exp $ */
+/* $OpenBSD: clock.c,v 1.3 2021/07/24 22:41:09 jca Exp $ */
/*
* Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
@@ -47,6 +47,7 @@ static struct timecounter tb_timecounter = {
.tc_name = "tb",
.tc_quality = 0,
.tc_priv = NULL,
+ .tc_user = TC_TB,
};
void cpu_startclock(void);