Skip to content

Commit 9e5ea06

Browse files
xypronlsandov1
authored andcommitted
kern/riscv/efi/init: Use time register in grub_efi_get_time_ms()
The cycle register is not guaranteed to count at constant frequency. If it is counting at all depends on the state the performance monitoring unit. Use the time register to measure time. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Daniel Kiper <[email protected]>
1 parent 4ac041b commit 9e5ea06

File tree

1 file changed

+7
-8
lines changed
  • grub-core/kern/riscv/efi

1 file changed

+7
-8
lines changed

grub-core/kern/riscv/efi/init.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ grub_efi_get_time_ms (void)
3333
grub_uint64_t tmr;
3434

3535
#if __riscv_xlen == 64
36-
asm volatile ("rdcycle %0" : "=r" (tmr));
36+
asm volatile ("rdtime %0" : "=r"(tmr));
3737
#else
3838
grub_uint32_t lo, hi, tmp;
39-
asm volatile (
40-
"1:\n"
41-
"rdcycleh %0\n"
42-
"rdcycle %1\n"
43-
"rdcycleh %2\n"
44-
"bne %0, %2, 1b"
45-
: "=&r" (hi), "=&r" (lo), "=&r" (tmp));
39+
asm volatile ("1:\n"
40+
"rdtimeh %0\n"
41+
"rdtime %1\n"
42+
"rdtimeh %2\n"
43+
"bne %0, %2, 1b"
44+
: "=&r" (hi), "=&r" (lo), "=&r" (tmp));
4645
tmr = ((grub_uint64_t)hi << 32) | lo;
4746
#endif
4847

0 commit comments

Comments
 (0)