upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv64: Replace rdcycle64 with rdtime64 when running in userspace (#194)

Reviewed-by: Török Edwin <edwintorok@users.noreply.github.com>

authored by

Adrian Bunk and committed by
GitHub
482d4b22 9ce288d4

+7 -2
+7 -2
src/native/entropy_cpu_stubs.c
··· 134 134 #endif 135 135 136 136 #if defined (__riscv) && (64 == __riscv_xlen) 137 - static inline uint64_t rdcycle64(void) 137 + //since rdcycle is a privileged instruction since linux 6.6, we use rdtime when in user-space 138 + static inline uint64_t cycle_count(void) 138 139 { 139 140 uint64_t rval; 141 + #if defined(__ocaml_freestanding__) || defined(__ocaml_solo5__) 140 142 __asm__ __volatile__ ("rdcycle %0" : "=r" (rval)); 143 + #else 144 + __asm__ __volatile__ ("rdtime %0" : "=r" (rval)); 145 + #endif /* __ocaml_freestanding__ || __ocaml_solo5__ */ 141 146 return rval; 142 147 } 143 148 #endif ··· 176 181 #elif defined(__powerpc64__) 177 182 return Val_long (read_cycle_counter ()); 178 183 #elif defined(__riscv) && (64 == __riscv_xlen) 179 - return Val_long (rdcycle64 ()); 184 + return Val_long (cycle_count ()); 180 185 #elif defined (__s390x__) 181 186 return Val_long (getticks ()); 182 187 #elif defined(__mips__)