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 1/2] qemu-timer: Call clock reset notifiers on forward jumps
Date: Fri, 12 Jun 2015 10:08:45 -0400	[thread overview]
Message-ID: <20150612140845.GD2749@TopQuark.net> (raw)
In-Reply-To: <cover.1434067302.git.git@PaulSD.com>

Commit 691a0c9c introduced a mechanism by which QEMU_CLOCK_HOST can
notify other parts of the emulator when the host clock has jumped 
backward.  This is used to avoid stalling timers that were scheduled
based on the host clock.

However, if the host clock jumps forward, then timers that were
scheduled based on the host clock may fire rapidly and cause other
problems.  For example, the mc146818rtc periodic timer will block
execution of the VM and consume host CPU while firing every interrupt
for the time period that was skipped by the host clock.

To correct that problem, this commit fires the reset notification if the
host clock jumps forward by more than a hard-coded limit.  The limit is
currently set to a value of 60 seconds, which should be small enough to 
prevent excessive timer loops, but large enough to avoid frequent resets 
in idle VMs.

Signed-off-by: Paul Donohue <qemu-git@PaulSD.com>
---
 include/qemu/timer.h | 9 +++++++++
 qemu-timer.c         | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index e5bd494..0193036 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -787,6 +787,14 @@ static inline int64_t get_ticks_per_sec(void)
     return 1000000000LL;
 }
 
+static inline int64_t get_max_clock_jump(void)
+{
+    // This should be small enough to prevent excessive interrupts from being
+    // generated by the RTC on clock jumps, but large enough to avoid frequent
+    // unnecessary resets in idle VMs.
+    return 60 * get_ticks_per_sec();
+}
+
 /*
 *   * Low level clock functions
 *     */
diff --git a/qemu-timer.c b/qemu-timer.c
index 5741f0d..d27be3d 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -573,7 +573,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
         now = get_clock_realtime();
         last = clock->last;
         clock->last = now;
-        if (now < last) {
+        if (now < last || now > (last + get_max_clock_jump())) {
             notifier_list_notify(&clock->reset_notifiers, &now);
         }
         return now;
-- 
2.1.4

  reply	other threads:[~2015-06-12 14:08 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 ` Paul Donohue [this message]
2015-06-17 14:00   ` [Qemu-devel] [PATCH 1/2] qemu-timer: Call clock reset notifiers on forward jumps Paolo Bonzini
2015-06-18 12:58     ` Paul Donohue
2015-06-18 13:17       ` Paolo Bonzini
2015-06-12 14:10 ` [Qemu-devel] [PATCH 2/2] mc146818rtc: Reset the periodic timer on load Paul Donohue
2015-06-17 14:01   ` 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=20150612140845.GD2749@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.