Re: [Qemu-devel] [PATCH v3] hmp, qmp: introduce "info memory" and "query-memory" commands
Hi Guys, Thank you for the input. Please find updated patch v4 at http://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg07065.html. Vadim On Tue, Jun 27, 2017 at 4:14 PM, Eric Blakewrote: > On 06/27/2017 09:05 AM, Igor Mammedov wrote: > > On Wed, 14 Jun 2017 17:21:06 +0200 > > Vadim Galitsyn wrote: > > > > >> +void hmp_info_memory(Monitor *mon, const QDict *qdict) > >> +{ > >> +Error *err = NULL; > >> +MemoryInfo *info = qmp_query_memory(); > >> +if (info) { > >> +monitor_printf(mon, "base-memory: %" PRIu64 "\n", > >> + info->base_memory); > >> +monitor_printf(mon, "hot-plug-memory: %" PRIu64 "\n", > >> + info->hot_plug_memory); > > it shouldn't be printed if hotplug is not enabled > > In which case, the QAPI change in the .json file should mark it as > '*hot-plug-memory', to make it an optional field, and you'll need to > check/set info->has_hot_plug_memory as appropriate. > > > > >> +monitor_printf(mon, "ballooned-actual-memory: %" PRIu64 "\n", > >> + info->ballooned_actual_memory); > >> +g_free(info); > > > > probably there is autogenerated qapi_free_FOO() for MemInfo type > > Yes, there is. > > > since it's QAPI type, it should be used here instead of g_free() if it > exists. > > Yes, that is correct. > > > >> +# > >> +# @ballooned-actual-memory: amount of guest memory available after > ballooning. > >> +# > >> +# Since: 2.10.0 > >> +## > >> +{ 'struct': 'MemoryInfo', > >> + 'data' : { 'base-memory': 'int', > >> 'hot-plug-memory': 'int', > > should be optional and shown only if hotplug is actually enabled > > > >> + 'ballooned-actual-memory': 'int' } } > > maybe the same for ballooning > > Yes, that makes sense to have both of those stats be optional, since > they are opt-in configurations. > > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3266 > Virtualization: qemu.org | libvirt.org > >
Re: [Qemu-devel] [PATCH v3] hmp, qmp: introduce "info memory" and "query-memory" commands
On 06/27/2017 09:05 AM, Igor Mammedov wrote: > On Wed, 14 Jun 2017 17:21:06 +0200 > Vadim Galitsynwrote: > >> +void hmp_info_memory(Monitor *mon, const QDict *qdict) >> +{ >> +Error *err = NULL; >> +MemoryInfo *info = qmp_query_memory(); >> +if (info) { >> +monitor_printf(mon, "base-memory: %" PRIu64 "\n", >> + info->base_memory); >> +monitor_printf(mon, "hot-plug-memory: %" PRIu64 "\n", >> + info->hot_plug_memory); > it shouldn't be printed if hotplug is not enabled In which case, the QAPI change in the .json file should mark it as '*hot-plug-memory', to make it an optional field, and you'll need to check/set info->has_hot_plug_memory as appropriate. > >> +monitor_printf(mon, "ballooned-actual-memory: %" PRIu64 "\n", >> + info->ballooned_actual_memory); >> +g_free(info); > > probably there is autogenerated qapi_free_FOO() for MemInfo type Yes, there is. > since it's QAPI type, it should be used here instead of g_free() if it exists. Yes, that is correct. >> +# >> +# @ballooned-actual-memory: amount of guest memory available after >> ballooning. >> +# >> +# Since: 2.10.0 >> +## >> +{ 'struct': 'MemoryInfo', >> + 'data' : { 'base-memory': 'int', >> 'hot-plug-memory': 'int', > should be optional and shown only if hotplug is actually enabled > >> + 'ballooned-actual-memory': 'int' } } > maybe the same for ballooning Yes, that makes sense to have both of those stats be optional, since they are opt-in configurations. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org signature.asc Description: OpenPGP digital signature
Re: [Qemu-devel] [PATCH v3] hmp, qmp: introduce "info memory" and "query-memory" commands
On Wed, 14 Jun 2017 17:21:06 +0200 Vadim Galitsynwrote: > Commands above provide the following memory information in bytes: > > * base-memory - amount of static memory specified > with '-m' option at the start of the QEMU process. > > * hot-plug-memory - amount of memory that was hot-plugged. > > * ballooned-actual-memory - size of the memory that remains > available to the guest after ballooning, as reported by the > guest. If the guest has not reported its memory, this value > equals to @base-memory + @hot-plug-memory. If ballooning > is not enabled, zero value is reported. > > NOTE: > > Parameter @ballooned-actual-memory reports the same as > "info balloon" command when ballooning is enabled. The idea > to have it in scope of this command(s) comes from > https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01472.html. > > Signed-off-by: Vasilis Liaskovitis > Signed-off-by: Mohammed Gamal > Signed-off-by: Eduardo Otubo > Signed-off-by: Vadim Galitsyn > Reviewed-by: Eugene Crosser > Cc: Dr. David Alan Gilbert > Cc: Markus Armbruster > Cc: qemu-devel@nongnu.org > --- > > v3: > * Use PRIu64 instead of 'lu' when printing results via HMP. > * Report zero hot-plugged memory instead of reporting error >when target architecture has no CONFIG_MEM_HOTPLUG enabled. > > v2: > * Fixed build for targets which do not have CONFIG_MEM_HOTPLUG enabled. > > hmp-commands-info.hx | 15 +++ > hmp.c| 16 > hmp.h| 1 + > qapi-schema.json | 27 +++ > qmp.c| 36 > 5 files changed, 95 insertions(+) > > diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx > index ae169011b1..bc37525550 100644 > --- a/hmp-commands-info.hx > +++ b/hmp-commands-info.hx > @@ -833,6 +833,21 @@ STEXI > @end table > ETEXI > > +STEXI > +@item info memory s/memory/memory-size-summary/ maybe the same for qmp command name > +@findex memory > +Display *** s/***/summary present memory size including hotplugged, ballooned if enabled. or something like this > +ETEXI > + > +{ > +.name = "memory", > +.args_type = "", > +.params = "", > +.help = "show memory size information in bytes (static, " > + "hotplugged, ballooned)", > +.cmd= hmp_info_memory, > +}, > + > STEXI > @end table > ETEXI > diff --git a/hmp.c b/hmp.c > index 8c72c58b20..d6ec686376 100644 > --- a/hmp.c > +++ b/hmp.c > @@ -2817,3 +2817,19 @@ void hmp_info_vm_generation_id(Monitor *mon, const > QDict *qdict) > hmp_handle_error(mon, ); > qapi_free_GuidInfo(info); > } > + > +void hmp_info_memory(Monitor *mon, const QDict *qdict) > +{ > +Error *err = NULL; > +MemoryInfo *info = qmp_query_memory(); > +if (info) { > +monitor_printf(mon, "base-memory: %" PRIu64 "\n", > + info->base_memory); > +monitor_printf(mon, "hot-plug-memory: %" PRIu64 "\n", > + info->hot_plug_memory); it shouldn't be printed if hotplug is not enabled > +monitor_printf(mon, "ballooned-actual-memory: %" PRIu64 "\n", > + info->ballooned_actual_memory); > +g_free(info); probably there is autogenerated qapi_free_FOO() for MemInfo type since it's QAPI type, it should be used here instead of g_free() if it exists. > +} > +hmp_handle_error(mon, ); > +} > diff --git a/hmp.h b/hmp.h > index d8b94ce9dc..c422aa2fac 100644 > --- a/hmp.h > +++ b/hmp.h > @@ -143,5 +143,6 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict); > void hmp_info_ramblock(Monitor *mon, const QDict *qdict); > void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); > void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); > +void hmp_info_memory(Monitor *mon, const QDict *qdict); > > #endif > diff --git a/qapi-schema.json b/qapi-schema.json > index 4b50b652d3..33cd7cb3b8 100644 > --- a/qapi-schema.json > +++ b/qapi-schema.json > @@ -4324,6 +4324,33 @@ >'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool', > '*unavailable-features': [ 'str' ], 'typename': 'str' } } > > +## > +# @MemoryInfo: > +# > +# Memory information in bytes. s/Memory/Present memory/ > +# > +# @base-memory: size of static memory which was specified on Qemu start. s/static/unremovable/ s/was specified on Qemu start/is specified with '-m size' CLI option > +# > +# @hot-plug-memory: size of hot-plugged memory. hotpluggable-memory > +# > +# @ballooned-actual-memory: amount of guest memory available after > ballooning. > +# > +# Since: 2.10.0 > +## > +{
[Qemu-devel] [PATCH v3] hmp, qmp: introduce "info memory" and "query-memory" commands
Commands above provide the following memory information in bytes: * base-memory - amount of static memory specified with '-m' option at the start of the QEMU process. * hot-plug-memory - amount of memory that was hot-plugged. * ballooned-actual-memory - size of the memory that remains available to the guest after ballooning, as reported by the guest. If the guest has not reported its memory, this value equals to @base-memory + @hot-plug-memory. If ballooning is not enabled, zero value is reported. NOTE: Parameter @ballooned-actual-memory reports the same as "info balloon" command when ballooning is enabled. The idea to have it in scope of this command(s) comes from https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01472.html. Signed-off-by: Vasilis LiaskovitisSigned-off-by: Mohammed Gamal Signed-off-by: Eduardo Otubo Signed-off-by: Vadim Galitsyn Reviewed-by: Eugene Crosser Cc: Dr. David Alan Gilbert Cc: Markus Armbruster Cc: qemu-devel@nongnu.org --- v3: * Use PRIu64 instead of 'lu' when printing results via HMP. * Report zero hot-plugged memory instead of reporting error when target architecture has no CONFIG_MEM_HOTPLUG enabled. v2: * Fixed build for targets which do not have CONFIG_MEM_HOTPLUG enabled. hmp-commands-info.hx | 15 +++ hmp.c| 16 hmp.h| 1 + qapi-schema.json | 27 +++ qmp.c| 36 5 files changed, 95 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae169011b1..bc37525550 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -833,6 +833,21 @@ STEXI @end table ETEXI +STEXI +@item info memory +@findex memory +Display total memory size in bytes (static, hotplugged, ballooned) +ETEXI + +{ +.name = "memory", +.args_type = "", +.params = "", +.help = "show memory size information in bytes (static, " + "hotplugged, ballooned)", +.cmd= hmp_info_memory, +}, + STEXI @end table ETEXI diff --git a/hmp.c b/hmp.c index 8c72c58b20..d6ec686376 100644 --- a/hmp.c +++ b/hmp.c @@ -2817,3 +2817,19 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict) hmp_handle_error(mon, ); qapi_free_GuidInfo(info); } + +void hmp_info_memory(Monitor *mon, const QDict *qdict) +{ +Error *err = NULL; +MemoryInfo *info = qmp_query_memory(); +if (info) { +monitor_printf(mon, "base-memory: %" PRIu64 "\n", + info->base_memory); +monitor_printf(mon, "hot-plug-memory: %" PRIu64 "\n", + info->hot_plug_memory); +monitor_printf(mon, "ballooned-actual-memory: %" PRIu64 "\n", + info->ballooned_actual_memory); +g_free(info); +} +hmp_handle_error(mon, ); +} diff --git a/hmp.h b/hmp.h index d8b94ce9dc..c422aa2fac 100644 --- a/hmp.h +++ b/hmp.h @@ -143,5 +143,6 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict); void hmp_info_ramblock(Monitor *mon, const QDict *qdict); void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); +void hmp_info_memory(Monitor *mon, const QDict *qdict); #endif diff --git a/qapi-schema.json b/qapi-schema.json index 4b50b652d3..33cd7cb3b8 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4324,6 +4324,33 @@ 'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool', '*unavailable-features': [ 'str' ], 'typename': 'str' } } +## +# @MemoryInfo: +# +# Memory information in bytes. +# +# @base-memory: size of static memory which was specified on Qemu start. +# +# @hot-plug-memory: size of hot-plugged memory. +# +# @ballooned-actual-memory: amount of guest memory available after ballooning. +# +# Since: 2.10.0 +## +{ 'struct': 'MemoryInfo', + 'data' : { 'base-memory': 'int', 'hot-plug-memory': 'int', + 'ballooned-actual-memory': 'int' } } + +## +# @query-memory: +# +# Return memory size information which includes +# static, hotplugged and ballooned memory. +# +# Since: 2.10.0 +## +{ 'command': 'query-memory', 'returns': 'MemoryInfo' } + ## # @query-cpu-definitions: # diff --git a/qmp.c b/qmp.c index 7ee9bcfdcf..56b89ffbde 100644 --- a/qmp.c +++ b/qmp.c @@ -712,3 +712,39 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp) return head; } + +MemoryInfo *qmp_query_memory(Error **errp) +{ +MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo)); +BalloonInfo *balloon_info; +Error *local_err = NULL; + +mem_info->base_memory = ram_size; + +/* If current configuration