From patchwork Fri Jun 19 07:45:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 486611 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 927011401AF for ; Fri, 19 Jun 2015 17:56:10 +1000 (AEST) Received: from localhost ([::1]:56760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5r9k-00070M-Sc for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 03:56:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5r00-00064F-8x for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5qzz-0002QL-Ak for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5qzz-0002QE-32 for qemu-devel@nongnu.org; Fri, 19 Jun 2015 03:46:03 -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 AF15A2F02A9; Fri, 19 Jun 2015 07:46:02 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5J7jbhP019014; Fri, 19 Jun 2015 03:46:01 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 09:45:34 +0200 Message-Id: <1434699936-4433-14-git-send-email-pbonzini@redhat.com> In-Reply-To: <1434699936-4433-1-git-send-email-pbonzini@redhat.com> References: <1434699936-4433-1-git-send-email-pbonzini@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: Paul Donohue , Paul Donohue Subject: [Qemu-devel] [PULL 13/15] 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 From: Paul Donohue 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 Message-Id: <20150612141013.GE2749@TopQuark.net> Signed-off-by: Paolo Bonzini --- hw/timer/mc146818rtc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c index 3204825..2e3ffc8 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 || + 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) {