From: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, quintela@redhat.com,
jasowang@redhat.com, mst@redhat.com, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCH v5 6/9] replay: save/load initial state
Date: Mon, 26 Sep 2016 11:08:32 +0300 [thread overview]
Message-ID: <20160926080832.6992.62982.stgit@PASHA-ISP> (raw)
In-Reply-To: <20160926080757.6992.74311.stgit@PASHA-ISP>
This patch implements initial vmstate creation or loading at the start
of record/replay. It is needed for rewinding the execution in the replay mode.
v4 changes:
- snapshots are not created by default anymore
v3 changes:
- added rrsnapshot option
Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
---
docs/replay.txt | 16 ++++++++++++++++
include/sysemu/replay.h | 9 +++++++++
qemu-options.hx | 8 ++++++--
replay/replay-snapshot.c | 17 +++++++++++++++++
replay/replay.c | 5 +++++
vl.c | 10 ++++++++--
6 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/docs/replay.txt b/docs/replay.txt
index 347b2ff..03e1931 100644
--- a/docs/replay.txt
+++ b/docs/replay.txt
@@ -196,6 +196,22 @@ is recorded to the log. In replay phase the queue is matched with
events read from the log. Therefore block devices requests are processed
deterministically.
+Snapshotting
+------------
+
+New VM snapshots may be created in replay mode. They can be used later
+to recover the desired VM state. All VM states created in replay mode
+are associated with the moment of time in the replay scenario.
+After recovering the VM state replay will start from that position.
+
+Default starting snapshot name may be specified with icount field
+rrsnapshot as follows:
+ -icount shift=7,rr=record,rrfile=replay.bin,rrsnapshot=snapshot_name
+
+This snapshot is created at start of recording and restored at start
+of replaying. It also can be loaded while replaying to roll back
+the execution.
+
Network devices
---------------
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index abb35ca..740b425 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -43,6 +43,9 @@ typedef struct ReplayNetState ReplayNetState;
extern ReplayMode replay_mode;
+/* Name of the initial VM snapshot */
+extern char *replay_snapshot;
+
/* Replay process control functions */
/*! Enables recording or saving event log with specified parameters */
@@ -149,4 +152,10 @@ void replay_unregister_net(ReplayNetState *rns);
void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
const struct iovec *iov, int iovcnt);
+/* VM state operations */
+
+/*! Called at the start of execution.
+ Loads or saves initial vmstate depending on execution mode. */
+void replay_vmstate_init(void);
+
#endif
diff --git a/qemu-options.hx b/qemu-options.hx
index 0b621bb..1aa046e 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3367,12 +3367,12 @@ re-inject them.
ETEXI
DEF("icount", HAS_ARG, QEMU_OPTION_icount, \
- "-icount [shift=N|auto][,align=on|off][,sleep=on|off,rr=record|replay,rrfile=<filename>]\n" \
+ "-icount [shift=N|auto][,align=on|off][,sleep=on|off,rr=record|replay,rrfile=<filename>,rrsnapshot=<snapshot>]\n" \
" enable virtual instruction counter with 2^N clock ticks per\n" \
" instruction, enable aligning the host and virtual clocks\n" \
" or disable real time cpu sleeping\n", QEMU_ARCH_ALL)
STEXI
-@item -icount [shift=@var{N}|auto][,rr=record|replay,rrfile=@var{filename}]
+@item -icount [shift=@var{N}|auto][,rr=record|replay,rrfile=@var{filename},rrsnapshot=@var{snapshot}]
@findex -icount
Enable virtual instruction counter. The virtual cpu will execute one
instruction every 2^@var{N} ns of virtual time. If @code{auto} is specified
@@ -3405,6 +3405,10 @@ when the shift value is high (how high depends on the host machine).
When @option{rr} option is specified deterministic record/replay is enabled.
Replay log is written into @var{filename} file in record mode and
read from this file in replay mode.
+
+Option rrsnapshot is used to create new vm snapshot named @var{snapshot}
+at the start of execution recording. In replay mode this option is used
+to load the initial VM state.
ETEXI
DEF("watchdog", HAS_ARG, QEMU_OPTION_watchdog, \
diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c
index 5609ea0..9a57026 100644
--- a/replay/replay-snapshot.c
+++ b/replay/replay-snapshot.c
@@ -58,4 +58,21 @@ static const VMStateDescription vmstate_replay = {
void replay_vmstate_register(void)
{
vmstate_register(NULL, 0, &vmstate_replay, &replay_state);
+}
+
+void replay_vmstate_init(void)
+{
+ if (replay_snapshot) {
+ if (replay_mode == REPLAY_MODE_RECORD) {
+ if (save_vmstate(cur_mon, replay_snapshot) != 0) {
+ error_report("Could not create snapshot for icount record");
+ exit(1);
+ }
+ } else if (replay_mode == REPLAY_MODE_PLAY) {
+ if (load_vmstate(replay_snapshot) != 0) {
+ error_report("Could not load snapshot for icount replay");
+ exit(1);
+ }
+ }
+ }
}
diff --git a/replay/replay.c b/replay/replay.c
index 7f27cf1..1835b99 100644
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -26,6 +26,7 @@
#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint64_t))
ReplayMode replay_mode = REPLAY_MODE_NONE;
+char *replay_snapshot;
/* Name of replay file */
static char *replay_filename;
@@ -292,6 +293,7 @@ void replay_configure(QemuOpts *opts)
exit(1);
}
+ replay_snapshot = g_strdup(qemu_opt_get(opts, "rrsnapshot"));
replay_vmstate_register();
replay_enable(fname, mode);
@@ -346,6 +348,9 @@ void replay_finish(void)
replay_filename = NULL;
}
+ g_free(replay_snapshot);
+ replay_snapshot = NULL;
+
replay_finish_events();
replay_mutex_destroy();
}
diff --git a/vl.c b/vl.c
index 1298be1..e1c90ef 100644
--- a/vl.c
+++ b/vl.c
@@ -460,6 +460,9 @@ static QemuOptsList qemu_icount_opts = {
}, {
.name = "rrfile",
.type = QEMU_OPT_STRING,
+ }, {
+ .name = "rrsnapshot",
+ .type = QEMU_OPT_STRING,
},
{ /* end of list */ }
},
@@ -4411,7 +4414,8 @@ int main(int argc, char **argv, char **envp)
}
/* open the virtual block devices */
- if (snapshot || replay_mode != REPLAY_MODE_NONE) {
+ if (snapshot
+ || (replay_mode != REPLAY_MODE_NONE && !replay_snapshot)) {
qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
NULL, NULL);
}
@@ -4591,7 +4595,9 @@ int main(int argc, char **argv, char **envp)
replay_checkpoint(CHECKPOINT_RESET);
qemu_system_reset(VMRESET_SILENT);
register_global_state();
- if (loadvm) {
+ if (replay_mode != REPLAY_MODE_NONE) {
+ replay_vmstate_init();
+ } else if (loadvm) {
if (load_vmstate(loadvm) < 0) {
autostart = 0;
}
next prev parent reply other threads:[~2016-09-26 8:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-26 8:07 [Qemu-devel] [PATCH v5 0/9] replay additions Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 1/9] replay: move internal data to the structure Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 2/9] replay: vmstate for replay module Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 3/9] replay: allow replay stopping and restarting Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 4/9] record/replay: add network support Pavel Dovgalyuk
2016-10-27 3:36 ` Jason Wang
2016-10-27 7:58 ` Paolo Bonzini
2016-10-31 7:41 ` Jason Wang
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 5/9] savevm: add public save_vmstate function Pavel Dovgalyuk
2016-09-26 8:15 ` Paolo Bonzini
2016-09-26 8:08 ` Pavel Dovgalyuk [this message]
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 7/9] block: don't make snapshots for filters Pavel Dovgalyuk
2016-09-26 9:23 ` Kevin Wolf
2016-09-26 9:51 ` Pavel Dovgalyuk
2016-09-26 13:17 ` Kevin Wolf
2016-09-27 14:06 ` Pavel Dovgalyuk
2016-09-28 8:36 ` Kevin Wolf
2016-09-28 9:32 ` Pavel Dovgalyuk
2016-09-28 9:43 ` Kevin Wolf
2016-09-28 12:49 ` Pavel Dovgalyuk
2016-09-29 10:32 ` Kevin Wolf
2016-11-16 9:49 ` Pavel Dovgalyuk
2016-11-16 12:15 ` Paolo Bonzini
2016-11-16 13:50 ` Pavel Dovgalyuk
2016-11-16 12:20 ` Kevin Wolf
2016-11-21 12:22 ` Pavel Dovgalyuk
2016-11-21 15:54 ` Kevin Wolf
2016-12-05 7:43 ` Pavel Dovgalyuk
2016-12-05 10:34 ` Kevin Wolf
2016-12-05 11:49 ` Pavel Dovgalyuk
2016-12-05 12:44 ` Kevin Wolf
2016-12-06 9:37 ` Pavel Dovgalyuk
2016-12-22 6:58 ` Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 8/9] block: implement bdrv_recurse_is_first_non_filter for blkreplay Pavel Dovgalyuk
2016-09-26 8:08 ` [Qemu-devel] [PATCH v5 9/9] integratorcp: adding vmstate for save/restore Pavel Dovgalyuk
2016-09-26 8:15 ` [Qemu-devel] [PATCH v5 0/9] replay additions Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160926080832.6992.62982.stgit@PASHA-ISP \
--to=pavel.dovgaluk@ispras.ru \
--cc=jasowang@redhat.com \
--cc=kwolf@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).