From patchwork Wed Nov 9 01:18:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 124463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7295D1007D6 for ; Wed, 9 Nov 2011 12:19:07 +1100 (EST) Received: from localhost ([::1]:52878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNwog-0000VR-Kn for incoming@patchwork.ozlabs.org; Tue, 08 Nov 2011 20:19:02 -0500 Received: from eggs.gnu.org ([140.186.70.92]:42907) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNwoa-0000VL-V6 for qemu-devel@nongnu.org; Tue, 08 Nov 2011 20:18:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RNwoZ-0006lw-SM for qemu-devel@nongnu.org; Tue, 08 Nov 2011 20:18:56 -0500 Received: from [188.134.19.124] (port=47097 helo=octofox.metropolis) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RNwoZ-0006le-Gg for qemu-devel@nongnu.org; Tue, 08 Nov 2011 20:18:55 -0500 Received: from octofox.metropolis (localhost [127.0.0.1]) by octofox.metropolis (8.14.5/8.14.5) with ESMTP id pA91IptT018232; Wed, 9 Nov 2011 05:18:52 +0400 Received: (from jcmvbkbc@localhost) by octofox.metropolis (8.14.5/8.14.5/Submit) id pA91IpgB018231; Wed, 9 Nov 2011 05:18:51 +0400 From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 9 Nov 2011 05:18:09 +0400 Message-Id: <1320801489-18193-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.7.6.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 188.134.19.124 Cc: Blue Swirl , Max Filippov , Alexander Graf Subject: [Qemu-devel] [PATCH] hpet: fix infinite loop in qemu_run_timers with -icount enabled 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 hpet_timer timer callback rearms itself based on difference between current HPET tick counter and comparator value. Difference calculated by the hpet_calculate_diff function is limited to non-negative values. cur_tick is calculated via hpet_get_ticks that uses qemu_get_clock_ns(vm_clock). With -icount enabled vm_clock doesn't advance during qemu_run_timers loop thus once difference is zero, qemu_run_timers loops forever handling hpet_timer. Limit hpet_calculate_diff results to positive only values to avoid that infinite loop. This fixes the following qemu-system-x86_64 hang when it reaches timer_irq_works() in the linux bootup: [ 0.000000] Fast TSC calibration using PIT [ 0.000000] Detected 1000.054 MHz processor. [ 0.000031] Calibrating delay loop (skipped), value calculated using timer frequency.. 2000.10 BogoMIPS (lpj=10000540) [ 0.000404] pid_max: default: 32768 minimum: 301 [ 0.001138] Mount-cache hash table entries: 256 [ 0.003883] Initializing cgroup subsys ns [ 0.004035] Initializing cgroup subsys cpuacct [ 0.004280] Initializing cgroup subsys freezer [ 0.004790] Performance Events: AMD PMU driver. [ 0.004985] ... version: 0 [ 0.005134] ... bit width: 48 [ 0.005285] ... generic registers: 4 [ 0.005437] ... value mask: 0000ffffffffffff [ 0.005625] ... max period: 00007fffffffffff [ 0.005807] ... fixed-purpose events: 0 [ 0.005957] ... event mask: 000000000000000f [ 0.006275] SMP alternatives: switching to UP code Signed-off-by: Max Filippov --- hw/hpet.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/hpet.c b/hw/hpet.c index 12bd64d..6e6ea52 100644 --- a/hw/hpet.c +++ b/hw/hpet.c @@ -157,14 +157,14 @@ static inline uint64_t hpet_calculate_diff(HPETTimer *t, uint64_t current) cmp = (uint32_t)t->cmp; diff = cmp - (uint32_t)current; - diff = (int32_t)diff > 0 ? diff : (uint32_t)0; + diff = (int32_t)diff > 0 ? diff : (uint32_t)1; return (uint64_t)diff; } else { uint64_t diff, cmp; cmp = t->cmp; diff = cmp - current; - diff = (int64_t)diff > 0 ? diff : (uint64_t)0; + diff = (int64_t)diff > 0 ? diff : (uint64_t)1; return diff; } }