aboutsummaryrefslogtreecommitdiff
path: root/util/qemu-timer.c
diff options
context:
space:
mode:
authorPavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>2019-07-25 11:44:26 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2019-08-20 17:26:21 +0200
commitdcb1578069dd072f9aec74e3024cadb9ed0f3aae (patch)
treea3046cc620d45f20e983df481651c27402579767 /util/qemu-timer.c
parent978ae0e99c1760c228eef2d320386daab3bf5b10 (diff)
util/qemu-timer: refactor deadline calculation for external timers
icount-based record/replay uses qemu_clock_deadline_ns_all to measure the period until vCPU may be interrupted. This function takes in account the virtual timers, because they belong to the virtual devices that may generate interrupt request or affect the virtual machine state. However, there are a subset of virtual timers, that are marked with 'external' flag. These do not change the virtual machine state and only based on virtual clock. Calculating the deadling using the external timers breaks the determinism, because they do not belong to the replayed part of the virtual machine. This patch fixes the deadline calculation for this case by adding new parameter for skipping the external timers when it is needed. Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru> -- v2 changes: - added new parameter for timer attribute mask Message-Id: <156404426682.18669.17014100602930969222.stgit@pasha-Precision-3630-Tower> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/qemu-timer.c')
-rw-r--r--util/qemu-timer.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/util/qemu-timer.c b/util/qemu-timer.c
index 37ecfe31e8..d428fec567 100644
--- a/util/qemu-timer.c
+++ b/util/qemu-timer.c
@@ -247,14 +247,38 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list)
* ignore whether or not the clock should be used in deadline
* calculations.
*/
-int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
+int64_t qemu_clock_deadline_ns_all(QEMUClockType type, int attr_mask)
{
int64_t deadline = -1;
+ int64_t delta;
+ int64_t expire_time;
+ QEMUTimer *ts;
QEMUTimerList *timer_list;
QEMUClock *clock = qemu_clock_ptr(type);
+
+ if (!clock->enabled) {
+ return -1;
+ }
+
QLIST_FOREACH(timer_list, &clock->timerlists, list) {
- deadline = qemu_soonest_timeout(deadline,
- timerlist_deadline_ns(timer_list));
+ qemu_mutex_lock(&timer_list->active_timers_lock);
+ ts = timer_list->active_timers;
+ /* Skip all external timers */
+ while (ts && (ts->attributes & ~attr_mask)) {
+ ts = ts->next;
+ }
+ if (!ts) {
+ qemu_mutex_unlock(&timer_list->active_timers_lock);
+ continue;
+ }
+ expire_time = ts->expire_time;
+ qemu_mutex_unlock(&timer_list->active_timers_lock);
+
+ delta = expire_time - qemu_clock_get_ns(type);
+ if (delta <= 0) {
+ delta = 0;
+ }
+ deadline = qemu_soonest_timeout(deadline, delta);
}
return deadline;
}