Skip to content

Commit

Permalink
wip debug QEMU reset issues
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-h committed Mar 4, 2024
1 parent 2e7a954 commit 6d127af
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/arch/riscv/machine/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,33 @@ static inline void ackInterrupt(irq_t irq)
#ifndef CONFIG_KERNEL_MCS
void resetTimer(void)
{
uint64_t target;
// ToDo: On ARM we have TICKS_PER_MS defined TIMER_CLOCK_HZ / MS_IN_S,
// could also define this for RISC-V
uint64_t delta = (TIMER_CLOCK_HZ / MS_IN_S) * CONFIG_TIMER_TICK_MS;
// repeatedly try and set the timer in a loop as otherwise there is a race and we
// may set a timeout in the past, resulting in it never getting triggered
do {
target = riscv_read_time() + delta;
#if defined(CONFIG_PLAT_QEMU_RISCV_VIRT) || defined(CONFIG_PLAT_SPIKE)
int retry_cnt = 0;
for(;;)
{
#endif
uint64_t target = riscv_read_time() + delta;
sbi_set_timer(target);
} while (riscv_read_time() > target);
/* Perform a sanity check that the margin is big enough that we end up
* with a timestamp in the future. Seems it happened in QEMU that the
* simulation was too slow.
*/
uint64_t now = riscv_read_time();
if (likely(now < target)) {
return;
}
printf("Timer reset failed, %"PRIu64" (now) >= %"PRIu64"\n", now, target);
#if defined(CONFIG_PLAT_QEMU_RISCV_VIRT) || defined(CONFIG_PLAT_SPIKE)
retry_cnt++;
if (retry_cnt > 0) {
fail("Timer reset failed");
UNREACHABLE();
}
}
#endif
}

/**
Expand Down

0 comments on commit 6d127af

Please sign in to comment.