Skip to content

Conversation

@AFOliveira
Copy link
Member

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 as 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.

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.
@AFOliveira
Copy link
Member Author

cc @vidas @glguida

@vidas
Copy link
Member

vidas commented Feb 10, 2026

Good catch! (And yes, this does match rtl, took a while to untangle). Could you a add a minimal test case (we have a few in `tests/erbium/)?
@yhxln Is there a risk this breaks something in DV?

@AFOliveira
Copy link
Member Author

Good catch! (And yes, this does match rtl, took a while to untangle). Could you a add a minimal test case (we have a few in `tests/erbium/)? @yhxln Is there a risk this breaks something in DV?

Of course!

@AFOliveira AFOliveira force-pushed the fix/rvtimer-mtimecmp-raise branch from 07e7244 to 1a34bc4 Compare February 10, 2026 16:44
@AFOliveira
Copy link
Member Author

Could you a add a minimal test case (we have a few in `tests/erbium/)?

Done.

@AFOliveira AFOliveira force-pushed the fix/rvtimer-mtimecmp-raise branch from 1a34bc4 to f31b49d Compare February 10, 2026 17:10
@AFOliveira
Copy link
Member Author

AFOliveira commented Feb 10, 2026

Force-pushing to fix the copyright date dismissed the CI flow

@yhxln
Copy link
Contributor

yhxln commented Feb 10, 2026

Good catch! (And yes, this does match rtl, took a while to untangle). Could you a add a minimal test case (we have a few in `tests/erbium/)? @yhxln Is there a risk this breaks something in DV?

From DV point of view I think this is change is fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants