#include "qemu/osdep.h"
#include "qapi/error.h"
+#include "sysemu/cpu-timers.h"
#include "sysemu/replay.h"
+#include "sysemu/runstate.h"
#include "replay-internal.h"
-#include "qemu/timer.h"
#include "qemu/main-loop.h"
#include "qemu/option.h"
#include "sysemu/cpus.h"
-#include "sysemu/sysemu.h"
#include "qemu/error-report.h"
/* Current version of the replay mechanism.
Increase it when file format changes. */
-#define REPLAY_VERSION 0xe02007
+#define REPLAY_VERSION 0xe0200a
/* Size of replay log header */
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
ReplayState replay_state;
static GSList *replay_blockers;
+/* Replay breakpoints */
+uint64_t replay_break_icount = -1ULL;
+QEMUTimer *replay_break_timer;
+
bool replay_next_event_is(int event)
{
bool res = false;
/* nothing to skip - not all instructions used */
- if (replay_state.instructions_count != 0) {
+ if (replay_state.instruction_count != 0) {
assert(replay_state.data_kind == EVENT_INSTRUCTION);
return event == EVENT_INSTRUCTION;
}
while (true) {
- if (event == replay_state.data_kind) {
+ unsigned int data_kind = replay_state.data_kind;
+ if (event == data_kind) {
res = true;
}
- switch (replay_state.data_kind) {
+ switch (data_kind) {
case EVENT_SHUTDOWN ... EVENT_SHUTDOWN_LAST:
replay_finish_event();
- qemu_system_shutdown_request(replay_state.data_kind -
- EVENT_SHUTDOWN);
+ qemu_system_shutdown_request(data_kind - EVENT_SHUTDOWN);
break;
default:
/* clock, time_t, checkpoint and other events */
return res;
}
-uint64_t replay_get_current_step(void)
+uint64_t replay_get_current_icount(void)
{
- return cpu_get_icount_raw();
+ return icount_get_raw();
}
int replay_get_instructions(void)
int res = 0;
replay_mutex_lock();
if (replay_next_event_is(EVENT_INSTRUCTION)) {
- res = replay_state.instructions_count;
+ res = replay_state.instruction_count;
+ if (replay_break_icount != -1LL) {
+ uint64_t current = replay_get_current_icount();
+ assert(replay_break_icount >= current);
+ if (current + res > replay_break_icount) {
+ res = replay_break_icount - current;
+ }
+ }
}
replay_mutex_unlock();
return res;
{
if (replay_mode == REPLAY_MODE_PLAY) {
g_assert(replay_mutex_locked());
- if (replay_state.instructions_count > 0) {
- int count = (int)(replay_get_current_step()
- - replay_state.current_step);
+ if (replay_state.instruction_count > 0) {
+ int count = (int)(replay_get_current_icount()
+ - replay_state.current_icount);
/* Time can only go forward */
assert(count >= 0);
- replay_state.instructions_count -= count;
- replay_state.current_step += count;
- if (replay_state.instructions_count == 0) {
+ replay_state.instruction_count -= count;
+ replay_state.current_icount += count;
+ if (replay_state.instruction_count == 0) {
assert(replay_state.data_kind == EVENT_INSTRUCTION);
replay_finish_event();
/* Wake up iothread. This is required because
will be read from the log. */
qemu_notify_event();
}
+ /* Execution reached the break step */
+ if (replay_break_icount == replay_state.current_icount) {
+ /* Cannot make callback directly from the vCPU thread */
+ timer_mod_ns(replay_break_timer,
+ qemu_clock_get_ns(QEMU_CLOCK_REALTIME));
+ }
}
}
}
/* This checkpoint belongs to several threads.
Processing events from different threads is
non-deterministic */
- if (checkpoint != CHECKPOINT_CLOCK_WARP_START) {
+ if (checkpoint != CHECKPOINT_CLOCK_WARP_START
+ /* FIXME: this is temporary fix, other checkpoints
+ may also be invoked from the different threads someday.
+ Asynchronous event processing should be refactored
+ to create additional replay event kind which is
+ nailed to the one of the threads and which processes
+ the event queue. */
+ && checkpoint != CHECKPOINT_CLOCK_VIRTUAL) {
replay_save_events(checkpoint);
}
res = true;
return res;
}
+bool replay_has_checkpoint(void)
+{
+ bool res = false;
+ if (replay_mode == REPLAY_MODE_PLAY) {
+ g_assert(replay_mutex_locked());
+ replay_account_executed_instructions();
+ res = EVENT_CHECKPOINT <= replay_state.data_kind
+ && replay_state.data_kind <= EVENT_CHECKPOINT_LAST;
+ }
+ return res;
+}
+
static void replay_enable(const char *fname, int mode)
{
const char *fmode = NULL;
replay_mutex_init();
replay_state.data_kind = -1;
- replay_state.instructions_count = 0;
- replay_state.current_step = 0;
+ replay_state.instruction_count = 0;
+ replay_state.current_icount = 0;
replay_state.has_unread_data = 0;
/* skip file header for RECORD and check it for PLAY */
error_reportf_err(replay_blockers->data, "Record/replay: ");
exit(1);
}
- if (!use_icount) {
+ if (!icount_enabled()) {
error_report("Please enable icount to use record/replay");
exit(1);
}
/* finalize the file */
if (replay_file) {
if (replay_mode == REPLAY_MODE_RECORD) {
+ /*
+ * Can't do it in the signal handler, therefore
+ * add shutdown event here for the case of Ctrl-C.
+ */
+ replay_shutdown_request(SHUTDOWN_CAUSE_HOST_SIGNAL);
/* write end event */
replay_put_event(EVENT_END);
g_free(replay_snapshot);
replay_snapshot = NULL;
+ replay_mode = REPLAY_MODE_NONE;
+
replay_finish_events();
}
{
replay_blockers = g_slist_prepend(replay_blockers, reason);
}
+
+const char *replay_get_filename(void)
+{
+ return replay_filename;
+}