[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/15] qemu-timer: Call clock reset notifiers on forw
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 12/15] qemu-timer: Call clock reset notifiers on forward jumps |
Date: |
Fri, 19 Jun 2015 09:45:33 +0200 |
From: Paul Donohue <address@hidden>
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 <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
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..9e4f90f 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -787,6 +787,15 @@ 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..aa6757e 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.4.3
- [Qemu-devel] [PULL 03/15] qemu-ga: debug printouts to help troubleshoot installation, (continued)
- [Qemu-devel] [PULL 03/15] qemu-ga: debug printouts to help troubleshoot installation, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 04/15] qemu-ga: Introduce Windows MSI script, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 02/15] qemu-ga: adding vss-[un]install options, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 06/15] i8254: fix out-of-bounds memory access in pit_ioport_read(), Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 05/15] qemu-ga: Building Windows MSI installation with configure/Makefile, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 07/15] tests: Link libqos virtio object to virtio-scsi-test, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 08/15] libqos: Allow calling guest_free on NULL pointer, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 09/15] libqos: Complete virtio device ID definition list, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 10/15] tests: virtio-scsi: Move start/stop to individual test functions, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 11/15] tests: virtio-scsi: Add test for unaligned WRITE SAME, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 12/15] qemu-timer: Call clock reset notifiers on forward jumps,
Paolo Bonzini <=
- [Qemu-devel] [PULL 13/15] mc146818rtc: Reset the periodic timer on load, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 14/15] exec: do not clamp accesses to MMIO regions, Paolo Bonzini, 2015/06/19
- [Qemu-devel] [PULL 15/15] exec: clamp accesses against the MemoryRegionSection, Paolo Bonzini, 2015/06/19
- Re: [Qemu-devel] [PULL 00/15] Timer, virtio-scsi-test, build, memory changes for 2015-06-19, Peter Maydell, 2015/06/19