]> xenbits.xensource.com Git - people/andrewcoop/xen.git/commitdiff
xen/riscv: implement get_s_time()
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Tue, 15 Apr 2025 11:25:19 +0000 (13:25 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Apr 2025 11:26:42 +0000 (13:26 +0200)
Also tick_to_ns() is implemeted as it is used in get_s_time().

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich<jbeulich@suse.com>
xen/arch/riscv/include/asm/time.h
xen/arch/riscv/stubs.c
xen/arch/riscv/time.c

index e8d9ffec574ca30c29482ab94a0f1699dde0731f..63bdd471ccacda45d0b6e08cce1cfb49485e773b 100644 (file)
@@ -3,6 +3,7 @@
 #define ASM__RISCV__TIME_H
 
 #include <xen/bug.h>
+#include <xen/lib.h>
 #include <xen/types.h>
 #include <asm/csr.h>
 
@@ -23,6 +24,11 @@ static inline cycles_t get_cycles(void)
     return csr_read(CSR_TIME);
 }
 
+static inline s_time_t ticks_to_ns(uint64_t ticks)
+{
+    return muldiv64(ticks, MILLISECS(1), cpu_khz);
+}
+
 void preinit_xen_time(void);
 
 #endif /* ASM__RISCV__TIME_H */
index a1d64534cd9cd7947e67972459c9d79b6bd35e22..83416d3350c59fd2848a1deefb63fceb7cb1f124 100644 (file)
@@ -27,11 +27,6 @@ nodemask_t __read_mostly node_online_map = { { [0] = 1UL } };
 
 /* time.c */
 
-s_time_t get_s_time(void)
-{
-    BUG_ON("unimplemented");
-}
-
 int reprogram_timer(s_time_t timeout)
 {
     BUG_ON("unimplemented");
index 905bb13eb4db019139e5bc6eb7e7d5e39ef3335a..e962f8518d78e94142693f99bdfecf4031845981 100644 (file)
@@ -4,10 +4,18 @@
 #include <xen/init.h>
 #include <xen/lib.h>
 #include <xen/sections.h>
+#include <xen/types.h>
 
 unsigned long __ro_after_init cpu_khz; /* CPU clock frequency in kHz. */
 uint64_t __ro_after_init boot_clock_cycles;
 
+s_time_t get_s_time(void)
+{
+    uint64_t ticks = get_cycles() - boot_clock_cycles;
+
+    return ticks_to_ns(ticks);
+}
+
 /* Set up the timer on the boot CPU (early init function) */
 static void __init preinit_dt_xen_time(void)
 {