From acdc1d64c9a8eb97974905d49cde25d183f7c52f Mon Sep 17 00:00:00 2001 From: Shubing Guo Date: Tue, 1 Jul 2025 10:36:50 +0800 Subject: [PATCH] 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 --- src/vppinfra/time.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 -- 2.16.6