This statement only works using 64-bit arithmetic for the main
63
counter never changing by more then 2 . (Which is a boundary
case that should not happen in my life time.)
Signed-off-by: Don Slutz <dslutz@verizon.com>
Acked-by: Tim Deegan <tim@xen.org>
uint64_t period = h->hpet.period[tn];
if (period)
{
- elapsed = hpet_read_maincounter(h, guest_time) +
- period - comparator;
- comparator += (elapsed / period) * period;
- h->hpet.comparator64[tn] = comparator;
+ elapsed = hpet_read_maincounter(h, guest_time) - comparator;
+ if ( (int64_t)elapsed >= 0 )
+ {
+ comparator += ((elapsed + period) / period) * period;
+ h->hpet.comparator64[tn] = comparator;
+ }
}
}