Skip to content

Commit fee562e

Browse files
vivierMichael Tokarev
authored and
Michael Tokarev
committed
i6300esb: fix timer overflow
We use muldiv64() to compute the time to wait: timeout = muldiv64(get_ticks_per_sec(), timeout, 33000000); but get_ticks_per_sec() is 10^9 (30 bit value) and timeout is a 35 bit value. Whereas muldiv64 is: uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) So we loose 3 bits of timeout. Swapping get_ticks_per_sec() and timeout fixes it. We can also replace it by a multiplication by 30 ns, but this changes PCI clock frequency from 33MHz to 33.333333MHz and we need to do this on all the QEMU PCI devices (later...) Signed-off-by: Laurent Vivier <[email protected]> Reviewed-by: David Gibson <[email protected]> Signed-off-by: Michael Tokarev <[email protected]>
1 parent 6883de6 commit fee562e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

hw/watchdog/wdt_i6300esb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void i6300esb_restart_timer(I6300State *d, int stage)
136136
* multiply here can exceed 64-bits, before we divide by 33MHz, so
137137
* we use a higher-precision intermediate result.
138138
*/
139-
timeout = muldiv64(get_ticks_per_sec(), timeout, 33000000);
139+
timeout = muldiv64(timeout, get_ticks_per_sec(), 33000000);
140140

141141
i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout);
142142

0 commit comments

Comments
 (0)