ARM DDI 0487G.a states on page D13-4180 that, when the virtual timer is
enabled, the timer condition is met when CNTVCT_EL0 - CNTV_CVAL_EL0 >= 0.
Multiplying both sides of the inequality by -1, we get the equivalent
condition CNTV_CVAL_EL0 - CNTVCT_EL0 <= 0 for when the timer should fire.

On the same page, it states that a read of the CNTV_TVAL_EL0 register
returns CNTV_CVAL_EL0 - CNTVCT_EL0 if the virtual timer is enabled.
Putting the two together, the timer condition is met when the value of the
TVAL register is less than or *equal* to 0.

Same rules apply for the physical timer.

Fix the check for the timer expiring by treating a TVAL value equal to zero
as a valid condition for the timer to fire.

Signed-off-by: Alexandru Elisei <[email protected]>
---
 arm/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arm/timer.c b/arm/timer.c
index 09e3f8f6bd7d..2a6687f22874 100644
--- a/arm/timer.c
+++ b/arm/timer.c
@@ -277,7 +277,7 @@ static void test_timer(struct timer_info *info)
        local_irq_enable();
        left = info->read_tval();
        report(info->irq_received, "interrupt received after TVAL/WFI");
-       report(left < 0, "timer has expired");
+       report(left <= 0, "timer has expired");
        report_info("TVAL is %d ticks", left);
 }
 
-- 
2.34.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

Reply via email to