From patchwork Wed Jun 12 12:30:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bharat Bhushan X-Patchwork-Id: 250750 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 903C02C0098 for ; Wed, 12 Jun 2013 22:24:45 +1000 (EST) Received: from localhost ([::1]:48411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umk6O-0001ir-Cv for incoming@patchwork.ozlabs.org; Wed, 12 Jun 2013 08:24:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umk64-0001gS-7M for qemu-devel@nongnu.org; Wed, 12 Jun 2013 08:24:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Umk5z-0006vF-SW for qemu-devel@nongnu.org; Wed, 12 Jun 2013 08:24:16 -0400 Received: from co9ehsobe005.messaging.microsoft.com ([207.46.163.28]:43155 helo=co9outboundpool.messaging.microsoft.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umk5l-0006p0-PG; Wed, 12 Jun 2013 08:23:57 -0400 Received: from mail94-co9-R.bigfish.com (10.236.132.235) by CO9EHSOBE040.bigfish.com (10.236.130.103) with Microsoft SMTP Server id 14.1.225.23; Wed, 12 Jun 2013 12:23:56 +0000 Received: from mail94-co9 (localhost [127.0.0.1]) by mail94-co9-R.bigfish.com (Postfix) with ESMTP id 10019B80107; Wed, 12 Jun 2013 12:23:56 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 6 X-BigFish: VS6(zz853kzz1f42h1ee6h1de0h1fdah1202h1e76h1d1ah1d2ah1fc6h1082kzz8275bhz2dh2a8h668h839he5bhf0ah107ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e1dh1e23h1155h) Received: from mail94-co9 (localhost.localdomain [127.0.0.1]) by mail94-co9 (MessageSwitch) id 137103983479773_13878; Wed, 12 Jun 2013 12:23:54 +0000 (UTC) Received: from CO9EHSMHS001.bigfish.com (unknown [10.236.132.238]) by mail94-co9.bigfish.com (Postfix) with ESMTP id 10E3030005E; Wed, 12 Jun 2013 12:23:54 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS001.bigfish.com (10.236.130.11) with Microsoft SMTP Server (TLS) id 14.1.225.23; Wed, 12 Jun 2013 12:23:53 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.328.11; Wed, 12 Jun 2013 12:23:53 +0000 Received: from freescale.com ([10.232.15.72]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with SMTP id r5CCNgLk002541; Wed, 12 Jun 2013 05:23:49 -0700 Received: by freescale.com (sSMTP sendmail emulation); Wed, 12 Jun 2013 18:00:51 +0530 From: Bharat Bhushan To: , , , , , Date: Wed, 12 Jun 2013 18:00:50 +0530 Message-ID: <1371040250-23336-1-git-send-email-Bharat.Bhushan@freescale.com> X-Mailer: git-send-email 1.7.0.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.46.163.28 Cc: Bharat Bhushan Subject: [Qemu-devel] [PATCH] booke_ppc: limit booke timer to max when timeout overflow 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 Limit watchdog and fit timer to maximum timeout value which qemu timer can support (INT64_MAX). This maximum timeout will be hundreds of years, so limiting to max timeout is pretty safe. Signed-off-by: Bharat Bhushan --- hw/ppc/ppc_booke.c | 24 ++++++++++++++++++++---- 1 files changed, 20 insertions(+), 4 deletions(-) diff --git a/hw/ppc/ppc_booke.c b/hw/ppc/ppc_booke.c index e41b036..000c27f 100644 --- a/hw/ppc/ppc_booke.c +++ b/hw/ppc/ppc_booke.c @@ -131,17 +131,33 @@ static void booke_update_fixed_timer(CPUPPCState *env, struct QEMUTimer *timer) { ppc_tb_t *tb_env = env->tb_env; - uint64_t lapse; + uint64_t delta_tick, ticks = 0; uint64_t tb; - uint64_t period = 1 << (target_bit + 1); + uint64_t period; uint64_t now; now = qemu_get_clock_ns(vm_clock); tb = cpu_ppc_get_tb(tb_env, now, tb_env->tb_offset); + period = 1ULL << target_bit; + delta_tick = period - (tb & (period - 1)); - lapse = period - ((tb - (1 << target_bit)) & (period - 1)); + /* the timer triggers only when the selected bit toggles from 0 to 1 */ + if (tb & period) { + ticks = period; + } - *next = now + muldiv64(lapse, get_ticks_per_sec(), tb_env->tb_freq); + if (ticks + delta_tick < ticks) { + /* Overflow, so assume the biggest number we can express. */ + ticks = UINT64_MAX; + } else { + ticks += delta_tick; + } + + *next = now + muldiv64(ticks, get_ticks_per_sec(), tb_env->tb_freq); + if ((*next < now) || (*next > INT64_MAX)) { + /* Overflow, so assume the biggest number the qemu timer supports. */ + *next = INT64_MAX; + } /* XXX: If expire time is now. We can't run the callback because we don't * have access to it. So we just set the timer one nanosecond later.