[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v3 38/49] replay: command line options
From: |
Pavel Dovgalyuk |
Subject: |
[Qemu-devel] [RFC PATCH v3 38/49] replay: command line options |
Date: |
Thu, 31 Jul 2014 16:57:02 +0400 |
User-agent: |
StGit/0.16 |
This patch introduces command line options for enabling recording or replaying
virtual machine behavior. "-record" option starts recording of the execution
and saves it into the log, specified with "fname" parameter. "-replay" option
is intended for replaying previously saved log.
Signed-off-by: Pavel Dovgalyuk <address@hidden>
---
cpus.c | 15 ++++++++--
qemu-options.hx | 29 ++++++++++++++++++++
replay/replay.c | 2 +
vl.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
4 files changed, 120 insertions(+), 5 deletions(-)
diff --git a/cpus.c b/cpus.c
index d5fa5d1..70df028 100644
--- a/cpus.c
+++ b/cpus.c
@@ -841,12 +841,21 @@ static void qemu_wait_io_event_common(CPUState *cpu)
static void qemu_tcg_wait_io_event(void)
{
CPUState *cpu;
+ GMainContext *context = g_main_context_default();
- while (all_cpu_threads_idle()) {
- /* Start accounting real time to the virtual clock if the CPUs
- are idle. */
+ if (replay_mode == REPLAY_MODE_PLAY
+ && all_cpu_threads_idle() && first_cpu->halted) {
+ /* wakeup iothread when there is no code to execute in replay mode */
qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
+ g_main_context_wakeup(context);
qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex);
+ } else {
+ while (all_cpu_threads_idle()) {
+ /* Start accounting real time to the virtual clock if the CPUs
+ are idle. */
+ qemu_clock_warp(QEMU_CLOCK_VIRTUAL);
+ qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex);
+ }
}
while (iothread_requesting_mutex) {
diff --git a/qemu-options.hx b/qemu-options.hx
index 1549625..7dcdf68 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3348,6 +3348,35 @@ Dump json-encoded vmstate information for current
machine type to file
in @var{file}
ETEXI
+DEF("record", HAS_ARG, QEMU_OPTION_record,
+ "-record
fname=<filename>[,suffix=<suffix>,snapshot=<on/off>,icount=<icount>]\n"
+ " writes replay file for latter replaying\n",
+ QEMU_ARCH_ALL)
+STEXI
address@hidden -record
address@hidden,address@hidden,address@hidden,address@hidden
+Writes compact execution trace into @var{file}.
+Changes for disk images are written
+into separate files with @var{suffix} added. If no @var{suffix} is
+specified, "replay_qcow" is used as suffix.
+If @var{snapshot} parameter is set as off, then original disk image will be
+modified. Default value is on.
address@hidden parameter is used for vm clock emulation.
+ETEXI
+
+DEF("replay", HAS_ARG, QEMU_OPTION_replay,
+ "-replay
fname=<filename>[,suffix=<suffix>,snapshot=<on/off>,icount=<icount>]\n"
+ " plays saved replay file\n", QEMU_ARCH_ALL)
+STEXI
address@hidden -replay
address@hidden,address@hidden,address@hidden,address@hidden
+Plays compact execution trace from @var{filename}.
+Changes for disk images and VM states are read
+from separate files with @var{suffix} added. If no @var{suffix} is
+specified, "replay_qcow" is used as suffix.
+If @var{snapshot} parameter is set as off, then original disk image will be
+modified. Default value is on.
address@hidden parameter is used for vm clock emulation.
+ETEXI
+
HXCOMM This is the last statement. Insert new options before this line!
STEXI
@end table
diff --git a/replay/replay.c b/replay/replay.c
index f3e7c09..ea4de5c 100755
--- a/replay/replay.c
+++ b/replay/replay.c
@@ -320,6 +320,8 @@ void replay_configure(QemuOpts *opts, int mode)
replay_image_suffix = g_strdup("replay_qcow");
}
+ replay_icount = (int)qemu_opt_get_number(opts, "icount", 0);
+
replay_enable(fname, mode);
}
diff --git a/vl.c b/vl.c
index bddea69..628aca6 100644
--- a/vl.c
+++ b/vl.c
@@ -538,6 +538,48 @@ static QemuOptsList qemu_mem_opts = {
},
};
+static QemuOptsList qemu_record_opts = {
+ .name = "record",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_record_opts.head),
+ .desc = {
+ {
+ .name = "fname",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "suffix",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "snapshot",
+ .type = QEMU_OPT_BOOL,
+ },{
+ .name = "icount",
+ .type = QEMU_OPT_NUMBER,
+ },
+ { /* end of list */ }
+ },
+};
+
+static QemuOptsList qemu_replay_opts = {
+ .name = "replay",
+ .head = QTAILQ_HEAD_INITIALIZER(qemu_replay_opts.head),
+ .desc = {
+ {
+ .name = "fname",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "suffix",
+ .type = QEMU_OPT_STRING,
+ },{
+ .name = "snapshot",
+ .type = QEMU_OPT_BOOL,
+ },{
+ .name = "icount",
+ .type = QEMU_OPT_NUMBER,
+ },
+ { /* end of list */ }
+ },
+};
+
/**
* Get machine options
*
@@ -2925,7 +2967,8 @@ out:
int main(int argc, char **argv, char **envp)
{
int i;
- int snapshot, linux_boot;
+ int snapshot, linux_boot, replay_snapshot;
+ int not_compatible_replay_param = 0;
const char *icount_option = NULL;
const char *initrd_filename;
const char *kernel_filename, *kernel_cmdline;
@@ -2997,6 +3040,8 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_msg_opts);
qemu_add_opts(&qemu_name_opts);
qemu_add_opts(&qemu_numa_opts);
+ qemu_add_opts(&qemu_replay_opts);
+ qemu_add_opts(&qemu_record_opts);
runstate_init();
@@ -3010,6 +3055,7 @@ int main(int argc, char **argv, char **envp)
cpu_model = NULL;
ram_size = default_ram_size;
snapshot = 0;
+ replay_snapshot = 1;
cyls = heads = secs = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
@@ -3127,6 +3173,7 @@ int main(int argc, char **argv, char **envp)
break;
case QEMU_OPTION_pflash:
drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
+ not_compatible_replay_param++;
break;
case QEMU_OPTION_snapshot:
snapshot = 1;
@@ -3283,6 +3330,7 @@ int main(int argc, char **argv, char **envp)
#endif
case QEMU_OPTION_bt:
add_device_config(DEV_BT, optarg);
+ not_compatible_replay_param++;
break;
case QEMU_OPTION_audio_help:
AUD_help ();
@@ -3497,6 +3545,7 @@ int main(int argc, char **argv, char **envp)
if (!opts) {
exit(1);
}
+ not_compatible_replay_param++;
break;
case QEMU_OPTION_fsdev:
olist = qemu_find_opts("fsdev");
@@ -3625,6 +3674,7 @@ int main(int argc, char **argv, char **envp)
if (strncmp(optarg, "mon:", 4) == 0) {
default_monitor = 0;
}
+ not_compatible_replay_param++;
break;
case QEMU_OPTION_debugcon:
add_device_config(DEV_DEBUGCON, optarg);
@@ -3745,6 +3795,7 @@ int main(int argc, char **argv, char **envp)
if (!qemu_opts_parse(qemu_find_opts("smp-opts"), optarg, 1)) {
exit(1);
}
+ not_compatible_replay_param++;
break;
case QEMU_OPTION_vnc:
#ifdef CONFIG_VNC
@@ -3979,6 +4030,24 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
break;
+ case QEMU_OPTION_record:
+ opts = qemu_opts_parse(qemu_find_opts("record"), optarg, 0);
+ if (!opts) {
+ fprintf(stderr, "Invalid record options: %s\n", optarg);
+ exit(1);
+ }
+ replay_configure(opts, REPLAY_MODE_RECORD);
+ replay_snapshot = qemu_opt_get_bool(opts, "snapshot", 1);
+ break;
+ case QEMU_OPTION_replay:
+ opts = qemu_opts_parse(qemu_find_opts("replay"), optarg, 0);
+ if (!opts) {
+ fprintf(stderr, "Invalid replay options: %s\n", optarg);
+ exit(1);
+ }
+ replay_configure(opts, REPLAY_MODE_PLAY);
+ replay_snapshot = qemu_opt_get_bool(opts, "snapshot", 1);
+ break;
default:
os_parse_cmd_args(popt->index, optarg);
}
@@ -3993,6 +4062,12 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
+ if (not_compatible_replay_param && (replay_mode != REPLAY_MODE_NONE)) {
+ fprintf(stderr, "options -smp, -pflash, -chardev, -bt, -parallel "
+ "are not compatible with record/replay\n");
+ exit(1);
+ }
+
if (qemu_opts_foreach(qemu_find_opts("sandbox"), parse_sandbox, NULL, 0)) {
exit(1);
}
@@ -4359,7 +4434,7 @@ int main(int argc, char **argv, char **envp)
ram_mig_init();
/* open the virtual block devices */
- if (snapshot)
+ if (snapshot || (replay_mode != REPLAY_MODE_NONE && replay_snapshot))
qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
NULL, 0);
if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
&machine_class->block_default_type, 1) != 0) {
- [Qemu-devel] [RFC PATCH v3 28/49] replay: recording and replaying clock ticks, (continued)
- [Qemu-devel] [RFC PATCH v3 28/49] replay: recording and replaying clock ticks, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 29/49] replay: recording and replaying different timers, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 30/49] replay: shutdown event, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 31/49] replay: checkpoints, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 32/49] vmclock: add virtual clock based on replay icount, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 33/49] replay: bottom halves, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 34/49] replay: replay aio requests, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 35/49] replay: thread pool, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 36/49] pl031: vmstate in replay mode, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 37/49] replay: initialization and deinitialization, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 38/49] replay: command line options,
Pavel Dovgalyuk <=
- [Qemu-devel] [RFC PATCH v3 39/49] replay: snapshotting the virtual machine, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 40/49] replay: recording of the user input, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 41/49] tap-win32: destroy the thread at exit, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 42/49] replay: network packets record/replay, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 43/49] replay: audio data record/replay, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 44/49] replay: serial port, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 45/49] replay: USB passthrough, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 46/49] replay: replay_info command, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 47/49] replay: replay_break command, Pavel Dovgalyuk, 2014/07/31
- [Qemu-devel] [RFC PATCH v3 48/49] replay: replay_seek_step command, Pavel Dovgalyuk, 2014/07/31