On Fri, Jul 25, 2014 at 5:56 PM, Sebastian Tanase <sebastian.tan...@openwide.fr> wrote: > Make icount parameter use QemuOpts style options in order > to easily add other suboptions. > > Signed-off-by: Sebastian Tanase <sebastian.tan...@openwide.fr> > Tested-by: Camille Bégué <camille.be...@openwide.fr> > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > cpus.c | 10 +++++++++- > include/qemu-common.h | 3 ++- > qemu-options.hx | 4 ++-- > qtest.c | 13 +++++++++++-- > vl.c | 35 ++++++++++++++++++++++++++++------- > 5 files changed, 52 insertions(+), 13 deletions(-) > > diff --git a/cpus.c b/cpus.c > index 5e7f2cf..dcca96a 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -440,13 +440,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); > vmstate_register(NULL, 0, &vmstate_timers, &timers_state); > + option = qemu_opt_get(opts, "shift"); > if (!option) { > 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_rt, NULL); > diff --git a/vl.c b/vl.c > index 41ddcd2..103027f 100644 > --- a/vl.c > +++ b/vl.c > @@ -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 > * > @@ -2896,13 +2910,12 @@ int main(int argc, char **argv, char **envp) > { > int i; > int snapshot, linux_boot; > - const char *icount_option = NULL; > const char *initrd_filename; > const char *kernel_filename, *kernel_cmdline; > const char *boot_order; > DisplayState *ds; > int cyls, heads, secs, translation; > - QemuOpts *hda_opts = NULL, *opts, *machine_opts; > + QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL; > QemuOptsList *olist; > int optind; > const char *optarg; > @@ -2967,6 +2980,7 @@ 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_icount_opts); > > runstate_init(); > > @@ -3817,7 +3831,11 @@ int main(int argc, char **argv, char **envp) > } > break; > case QEMU_OPTION_icount: > - icount_option = optarg; > + icount_opts = qemu_opts_parse(qemu_find_opts("icount"), > + optarg, 1); > + if (!icount_opts) { > + exit(1); > + } > break; > case QEMU_OPTION_incoming: > incoming = optarg; > @@ -4294,11 +4312,14 @@ int main(int argc, char **argv, char **envp) > qemu_spice_init(); > #endif > > - if (icount_option && (kvm_enabled() || xen_enabled())) { > - fprintf(stderr, "-icount is not allowed with kvm or xen\n"); > - exit(1); > + if (icount_opts) { > + if (kvm_enabled() || xen_enabled()) { > + 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);
When icount_opts is null, seqlock_init() & vmstate_register() in configure_icount() cannot be executed. > /* clean up network at qemu process termination */ > atexit(&net_cleanup); > -- > 2.0.0.rc2 > >