From: Shubing Guo Date: Tue, 1 Jul 2025 02:36:50 +0000 (+0800) Subject: vppinfra: fix cpu time on riscv X-Git-Tag: v26.02-rc0~112 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F77%2F43377%2F3;p=vpp.git vppinfra: fix cpu time on riscv 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 --- diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h index 761dbed3fe8..05e82f8895f 100644 --- a/src/vppinfra/time.h +++ b/src/vppinfra/time.h @@ -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