vppinfra: fix cpu time on riscv 77/43377/3
authorShubing Guo <[email protected]>
Tue, 1 Jul 2025 02:36:50 +0000 (10:36 +0800)
committerFlorin Coras <[email protected]>
Wed, 6 Aug 2025 23:17:09 +0000 (23:17 +0000)
Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on
RISC-V and can't be used directly from userland.Use RDTIME instead,
which while less accurate has the advantage of being synchronized
between CPU (and thus monotonic) and of constant frequency.

Type: fix
Change-Id: I53ab9cd1d0fcdd8f0e88d189840ba1d3b5ddd67a
Signed-off-by: Shubing Guo <[email protected]>
src/vppinfra/time.h

index 761dbed..05e82f8 100644 (file)
@@ -192,13 +192,13 @@ clib_cpu_time_now (void)
   return result;
 }
 
-#elif defined(__riscv)
+#elif defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen == 64)
 
 always_inline u64
 clib_cpu_time_now (void)
 {
   u64 result;
-  asm volatile("rdcycle %0\n" : "=r"(result));
+  asm volatile ("rdtime %0\n" : "=r"(result));
   return result;
 }
 #else