Skip to content

Commit 43356a2

Browse files
committed
unscaledcycleclock: remove RISC-V support
Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on RISC-V and can't be used directly from userland. There is a sysctl option to change that as a transition period, but it will eventually disappear. The RDTIME instruction is another less accurate alternative, however its frequency varies from board to board, and there is currently now way to get its frequency from userland [2]. Therefore this patch just removes the code for unscaledcycleclock on RISC-V. Without processor specific implementation, abseil relies on std::chrono::steady_clock::now().time_since_epoch() which is basically a wrapper around clock_gettime (CLOCK_MONOTONIC), which in turns use __vdso_clock_gettime(). On RISC-V this VDSO is just a wrapper around RDTIME correctly scaled to use nanoseconds units. This fixes the testsuite on riscv64, tested on a VisionFive 2 board. [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3 [2] #1631
1 parent 4024afb commit 43356a2

2 files changed

Lines changed: 3 additions & 15 deletions

File tree

absl/base/internal/unscaledcycleclock.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,6 @@ double UnscaledCycleClock::Frequency() {
121121
return aarch64_timer_frequency;
122122
}
123123

124-
#elif defined(__riscv)
125-
126-
int64_t UnscaledCycleClock::Now() {
127-
int64_t virtual_timer_value;
128-
asm volatile("rdcycle %0" : "=r"(virtual_timer_value));
129-
return virtual_timer_value;
130-
}
131-
132-
double UnscaledCycleClock::Frequency() {
133-
return base_internal::NominalCPUFrequency();
134-
}
135-
136124
#elif defined(_M_IX86) || defined(_M_X64)
137125

138126
#pragma intrinsic(__rdtsc)

absl/base/internal/unscaledcycleclock_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
// The following platforms have an implementation of a hardware counter.
2323
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
24-
defined(__powerpc__) || defined(__ppc__) || defined(__riscv) || \
25-
defined(_M_IX86) || (defined(_M_X64) && !defined(_M_ARM64EC))
24+
defined(__powerpc__) || defined(__ppc__) || defined(_M_IX86) || \
25+
(defined(_M_X64) && !defined(_M_ARM64EC))
2626
#define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1
2727
#else
2828
#define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 0
@@ -53,7 +53,7 @@
5353
#if ABSL_USE_UNSCALED_CYCLECLOCK
5454
// This macro can be used to test if UnscaledCycleClock::Frequency()
5555
// is NominalCPUFrequency() on a particular platform.
56-
#if (defined(__i386__) || defined(__x86_64__) || defined(__riscv) || \
56+
#if (defined(__i386__) || defined(__x86_64__) || \
5757
defined(_M_IX86) || defined(_M_X64))
5858
#define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY
5959
#endif

0 commit comments

Comments
 (0)