From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMXZe-0001eg-Lk for qemu-devel@nongnu.org; Tue, 04 Aug 2015 04:27:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMXZb-0002Gv-Gd for qemu-devel@nongnu.org; Tue, 04 Aug 2015 04:27:50 -0400 From: Laurent Vivier Date: Tue, 4 Aug 2015 10:27:31 +0200 Message-Id: <1438676851-10684-1-git-send-email-lvivier@redhat.com> In-Reply-To: <1438609948-3744-1-git-send-email-lvivier@redhat.com> References: <1438609948-3744-1-git-send-email-lvivier@redhat.com> Subject: [Qemu-devel] [PATCH][TRIVIAL] i6300esb: fix timer overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , "Richard W.M. Jones" , David Gibson 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 --- hw/watchdog/wdt_i6300esb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/watchdog/wdt_i6300esb.c b/hw/watchdog/wdt_i6300esb.c index cfa2b1b..3e07d44 100644 --- a/hw/watchdog/wdt_i6300esb.c +++ b/hw/watchdog/wdt_i6300esb.c @@ -136,7 +136,7 @@ static void i6300esb_restart_timer(I6300State *d, int stage) * multiply here can exceed 64-bits, before we divide by 33MHz, so * we use a higher-precision intermediate result. */ - timeout = muldiv64(get_ticks_per_sec(), timeout, 33000000); + timeout = muldiv64(timeout, get_ticks_per_sec(), 33000000); i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout); -- 2.1.0