Skip to content

Commit 56a447e

Browse files
committed
[sw-sysemu] Fix rvtimer write_mtimecmp immediate interrupt raise
When mtimecmp is written to a value already in the past (mtime >= mtimecmp) and the interrupt was not previously asserted, raise the timer interrupt immediately. This mirrors hardware behavior where the comparator fires as soon as the condition is met. If the interrupt was already asserted (MIP bit already set), no action is needed — the hart already has a pending interrupt. Without this fix, tickless kernels that write mtimecmp to a nearly-passed value can deadlock: the internal interrupt flag is set but the hart MIP bit is never updated, so the ISR never fires and no subsequent write_mtimecmp call is made.
1 parent 94ff61b commit 56a447e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sw-sysemu/devices/rvtimer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ struct RVTimer
5757
agent.chip->clear_machine_timer_interrupt(shire);
5858
}
5959
}
60+
} else if (!had_interrupt && interrupt) {
61+
// raise immediately if mtimecmp is written in the past.
62+
for (unsigned shire = 0; shire < EMU_NUM_SHIRES; ++shire) {
63+
if ((interrupt_shire_mask >> shire) & 1) {
64+
agent.chip->raise_machine_timer_interrupt(shire);
65+
}
66+
}
6067
}
6168
}
6269

0 commit comments

Comments
 (0)