From 771d1f218553ae1abaee7ef934231e88b7e91b03 Mon Sep 17 00:00:00 2001 From: Marvin Schmidt Date: Fri, 20 Oct 2023 14:27:20 +0200 Subject: [PATCH] unscaledcycleclock: Replace rdcycle instruction with rdtime on RISC-V The `rdcycle` instruction causes SIGILL with RISCV_PMU_SBI=y in the kernel[1] According to a PR for the highway project[2] which fixed the same problem there `rdtime` is the proper equivalent for the x86 `rdtsc` instruction on RISC-V Using `rdtime` instead of `rdcycle` makes all tests pass on my VisionFive 2 board [1] https://lists.infradead.org/pipermail/linux-riscv/2022-September/018862.html [2] https://github.com/google/highway/pull/961 Signed-off-by: Marvin Schmidt --- absl/base/internal/unscaledcycleclock.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc index 05e0e7ba5ee..06374915c0d 100644 --- a/absl/base/internal/unscaledcycleclock.cc +++ b/absl/base/internal/unscaledcycleclock.cc @@ -125,7 +125,7 @@ double UnscaledCycleClock::Frequency() { int64_t UnscaledCycleClock::Now() { int64_t virtual_timer_value; - asm volatile("rdcycle %0" : "=r"(virtual_timer_value)); + asm volatile("rdtime %0" : "=r"(virtual_timer_value)); return virtual_timer_value; }