From patchwork Sun Jun 30 01:45:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 255833 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 913452C02CE for ; Sun, 30 Jun 2013 11:51:03 +1000 (EST) Received: from localhost ([::1]:51152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6n7-0003J3-Fu for incoming@patchwork.ozlabs.org; Sat, 29 Jun 2013 21:51:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6hf-0003cw-Vg for qemu-devel@nongnu.org; Sat, 29 Jun 2013 21:45:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ut6hY-0007eF-Lq for qemu-devel@nongnu.org; Sat, 29 Jun 2013 21:45:23 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37021 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6hY-0007cv-DS; Sat, 29 Jun 2013 21:45:16 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F21DDA5526; Sun, 30 Jun 2013 03:45:14 +0200 (CEST) From: Alexander Graf To: qemu-ppc@nongnu.org Date: Sun, 30 Jun 2013 03:45:00 +0200 Message-Id: <1372556709-23868-24-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1372556709-23868-1-git-send-email-agraf@suse.de> References: <1372556709-23868-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: Blue Swirl , Bharat Bhushan , qemu-devel@nongnu.org, Aurelien Jarno , Bharat Bhushan Subject: [Qemu-devel] [PATCH 23/32] 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 From: Bharat Bhushan 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 Signed-off-by: Alexander Graf --- hw/ppc/ppc_booke.c | 24 ++++++++++++++++++++---- 1 file 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.