From patchwork Mon Aug 3 13:52:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 503159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3B5EA140E3B for ; Mon, 3 Aug 2015 23:53:11 +1000 (AEST) Received: from localhost ([::1]:59279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMGAu-0003Yg-El for incoming@patchwork.ozlabs.org; Mon, 03 Aug 2015 09:53:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50158) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMGAY-0002wl-T6 for qemu-devel@nongnu.org; Mon, 03 Aug 2015 09:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZMGAU-0007FY-Sb for qemu-devel@nongnu.org; Mon, 03 Aug 2015 09:52:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZMGAU-0007Et-Nm for qemu-devel@nongnu.org; Mon, 03 Aug 2015 09:52:42 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id B5CA78E90D; Mon, 3 Aug 2015 13:52:41 +0000 (UTC) Received: from thinkpad.redhat.com (vpn1-4-190.ams2.redhat.com [10.36.4.190]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t73DqdBh026447; Mon, 3 Aug 2015 09:52:39 -0400 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 3 Aug 2015 15:52:28 +0200 Message-Id: <1438609948-3744-1-git-send-email-lvivier@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Laurent Vivier , Paolo Bonzini , "Richard W.M. Jones" , David Gibson Subject: [Qemu-devel] [PATCH] i6300esb: correctly convert watchdog clock ticks into nanoseconds X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Originally, qemu_mod_timer() was using ticks to count time. And i6300esb was converting internal clock ticks (33 MHz) to QEMU timer ticks. The timer has been changed by a script to use nanoseconds: 7447545 change all other clock references to use nanosecond resolution accessors As i6300esb takes nanoseconds, we don't need anymore to multiply counter by get_ticks_per_sec()/33MHz, but instead we must convert watchdog ticks into nanoseconds. Signed-off-by: Laurent Vivier --- hw/watchdog/wdt_i6300esb.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/watchdog/wdt_i6300esb.c b/hw/watchdog/wdt_i6300esb.c index cfa2b1b..21119ab 100644 --- a/hw/watchdog/wdt_i6300esb.c +++ b/hw/watchdog/wdt_i6300esb.c @@ -124,19 +124,24 @@ static void i6300esb_restart_timer(I6300State *d, int stage) else timeout = d->timer2_preload; - if (d->clock_scale == CLOCK_SCALE_1KHZ) + /* convert timeout to 33Mhz clock ticks */ + if (d->clock_scale == CLOCK_SCALE_1KHZ) { + /* The 20-bit Preload Value is loaded into bits 34:15 of the + * main down counter. [...] The approximate clock generated + * is 1 KHz, (Default) + */ timeout <<= 15; - else + } else { + /* The 20-bit Preload Value is loaded into bits 24:5 of the + * main down counter. [...] The approximate clock generated + * is 1 MHz. + */ timeout <<= 5; - - /* Get the timeout in units of ticks_per_sec. - * - * ticks_per_sec is typically 10^9 == 0x3B9ACA00 (30 bits), with - * 20 bits of user supplied preload, and 15 bits of scale, the - * multiply here can exceed 64-bits, before we divide by 33MHz, so - * we use a higher-precision intermediate result. + } + /* A 33 Mhz clock gives a 30 ns tick, + * convert timeout from ticks to ns */ - timeout = muldiv64(get_ticks_per_sec(), timeout, 33000000); + timeout *= 30; i6300esb_debug("stage %d, timeout %" PRIi64 "\n", d->stage, timeout);