From b60c48a7019614902f2debe4d4181ec8cfa60e0d Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:24:33 +0300 Subject: replay: shutdown event This patch records and replays simulator shutdown event. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162433.8676.32262.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- vl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 601ace2..f481a1e 100644 --- a/vl.c +++ b/vl.c @@ -122,6 +122,7 @@ int main(int argc, char **argv) #include "qapi-event.h" #include "exec/semihost.h" #include "crypto/init.h" +#include "sysemu/replay.h" #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 @@ -1803,6 +1804,7 @@ void qemu_system_killed(int signal, pid_t pid) void qemu_system_shutdown_request(void) { trace_qemu_system_shutdown_request(); + replay_shutdown_request(); shutdown_requested = 1; qemu_notify_event(); } -- 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 --- vl.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index f481a1e..8806092 100644 --- a/vl.c +++ b/vl.c @@ -1642,15 +1642,21 @@ static void qemu_kill_report(void) static int qemu_reset_requested(void) { int r = reset_requested; - reset_requested = 0; - return r; + if (r && replay_checkpoint(CHECKPOINT_RESET_REQUESTED)) { + reset_requested = 0; + return r; + } + return false; } static int qemu_suspend_requested(void) { int r = suspend_requested; - suspend_requested = 0; - return r; + if (r && replay_checkpoint(CHECKPOINT_SUSPEND_REQUESTED)) { + suspend_requested = 0; + return r; + } + return false; } static WakeupReason qemu_wakeup_requested(void) @@ -1798,7 +1804,12 @@ void qemu_system_killed(int signal, pid_t pid) shutdown_signal = signal; shutdown_pid = pid; no_shutdown = 0; - qemu_system_shutdown_request(); + + /* Cannot call qemu_system_shutdown_request directly because + * we are in a signal handler. + */ + shutdown_requested = 1; + qemu_notify_event(); } void qemu_system_shutdown_request(void) @@ -4483,6 +4494,10 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); + /* This checkpoint is required by replay to separate prior clock + reading from the other reads, because timer polling functions query + clock values from the log. */ + replay_checkpoint(CHECKPOINT_INIT); qdev_machine_init(); current_machine->ram_size = ram_size; @@ -4601,6 +4616,10 @@ int main(int argc, char **argv, char **envp) exit(1); } + /* This checkpoint is required by replay to separate prior clock + reading from the other reads, because timer polling functions query + clock values from the log. */ + replay_checkpoint(CHECKPOINT_RESET); qemu_system_reset(VMRESET_SILENT); register_global_state(); if (loadvm) { -- cgit v1.1 From 7615936ebf4e60c4565268a30df2356c841526f8 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:07 +0300 Subject: replay: initialization and deinitialization This patch introduces the functions for enabling the record/replay and for freeing the resources when simulator closes. Reviewed-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162507.8676.90232.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- vl.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'vl.c') diff --git a/vl.c b/vl.c index 8806092..b3ff137 100644 --- a/vl.c +++ b/vl.c @@ -4616,6 +4616,8 @@ int main(int argc, char **argv, char **envp) exit(1); } + replay_start(); + /* This checkpoint is required by replay to separate prior clock reading from the other reads, because timer polling functions query clock values from the log. */ @@ -4657,6 +4659,8 @@ int main(int argc, char **argv, char **envp) } main_loop(); + replay_disable_events(); + bdrv_close_all(); pause_all_vcpus(); res_free(); -- cgit v1.1 From 0194749ac4131e1bed8e166c5d5cf541678ef204 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:13 +0300 Subject: replay: replay blockers for devices Some devices are not supported by record/replay subsystem. This patch introduces replay blocker which denies starting record/replay if such devices are included into the configuration. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162512.8676.11367.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- vl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'vl.c') diff --git a/vl.c b/vl.c index b3ff137..c1e54f4 100644 --- a/vl.c +++ b/vl.c @@ -123,6 +123,7 @@ int main(int argc, char **argv) #include "exec/semihost.h" #include "crypto/init.h" #include "sysemu/replay.h" +#include "qapi/qmp/qerror.h" #define MAX_VIRTIO_CONSOLES 1 #define MAX_SCLP_CONSOLES 1 @@ -847,7 +848,11 @@ static void configure_rtc(QemuOpts *opts) if (!strcmp(value, "utc")) { rtc_utc = 1; } else if (!strcmp(value, "localtime")) { + Error *blocker = NULL; rtc_utc = 0; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, + "-rtc base=localtime"); + replay_add_blocker(blocker); } else { configure_rtc_date_offset(value, 0); } @@ -1256,6 +1261,11 @@ static void smp_parse(QemuOpts *opts) exit(1); } + if (smp_cpus > 1 || smp_cores > 1 || smp_threads > 1) { + Error *blocker = NULL; + error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); + replay_add_blocker(blocker); + } } static void realtime_init(void) -- cgit v1.1 From 4c27b859722089e0270fd4f41b4b3c63b6647439 Mon Sep 17 00:00:00 2001 From: Pavel Dovgalyuk Date: Thu, 17 Sep 2015 19:25:18 +0300 Subject: replay: command line options This patch introduces command line options for enabling recording or replaying virtual machine behavior. These options are added to icount command line parameter. They include 'rr' which switches between record and replay and 'rrfile' for specifying the filename for replay log. Signed-off-by: Pavel Dovgalyuk Message-Id: <20150917162518.8676.70792.stgit@PASHA-ISP.def.inno> Signed-off-by: Paolo Bonzini Signed-off-by: Pavel Dovgalyuk --- vl.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'vl.c') diff --git a/vl.c b/vl.c index c1e54f4..bc4890b 100644 --- a/vl.c +++ b/vl.c @@ -476,6 +476,12 @@ static QemuOptsList qemu_icount_opts = { }, { .name = "sleep", .type = QEMU_OPT_BOOL, + }, { + .name = "rr", + .type = QEMU_OPT_STRING, + }, { + .name = "rrfile", + .type = QEMU_OPT_STRING, }, { /* end of list */ } }, @@ -4014,6 +4020,8 @@ int main(int argc, char **argv, char **envp) } } + replay_configure(icount_opts); + opts = qemu_get_machine_opts(); optarg = qemu_opt_get(opts, "type"); if (optarg) { @@ -4447,9 +4455,10 @@ int main(int argc, char **argv, char **envp) } /* open the virtual block devices */ - if (snapshot) - qemu_opts_foreach(qemu_find_opts("drive"), - drive_enable_snapshot, NULL, NULL); + if (snapshot || replay_mode != REPLAY_MODE_NONE) { + qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot, + NULL, NULL); + } if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine_class->block_default_type, NULL)) { exit(1); -- cgit v1.1