From 8eda206e09089914006bfbdd71467d5246c06e4a Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:28 +0300 Subject: replay: recording and replaying clock ticks Clock ticks are considered as the sources of non-deterministic data for virtual machine. This patch implements saving the clock values when they are acquired (virtual, host clock). When replaying the execution corresponding values are read from log and transfered to the module, which wants to read the values. Such a design required the clock polling to be synchronized. Sometimes it is not true - e.g. when timeouts for timer lists are checked. In this case we use a cached value of the clock, passing it to the client code. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162427.8676.36558.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- qemu-timer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 2463fe6..3dc847b 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -24,6 +24,7 @@ #include "qemu/main-loop.h" #include "qemu/timer.h" +#include "sysemu/replay.h" #ifdef CONFIG_POSIX #include @@ -570,15 +571,16 @@ int64_t qemu_clock_get_ns(QEMUClockType type) return cpu_get_clock(); } case QEMU_CLOCK_HOST: - now = get_clock_realtime(); + now = REPLAY_CLOCK(REPLAY_CLOCK_HOST, get_clock_realtime()); last = clock->last; clock->last = now; - if (now < last || now > (last + get_max_clock_jump())) { + if ((now < last || now > (last + get_max_clock_jump())) + && replay_mode == REPLAY_MODE_NONE) { notifier_list_notify(&clock->reset_notifiers, &now); } return now; case QEMU_CLOCK_VIRTUAL_RT: - return cpu_get_clock(); + return REPLAY_CLOCK(REPLAY_CLOCK_VIRTUAL_RT, cpu_get_clock()); } } -- cgit v1.1 From 8bd7f71d794b93ce027b856f5b79a98f4f82e44c Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:44 +0300 Subject: replay: checkpoints This patch introduces checkpoints that synchronize cpu thread and iothread. When checkpoint is met in the code all asynchronous events from the queue are executed. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162444.8676.52916.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- qemu-timer.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 3dc847b..f16e422 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -25,6 +25,7 @@ #include "qemu/main-loop.h" #include "qemu/timer.h" #include "sysemu/replay.h" +#include "sysemu/sysemu.h" #ifdef CONFIG_POSIX #include @@ -478,10 +479,31 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) void *opaque; qemu_event_reset(&timer_list->timers_done_ev); - if (!timer_list->clock->enabled) { + if (!timer_list->clock->enabled || !timer_list->active_timers) { goto out; } + switch (timer_list->clock->type) { + case QEMU_CLOCK_REALTIME: + break; + default: + case QEMU_CLOCK_VIRTUAL: + if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL)) { + goto out; + } + break; + case QEMU_CLOCK_HOST: + if (!replay_checkpoint(CHECKPOINT_CLOCK_HOST)) { + goto out; + } + break; + case QEMU_CLOCK_VIRTUAL_RT: + if (!replay_checkpoint(CHECKPOINT_CLOCK_VIRTUAL_RT)) { + goto out; + } + break; + } + current_time = qemu_clock_get_ns(timer_list->clock->type); for(;;) { qemu_mutex_lock(&timer_list->active_timers_lock); @@ -545,11 +567,17 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg) { int64_t deadline = -1; QEMUClockType type; + bool play = replay_mode == REPLAY_MODE_PLAY; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - if (qemu_clock_use_for_deadline(tlg->tl[type]->clock->type)) { - deadline = qemu_soonest_timeout(deadline, - timerlist_deadline_ns( - tlg->tl[type])); + if (qemu_clock_use_for_deadline(type)) { + if (!play || type == QEMU_CLOCK_REALTIME) { + deadline = qemu_soonest_timeout(deadline, + timerlist_deadline_ns(tlg->tl[type])); + } else { + /* Read clock from the replay file and + do not calculate the deadline, based on virtual clock. */ + qemu_clock_get_ns(type); + } } } return deadline; @@ -574,8 +602,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type) now = REPLAY_CLOCK(REPLAY_CLOCK_HOST, get_clock_realtime()); last = clock->last; clock->last = now; - if ((now < last || now > (last + get_max_clock_jump())) - && replay_mode == REPLAY_MODE_NONE) { + if (now < last || now > (last + get_max_clock_jump())) { notifier_list_notify(&clock->reset_notifiers, &now); } return now; -- cgit v1.1