提交 1ad9580b 编写于 作者: S Sebastian Tanase 提交者: Paolo Bonzini

icount: Add QemuOpts for icount

Make icount parameter use QemuOpts style options in order
to easily add other suboptions.
Signed-off-by: NSebastian Tanase <sebastian.tanase@openwide.fr>
Tested-by: NCamille Bégué <camille.begue@openwide.fr>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 71468395
...@@ -473,13 +473,21 @@ static const VMStateDescription vmstate_timers = { ...@@ -473,13 +473,21 @@ static const VMStateDescription vmstate_timers = {
} }
}; };
void configure_icount(const char *option) void configure_icount(QemuOpts *opts, Error **errp)
{ {
const char *option;
seqlock_init(&timers_state.vm_clock_seqlock, NULL); seqlock_init(&timers_state.vm_clock_seqlock, NULL);
vmstate_register(NULL, 0, &vmstate_timers, &timers_state); vmstate_register(NULL, 0, &vmstate_timers, &timers_state);
option = qemu_opt_get(opts, "shift");
if (!option) { if (!option) {
return; return;
} }
/* When using -icount shift, the shift option will be
misinterpreted as a boolean */
if (strcmp(option, "on") == 0 || strcmp(option, "off") == 0) {
error_setg(errp, "The shift option must be a number or auto");
}
icount_warp_timer = timer_new_ns(QEMU_CLOCK_REALTIME, icount_warp_timer = timer_new_ns(QEMU_CLOCK_REALTIME,
icount_warp_rt, NULL); icount_warp_rt, NULL);
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <assert.h> #include <assert.h>
#include <signal.h> #include <signal.h>
#include "glib-compat.h" #include "glib-compat.h"
#include "qemu/option.h"
#ifdef _WIN32 #ifdef _WIN32
#include "sysemu/os-win32.h" #include "sysemu/os-win32.h"
...@@ -105,7 +106,7 @@ static inline char *realpath(const char *path, char *resolved_path) ...@@ -105,7 +106,7 @@ static inline char *realpath(const char *path, char *resolved_path)
#endif #endif
/* icount */ /* icount */
void configure_icount(const char *option); void configure_icount(QemuOpts *opts, Error **errp);
extern int use_icount; extern int use_icount;
#include "qemu/osdep.h" #include "qemu/osdep.h"
......
...@@ -3011,11 +3011,11 @@ re-inject them. ...@@ -3011,11 +3011,11 @@ re-inject them.
ETEXI ETEXI
DEF("icount", HAS_ARG, QEMU_OPTION_icount, \ DEF("icount", HAS_ARG, QEMU_OPTION_icount, \
"-icount [N|auto]\n" \ "-icount [shift=N|auto]\n" \
" enable virtual instruction counter with 2^N clock ticks per\n" \ " enable virtual instruction counter with 2^N clock ticks per\n" \
" instruction\n", QEMU_ARCH_ALL) " instruction\n", QEMU_ARCH_ALL)
STEXI STEXI
@item -icount [@var{N}|auto] @item -icount [shift=@var{N}|auto]
@findex -icount @findex -icount
Enable virtual instruction counter. The virtual cpu will execute one Enable virtual instruction counter. The virtual cpu will execute one
instruction every 2^@var{N} ns of virtual time. If @code{auto} is specified instruction every 2^@var{N} ns of virtual time. If @code{auto} is specified
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
#include "hw/irq.h" #include "hw/irq.h"
#include "sysemu/sysemu.h" #include "sysemu/sysemu.h"
#include "sysemu/cpus.h" #include "sysemu/cpus.h"
#include "qemu/config-file.h"
#include "qemu/option.h"
#include "qemu/error-report.h"
#define MAX_IRQ 256 #define MAX_IRQ 256
...@@ -509,10 +512,16 @@ static void qtest_event(void *opaque, int event) ...@@ -509,10 +512,16 @@ static void qtest_event(void *opaque, int event)
} }
} }
int qtest_init_accel(MachineClass *mc) static void configure_qtest_icount(const char *options)
{ {
configure_icount("0"); QemuOpts *opts = qemu_opts_parse(qemu_find_opts("icount"), options, 1);
configure_icount(opts, &error_abort);
qemu_opts_del(opts);
}
int qtest_init_accel(MachineClass *mc)
{
configure_qtest_icount("0");
return 0; return 0;
} }
......
...@@ -537,6 +537,20 @@ static QemuOptsList qemu_mem_opts = { ...@@ -537,6 +537,20 @@ static QemuOptsList qemu_mem_opts = {
}, },
}; };
static QemuOptsList qemu_icount_opts = {
.name = "icount",
.implied_opt_name = "shift",
.merge_lists = true,
.head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
.desc = {
{
.name = "shift",
.type = QEMU_OPT_STRING,
},
{ /* end of list */ }
},
};
/** /**
* Get machine options * Get machine options
* *
...@@ -2908,13 +2922,12 @@ int main(int argc, char **argv, char **envp) ...@@ -2908,13 +2922,12 @@ int main(int argc, char **argv, char **envp)
{ {
int i; int i;
int snapshot, linux_boot; int snapshot, linux_boot;
const char *icount_option = NULL;
const char *initrd_filename; const char *initrd_filename;
const char *kernel_filename, *kernel_cmdline; const char *kernel_filename, *kernel_cmdline;
const char *boot_order; const char *boot_order;
DisplayState *ds; DisplayState *ds;
int cyls, heads, secs, translation; int cyls, heads, secs, translation;
QemuOpts *hda_opts = NULL, *opts, *machine_opts; QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
QemuOptsList *olist; QemuOptsList *olist;
int optind; int optind;
const char *optarg; const char *optarg;
...@@ -2979,6 +2992,7 @@ int main(int argc, char **argv, char **envp) ...@@ -2979,6 +2992,7 @@ int main(int argc, char **argv, char **envp)
qemu_add_opts(&qemu_msg_opts); qemu_add_opts(&qemu_msg_opts);
qemu_add_opts(&qemu_name_opts); qemu_add_opts(&qemu_name_opts);
qemu_add_opts(&qemu_numa_opts); qemu_add_opts(&qemu_numa_opts);
qemu_add_opts(&qemu_icount_opts);
runstate_init(); runstate_init();
...@@ -3830,7 +3844,11 @@ int main(int argc, char **argv, char **envp) ...@@ -3830,7 +3844,11 @@ int main(int argc, char **argv, char **envp)
} }
break; break;
case QEMU_OPTION_icount: case QEMU_OPTION_icount:
icount_option = optarg; icount_opts = qemu_opts_parse(qemu_find_opts("icount"),
optarg, 1);
if (!icount_opts) {
exit(1);
}
break; break;
case QEMU_OPTION_incoming: case QEMU_OPTION_incoming:
incoming = optarg; incoming = optarg;
...@@ -4306,11 +4324,14 @@ int main(int argc, char **argv, char **envp) ...@@ -4306,11 +4324,14 @@ int main(int argc, char **argv, char **envp)
qemu_spice_init(); qemu_spice_init();
#endif #endif
if (icount_option && (kvm_enabled() || xen_enabled())) { if (icount_opts) {
fprintf(stderr, "-icount is not allowed with kvm or xen\n"); if (kvm_enabled() || xen_enabled()) {
exit(1); fprintf(stderr, "-icount is not allowed with kvm or xen\n");
exit(1);
}
configure_icount(icount_opts, &error_abort);
qemu_opts_del(icount_opts);
} }
configure_icount(icount_option);
/* clean up network at qemu process termination */ /* clean up network at qemu process termination */
atexit(&net_cleanup); atexit(&net_cleanup);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册