All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Donohue <qemu-devel@PaulSD.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 2/2] mc146818rtc: Reset the periodic timer on load
Date: Fri, 12 Jun 2015 10:10:14 -0400	[thread overview]
Message-ID: <20150612141013.GE2749@TopQuark.net> (raw)
In-Reply-To: <cover.1434067302.git.git@PaulSD.com>

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 <qemu-git@PaulSD.com>
---
 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) {
-- 
2.1.4

  parent reply	other threads:[~2015-06-12 14:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 14:05 [Qemu-devel] [PATCH 0/2] qemu-timer/mc146818rtc: fix timer issues related to clock changes Paul Donohue
2015-06-12 14:08 ` [Qemu-devel] [PATCH 1/2] qemu-timer: Call clock reset notifiers on forward jumps Paul Donohue
2015-06-17 14:00   ` Paolo Bonzini
2015-06-18 12:58     ` Paul Donohue
2015-06-18 13:17       ` Paolo Bonzini
2015-06-12 14:10 ` Paul Donohue [this message]
2015-06-17 14:01   ` [Qemu-devel] [PATCH 2/2] mc146818rtc: Reset the periodic timer on load Paolo Bonzini
2015-06-18 14:36     ` Paul Donohue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150612141013.GE2749@TopQuark.net \
    --to=qemu-devel@paulsd.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.