Skip to content

Commit 55712b6

Browse files
committed
Use fixed timeout during fake timer phase
The previous event-driven timer implementation caused hrtimer warnings and boot delays on macOS CI because it calculated wait times based on emulator's fake incremental timer but used host OS real-time timers. Root cause: - During boot, semu_timer_get() returns fake ticks (slow linear growth) - calc_ns_until_next_interrupt() converted these to nanoseconds - kqueue/timerfd waited using wall clock time Fix: Use conservative 1ms fixed timeout during boot phase. After boot completes and timer switches to real-time, use dynamic calculation for optimal CPU efficiency.
1 parent 75b6554 commit 55712b6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mini-gdbstub/include/gdbstub.h"
2626
#include "riscv.h"
2727
#include "riscv_private.h"
28+
#include "utils.h"
2829
#define PRIV(x) ((emu_state_t *) x->priv)
2930

3031
/* Forward declarations for coroutine support */
@@ -986,9 +987,20 @@ static void print_mmu_cache_stats(vm_t *vm)
986987

987988
/* Calculate nanoseconds until next timer interrupt.
988989
* Returns 0 if interrupt is already due, or capped at 100ms maximum.
990+
*
991+
* During boot (when using fake incremental timer), use conservative 1ms timeout
992+
* to avoid mismatch between emulator time and host OS timer.
989993
*/
990994
static uint64_t calc_ns_until_next_interrupt(emu_state_t *emu)
991995
{
996+
/* During boot, use fixed short timeout to avoid fake timer / real-time
997+
* mismatch. The fake timer advances slowly (incremental), but host OS
998+
* timers use wall clock time, which can cause large delays if we calculate
999+
* based on fake timer values.
1000+
*/
1001+
if (!boot_complete)
1002+
return 1000000ULL; /* 1ms - conservative but safe during boot */
1003+
9921004
uint64_t current_time = semu_timer_get(&emu->mtimer.mtime);
9931005
uint64_t next_int = emu->mtimer.next_interrupt_at;
9941006

0 commit comments

Comments
 (0)