From: Igor Mammedov <imammedo@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, aliguori@amazon.com,
stefanb@linux.vnet.ibm.com, hutao@cn.fujitsu.com, mst@redhat.com,
mjt@tls.msk.ru, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com,
vasilis.liaskovitis@profitbricks.com, quintela@redhat.com,
kraxel@redhat.com, stefanha@redhat.com, pbonzini@redhat.com,
marcel.a@redhat.com, lcapitulino@redhat.com, chegu_vinod@hp.com,
afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse()
Date: Tue, 26 Nov 2013 14:17:34 +0100 [thread overview]
Message-ID: <20131126141734.75dd61b9@thinkpad> (raw)
In-Reply-To: <87vbzmxdus.fsf@blackfin.pond.sub.org>
On Thu, 21 Nov 2013 11:12:43 +0100
Markus Armbruster <armbru@redhat.com> wrote:
> Igor Mammedov <imammedo@redhat.com> writes:
>
> > Along with conversion extend -m option to support following parameters:
>
> Please split this into two patches: first conversion to QemuOpts, then
> extension.
>
> > "mem" - startup memory amount
> > "slots" - total number of hotplug memory slots
> > "maxmem" - maximum possible memory
> >
> > "slots" and "maxmem" should go in pair and "maxmem" should be greater
> > than "mem" for memory hotplug to be usable.
> >
> > v2:
> > make sure maxmem is not less than ram size
> >
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > qemu-options.hx | 9 +++++-
> > vl.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++---------
> > 2 files changed, 68 insertions(+), 14 deletions(-)
> >
> > diff --git a/qemu-options.hx b/qemu-options.hx
> > index 8b94264..fe4559b 100644
> > --- a/qemu-options.hx
> > +++ b/qemu-options.hx
> > @@ -210,8 +210,13 @@ use is discouraged as it may be removed from future versions.
> > ETEXI
> >
> > DEF("m", HAS_ARG, QEMU_OPTION_m,
> > - "-m megs set virtual RAM size to megs MB [default="
> > - stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_ARCH_ALL)
> > + "-m [mem=]megs[,slots=n,maxmem=size]\n"
> > + " set virtual RAM size to megs MB [default="
> > + stringify(DEFAULT_RAM_SIZE) "]\n"
> > + " mem=start-up memory amount\n"
> > + " slots=maximum number of hotplug slots\n"
> > + " maxmem=maximum total amount of memory\n",
> > + QEMU_ARCH_ALL)
>
> Help text is confusing, because it discusses megs twice. Fits right in,
> as output of -help is generally confusing (to put it politely).
>
> What about something like this:
>
> -m [mem=]megs[,slots=n,maxmem=size]
> configure guest RAM
> mem: initial amount of guest memory (default: XXX)
> slots: number of hotplug slots (default: none)
> maxmem: maximum amount of guest memory (default: mem)
Sure, I'll fix it.
> > STEXI
> > @item -m @var{megs}
> > @findex -m
> > diff --git a/vl.c b/vl.c
> > index f28674f..5974f0f 100644
> > --- a/vl.c
> > +++ b/vl.c
> > @@ -529,6 +529,28 @@ static QemuOptsList qemu_msg_opts = {
> > },
> > };
> >
> > +static QemuOptsList qemu_mem_opts = {
> > + .name = "memory-opts",
> > + .implied_opt_name = "mem",
> > + .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
> > + .merge_lists = true,
>
> Yes, because multiple -m need to accumulate.
>
> > + .desc = {
> > + {
> > + .name = "mem",
> > + .type = QEMU_OPT_SIZE,
> > + },
> > + {
> > + .name = "slots",
> > + .type = QEMU_OPT_NUMBER,
> > + },
> > + {
> > + .name = "maxmem",
> > + .type = QEMU_OPT_SIZE,
> > + },
> > + { /* end of list */ }
> > + },
> > +};
> > +
> > /**
> > * Get machine options
> > *
> > @@ -2816,6 +2838,14 @@ static int object_create(QemuOpts *opts, void *opaque)
> > return 0;
> > }
> >
> > +static void qemu_init_default_mem_opts(uint64_t size)
> > +{
> > + QemuOpts *opts = qemu_opts_create_nofail(&qemu_mem_opts);
> > + qemu_opt_set_number(opts, "mem", size);
> > + qemu_opt_set_number(opts, "maxmem", size);
> > + qemu_opt_set_number(opts, "slots", 0);
> > +}
> > +
>
> We usually don't put defaults in QemuOpts. Instead, the code querying
> QemuOpts detects and handles absence of the parameter. Can be as simple
> as qemu_opt_get_size(opts, "mem", DEFAULT_RAM_SIZE * 1024 * 1024).
It allows to make number of uses a bit simpler:
for example v6:
QemuOpts *opts = qemu_opts_find(qemu_find_opts("memory-opts"), NULL);
if (!opts) { /* no -m x,... was passed to cmd line so no mem hotplug */
return;
}
mem_st->dev_count = qemu_opt_get_number(opts, "slots", 0);
becomes"
QemuOpts *opts = qemu_opts_find(qemu_find_opts("memory-opts"), NULL);
state->dev_count = qemu_opt_get_number(opts, "slots", 0);
and eliminates need to pepper code with DEFAULT_RAM_SIZE * 1024 * 1024 or
like constants wherever qemu_opt_get_..() is called, that was main reason
to set defaults. i.e. set defaults only once instead of spreading them in
every place qemu_opt_get_..() is called.
>
> See also below.
>
> > int main(int argc, char **argv, char **envp)
> > {
> > int i;
> > @@ -2887,6 +2917,7 @@ int main(int argc, char **argv, char **envp)
> > qemu_add_opts(&qemu_tpmdev_opts);
> > qemu_add_opts(&qemu_realtime_opts);
> > qemu_add_opts(&qemu_msg_opts);
> > + qemu_add_opts(&qemu_mem_opts);
> >
> > runstate_init();
> >
> > @@ -2901,7 +2932,8 @@ int main(int argc, char **argv, char **envp)
> > module_call_init(MODULE_INIT_MACHINE);
> > machine = find_default_machine();
> > cpu_model = NULL;
> > - ram_size = 0;
> > + ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
> > + qemu_init_default_mem_opts(ram_size);
> > snapshot = 0;
> > cyls = heads = secs = 0;
> > translation = BIOS_ATA_TRANSLATION_AUTO;
> > @@ -3178,21 +3210,43 @@ int main(int argc, char **argv, char **envp)
> > exit(0);
> > break;
> > case QEMU_OPTION_m: {
> > - int64_t value;
> > uint64_t sz;
> > - char *end;
> > + const char *end;
> > + char *s;
> >
> > - value = strtosz(optarg, &end);
> > - if (value < 0 || *end) {
> > - fprintf(stderr, "qemu: invalid ram size: %s\n", optarg);
> > + opts = qemu_opts_parse(qemu_find_opts("memory-opts"),
> > + optarg, 1);
> > + if (!opts) {
> > exit(1);
> > }
> > - sz = QEMU_ALIGN_UP((uint64_t)value, 8192);
> > +
> > + /* fixup legacy sugffix-less format */
>
> /* fix up legacy suffix-less format */
>
> The problem here is that OPT_SIZE treats values without a size suffix as
> bytes, but we need to default to MiB for backward compatibility.
>
> > + end = qemu_opt_get(opts, "mem");
> > + if (g_ascii_isdigit(end[strlen(end) - 1])) {
> > + s = g_strconcat(end, "M", NULL);
> > + qemu_opt_set(opts, "mem", s);
> > + g_free(s);
> > + }
>
> Ugly.
>
> Why is the variable called 'end'?
would be 'suffix' better?
>
> qemu_opt_set() appends to the list of options. The un-fixed-up option
> remains in the list. qemu_opt_unset() could fix that, but it asserts
> opts_accepts_any() for unclear reasons. git-blame points to Kevin.
it would be cleaner to unset it but it works event without unsetting it,
since qemu_opt_set...() adds to tail and qemu_opt_get...() finds options
from tail to head.
Nevertheless, Kevin do you recall reasons for assert in 0dd6c526:
int qemu_opt_unset(QemuOpts *opts, const char *name)
...
assert(opts_accepts_any(opts));
would it be ok if I remove it?
>
> Have you considered qemu_opt_set_number()?
it was code left from v6 when I didn't know about it. Sorry, I'll
use it instead.
>
> If this "need a default suffix" pattern exists elsewhere, we should
> consider extending QemuOptDesc to cover it.
I haven't seen/don't recall need for it anywhere else, but it would be
cleanest solution. But it would introduce temptation for users
to shrug off suffixes which is wrong in my opinion. -m 1024 is confusing
unless you know that it's in Mb.
it would be better not to introduce mechanism, that would allow to do such
thing in favor of explicit suffixes.
>
> > +
> > + sz = QEMU_ALIGN_UP(qemu_opt_get_size(opts, "mem", ram_size),
> > + 8192);
> > + /* compatibility behaviour for case "-m 0" */
> > + if (sz == 0) {
> > + sz = DEFAULT_RAM_SIZE * 1024 * 1024;
> > + }
> > +
>
> Yes, this is needed. Our command line is bonkers.
>
> > ram_size = sz;
> > if (ram_size != sz) {
> > fprintf(stderr, "qemu: ram size too large\n");
> > exit(1);
> > }
> > + /* store aligned value for future use */
> > + qemu_opt_set_number(opts, "mem", ram_size);
>
> Here, you use qemu_opt_set_number().
>
> Again, this appends to the list, and leaves the non-aligned value in.
it's not an issue since the last appended opt is used in qemu_opt_get_size().
>
> > +
> > + sz = qemu_opt_get_size(opts, "maxmem", ram_size);
> > + if (sz < ram_size) {
> > + qemu_opt_set_number(opts, "maxmem", ram_size);
> > + }
> > break;
> > }
>
> Looks like you want to fix up something like "-m 1024", so that maxmem
> stays equal to mem. I'm afraid you also "fix" user errors like "-m
> mem=1024M,maxmem=512M".
Perhaps it would be better to bail out with error here.
>
> If you refrain from putting defaults into opts, you can distinguish the
> cases "user didn't specify maxmem, so assume mem", and "user specified
> maxmem, so check it's >= mem".
So foar, there is no point in distinguishing above cases,
since maxmem <= mem is invalid value and hotplug should be disabled.
So setting default maxmem to mem or anything less effectively disables hotplug.
>
> > #ifdef CONFIG_TPM
> > @@ -4029,11 +4083,6 @@ int main(int argc, char **argv, char **envp)
> > exit(1);
> > }
> >
> > - /* init the memory */
> > - if (ram_size == 0) {
> > - ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
> > - }
> > -
> > if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
> > != 0) {
> > exit(0);
Thanks for review!
--
Regards,
Igor
next prev parent reply other threads:[~2013-11-26 13:18 UTC|newest]
Thread overview: 143+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 2:38 [Qemu-devel] [PATCH 00/27 RFC v7] ACPI memory hotplug Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 01/27] acpi: factor out common pm_update_sci() into acpi core Igor Mammedov
2013-12-05 12:37 ` Michael S. Tsirkin
2013-12-05 15:11 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 02/27] rename pci_hotplug_fn to hotplug_fn and make it available for other devices Igor Mammedov
2013-11-25 12:49 ` Paolo Bonzini
2013-11-25 13:11 ` Paolo Bonzini
2013-11-25 15:57 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 03/27] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS Igor Mammedov
2013-12-19 14:35 ` Michael S. Tsirkin
2013-12-20 12:48 ` Igor Mammedov
2013-12-22 11:20 ` Michael S. Tsirkin
2013-11-21 2:38 ` [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse() Igor Mammedov
2013-11-21 6:01 ` Li Guang
2013-11-21 13:45 ` Igor Mammedov
2013-11-21 10:12 ` Markus Armbruster
2013-11-26 13:17 ` Igor Mammedov [this message]
2013-11-26 14:49 ` Markus Armbruster
2013-11-26 16:55 ` Igor Mammedov
2013-11-27 14:35 ` Markus Armbruster
2013-11-27 15:28 ` Igor Mammedov
2013-11-27 17:31 ` Markus Armbruster
2013-11-27 0:27 ` [Qemu-devel] [PATCH 04/28] vl: convert -m to QemuOpts Igor Mammedov
2013-11-27 0:27 ` [Qemu-devel] [PATCH 05/28] vl.c: extend -m option to support options for memory hotplug Igor Mammedov
2013-12-10 7:23 ` [Qemu-devel] [PATCH 04/28] vl: convert -m to QemuOpts Paolo Bonzini
2013-12-10 10:53 ` Igor Mammedov
2013-11-25 12:51 ` [Qemu-devel] [PATCH 04/27] vl: convert -m to qemu_opts_parse() Paolo Bonzini
2013-11-27 0:32 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 05/27] qapi: add SIZE type parser to string_input_visitor Igor Mammedov
2013-11-21 10:15 ` Markus Armbruster
2013-11-25 15:36 ` Igor Mammedov
2013-11-25 16:04 ` Michael S. Tsirkin
2013-11-25 16:32 ` Paolo Bonzini
2013-11-25 16:43 ` Eric Blake
2013-11-25 17:01 ` Paolo Bonzini
2013-11-27 14:15 ` Markus Armbruster
2013-11-27 15:17 ` Paolo Bonzini
2013-11-27 17:02 ` Markus Armbruster
2013-11-27 17:10 ` Paolo Bonzini
2013-12-19 14:40 ` Michael S. Tsirkin
2013-12-19 15:14 ` Markus Armbruster
2013-12-19 15:32 ` Michael S. Tsirkin
2013-12-19 15:31 ` Paolo Bonzini
2013-12-19 15:40 ` Michael S. Tsirkin
2013-12-19 15:46 ` Paolo Bonzini
2013-11-21 2:38 ` [Qemu-devel] [PATCH 06/27] get reference to /backend container via qemu_get_backend() Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 07/27] add memdev backend infrastructure Igor Mammedov
2013-11-25 12:54 ` Paolo Bonzini
2013-11-25 16:01 ` Igor Mammedov
2013-11-25 16:09 ` Paolo Bonzini
2013-11-27 14:37 ` Igor Mammedov
2013-11-27 15:21 ` Paolo Bonzini
2013-11-27 15:57 ` Igor Mammedov
2013-11-27 15:25 ` Eric Blake
2013-11-27 16:09 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 08/27] dimm: implement dimm device abstraction Igor Mammedov
2013-11-25 12:57 ` Paolo Bonzini
2013-11-25 15:10 ` Igor Mammedov
2013-11-25 15:16 ` Paolo Bonzini
2013-11-21 2:38 ` [Qemu-devel] [PATCH 09/27] dimm: map DimmDevice into DimBus provided address space Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 10/27] dimm: add busy slot check and slot auto-allocation Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 11/27] dimm: add busy address check and address auto-allocation Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 12/27] dimm: add hotplug callback to DimmBus Igor Mammedov
2013-11-25 13:01 ` Paolo Bonzini
2013-11-25 14:40 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 13/27] acpi: memory hotplug ACPI hardware implementation Igor Mammedov
2013-11-21 9:42 ` Michael S. Tsirkin
2013-11-21 14:21 ` Igor Mammedov
2013-11-21 14:38 ` Michael S. Tsirkin
2013-11-22 17:14 ` Igor Mammedov
2013-11-24 10:58 ` Michael S. Tsirkin
2013-11-25 7:27 ` Markus Armbruster
2013-11-25 13:45 ` Paolo Bonzini
2013-11-25 14:18 ` Igor Mammedov
2013-11-25 14:31 ` Paolo Bonzini
2013-11-25 14:57 ` Igor Mammedov
2013-11-25 13:56 ` Igor Mammedov
2013-11-27 17:59 ` Eric Blake
2013-11-21 2:38 ` [Qemu-devel] [PATCH 14/27] acpi: initialize memory hotplug ACPI PIIX4 hardware Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 15/27] acpi: piix4: add memory-hotplug-io-base property to piix4_pm Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 16/27] acpi: ich9: allow guest to clear SCI rised by GPE Igor Mammedov
2013-11-21 7:14 ` Michael S. Tsirkin
2013-11-21 8:12 ` Hu Tao
2013-11-21 8:18 ` Li Guang
2013-11-21 8:29 ` Michael S. Tsirkin
2013-11-21 8:32 ` Li Guang
2013-11-21 9:43 ` Michael S. Tsirkin
2013-11-22 0:57 ` Li Guang
2013-11-25 11:13 ` Igor Mammedov
2013-11-26 0:29 ` Li Guang
2013-11-26 22:36 ` Igor Mammedov
2013-11-27 0:15 ` Li Guang
2013-11-27 0:57 ` Igor Mammedov
2013-11-27 1:48 ` Li Guang
2013-11-27 9:43 ` Paolo Bonzini
2013-11-21 13:19 ` Igor Mammedov
2013-11-22 1:03 ` Li Guang
2013-11-21 8:26 ` Michael S. Tsirkin
2013-11-21 8:28 ` Hu Tao
2013-11-21 13:31 ` Igor Mammedov
2013-11-21 13:21 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 17/27] acpi: initialize memory hotplug ACPI ICH9 hardware Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 18/27] acpi: ich9: add memory-hotplug-io-base property to ich9_pm Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 19/27] acpi: piix4/ich9: add optional vmstate field for MemHotplugState migration Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 20/27] pc: piix: make PCII440FXState type public Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 21/27] pc: add memory hotplug 440fx machine Igor Mammedov
2013-11-21 5:48 ` Li Guang
2013-11-21 14:13 ` Andreas Färber
2013-11-21 14:34 ` Igor Mammedov
2013-11-21 14:39 ` Michael S. Tsirkin
2013-11-21 16:09 ` Andreas Färber
2013-11-21 16:17 ` Michael S. Tsirkin
2013-11-25 10:41 ` Igor Mammedov
2013-11-25 17:00 ` Andreas Färber
2013-11-26 20:26 ` Igor Mammedov
2013-11-22 14:23 ` Gerd Hoffmann
2013-11-25 11:00 ` Igor Mammedov
2013-11-25 11:39 ` Gerd Hoffmann
2013-11-25 13:34 ` Igor Mammedov
2013-11-25 13:35 ` Paolo Bonzini
2013-11-25 14:24 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 22/27] pc: add memory hotplug Q35 machine Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 23/27] pc: ACPI BIOS: implement memory hotplug interface Igor Mammedov
2013-11-21 9:37 ` Michael S. Tsirkin
2013-11-25 14:39 ` Igor Mammedov
2013-12-16 19:50 ` Michael S. Tsirkin
2013-12-16 21:42 ` Igor Mammedov
2013-11-25 13:42 ` Paolo Bonzini
2013-11-25 14:26 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 24/27] pc: ACPI BIOS: add ssdt-mem.hex.generated and update ssdt-misc.hex.generated Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 25/27] pc: ACPI BIOS: use enum for defining memory affinity flags Igor Mammedov
2013-11-21 7:20 ` Michael S. Tsirkin
2013-11-25 10:11 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 26/27] pc: ACPI BIOS: reserve SRAT entry for hotplug mem hole Igor Mammedov
2013-11-21 7:18 ` Michael S. Tsirkin
2013-11-25 10:11 ` Igor Mammedov
2013-11-21 2:38 ` [Qemu-devel] [PATCH 27/27] pc: ACPI BIOS: make GPE.3 handle memory hotplug event on PIIX and Q35 machines Igor Mammedov
2013-11-21 6:20 ` [Qemu-devel] [PATCH 00/27 RFC v7] ACPI memory hotplug Michael S. Tsirkin
2013-11-21 13:39 ` Igor Mammedov
2013-11-21 13:43 ` Michael S. Tsirkin
2013-11-21 14:37 ` Igor Mammedov
2013-11-21 14:45 ` Michael S. Tsirkin
2013-11-25 10:09 ` Igor Mammedov
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=20131126141734.75dd61b9@thinkpad \
--to=imammedo@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=chegu_vinod@hp.com \
--cc=hutao@cn.fujitsu.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=marcel.a@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stefanha@redhat.com \
--cc=vasilis.liaskovitis@profitbricks.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.