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 Jul 12, 2024
1 parent fca2edb commit f8e4062
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/arch/riscv/machine/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,24 @@ static inline void ackInterrupt(irq_t irq)
#ifndef CONFIG_KERNEL_MCS
void resetTimer(void)
{
assert(TIMER_CLOCK_HZ > 1000000); /* timer must be > 1 MHz */
/* timer must be > 1 kHz */
SEL4_COMPILE_ASSERT(timer_clock_1mhz, TIMER_CLOCK_HZ > 1000);
const uint64_t ticks_per_ms = TIMER_CLOCK_HZ / MS_IN_S;
const uint64_t delta = ticks_per_ms * CONFIG_TIMER_TICK_MS;
uint64_t target;
// 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;
sbi_set_timer(target);
} while (riscv_read_time() > target);
uint64_t target = riscv_read_time() + delta;
sbi_set_timer(target);
#if defined(CONFIG_PLAT_QEMU_RISCV_VIRT) || defined(CONFIG_PLAT_SPIKE)
/* 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)) {
printf("Timer reset failed, %"PRIu64" (now) >= %"PRIu64"\n", now, target);
fail("Timer reset failed");
UNREACHABLE();
}
#endif
}

/**
Expand Down

0 comments on commit f8e4062

Please sign in to comment.