From patchwork Fri Jun 12 14:10:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Donohue X-Patchwork-Id: 483709 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 E2F571402B4 for ; Sat, 13 Jun 2015 03:18:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=PaulSD.com header.i=@PaulSD.com header.b=XlCdRyo2; dkim-atps=neutral Received: from localhost ([::1]:52936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3SbN-0005on-1q for incoming@patchwork.ozlabs.org; Fri, 12 Jun 2015 13:18:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3Pf3-0007eg-0r for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z3Pex-00047l-1t for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:10:20 -0400 Received: from lepton.topquark.net ([168.235.66.66]:54625 helo=Mail2.TopQuark.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z3Pew-00047h-V7 for qemu-devel@nongnu.org; Fri, 12 Jun 2015 10:10:14 -0400 Received: from Mail1.TopQuark.net (pool-173-66-7-90.washdc.fios.verizon.net [173.66.7.90]) by Mail2.TopQuark.net (Postfix) with ESMTP id 8D4D0F60186; Fri, 12 Jun 2015 10:10:14 -0400 (EDT) Received: from Mail1.TopQuark.net (unknown [127.0.0.1]) by Mail1.TopQuark.net (Postfix) with ESMTP id 3230727EE1A5; Fri, 12 Jun 2015 10:10:14 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=PaulSD.com; h=date:from:to :cc:subject:message-id:mime-version:content-type:in-reply-to; s= mail; bh=9G5PmAU/5BLu2dTJAkjGt8biIKA=; b=XlCdRyo2YaonECKSEGSku1Q YewHPrIbAroJ6Hv3osaimycOQ177Eg3YATsz9rtgeWl3rUBV3fCbRIAAX4MkaCj3 wRSGE8HFSthEl4wgeImP0w52IUxWkTkgj/XGrsZ1JCOdsIfPLB+KyrM73/qbs75R lZ/UybU13KLsDLyF8zUs= Received: by Mail1.TopQuark.net (Postfix, from userid 1000) id 2020527EE1C8; Fri, 12 Jun 2015 10:10:14 -0400 (EDT) Date: Fri, 12 Jun 2015 10:10:14 -0400 From: Paul Donohue To: qemu-devel@nongnu.org Message-ID: <20150612141013.GE2749@TopQuark.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 168.235.66.66 X-Mailman-Approved-At: Fri, 12 Jun 2015 13:18:17 -0400 Cc: Paolo Bonzini Subject: [Qemu-devel] [PATCH 2/2] mc146818rtc: Reset the periodic timer on load 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 When loading a VM from a snapshot or migration, clock changes can cause the periodic timer to stall or loop rapidly. qemu-timer has a reset notifier mechanism that is used to avoid timer stalls or loops if the host clock changes while the VM is running when using QEMU_CLOCK_HOST. However, when loading a snapshot or migration, qemu-timer is initialized and fires the reset notifier before mc146818rtc is initialized and has registered its reset handler. In addition, this mechanism isn't used when using QEMU_CLOCK_REALTIME, which might also change when loading a snapshot or migration. To correct that problem, this commit resets the periodic timer after loading from a snapshot or migration if the clock has either jumped backward or has jumped forward by more than the clock jump limit that is used by the reset notifier code in qemu-timer. Signed-off-by: Paul Donohue --- hw/timer/mc146818rtc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index f2b77fa..68cf1f0 100644 --- a/hw/timer/mc146818rtc.c +++ b/hw/timer/mc146818rtc.c @@ -723,6 +723,12 @@ static int rtc_post_load(void *opaque, int version_id) check_update_timer(s); } + uint64_t now = qemu_clock_get_ns(rtc_clock); + if (now < (s->next_periodic_time - get_ticks_per_sec()) || + now > (s->next_periodic_time + get_max_clock_jump())) { + periodic_timer_update(s, qemu_clock_get_ns(rtc_clock)); + } + #ifdef TARGET_I386 if (version_id >= 2) { if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) {