diff mbox

[RFC,v2,19/21] Implement "info memtotal" and "query-memtotal"

Message ID 1342002726-18258-20-git-send-email-vasilis.liaskovitis@profitbricks.com
State New
Headers show

Commit Message

Vasilis Liaskovitis July 11, 2012, 10:32 a.m. UTC
Returns total memory of guest in bytes, including hotplugged memory.

Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
---
 hmp-commands.hx  |    2 ++
 hmp.c            |    7 +++++++
 hmp.h            |    1 +
 hw/dimm.c        |   15 +++++++++++++++
 monitor.c        |    7 +++++++
 qapi-schema.json |   12 ++++++++++++
 qmp-commands.hx  |   20 ++++++++++++++++++++
 7 files changed, 64 insertions(+), 0 deletions(-)

Comments

Eric Blake July 11, 2012, 3:14 p.m. UTC | #1
On 07/11/2012 04:32 AM, Vasilis Liaskovitis wrote:
> Returns total memory of guest in bytes, including hotplugged memory.
> 
> Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>

Should this instead be merged with query-balloon output, so that we have
a single command that shows all aspects of memory usage (both balloon
and hotplug at once)?


> @@ -1888,3 +1888,15 @@
>  # Since: 1.1.3
>  ##
>  { 'command': 'query-memhp', 'returns': ['MemHpInfo'] }
> +
> +##
> +# @query-memtotal:

A more generic name might be 'query-memory', especially if we merge
balloon and hotplug information into one command.

> +#
> +# Returns total memory in bytes, including hotplugged dimms
> +#
> +# Returns: a l

truncated
Vasilis Liaskovitis July 11, 2012, 4:55 p.m. UTC | #2
Hi,

On Wed, Jul 11, 2012 at 09:14:29AM -0600, Eric Blake wrote:
> On 07/11/2012 04:32 AM, Vasilis Liaskovitis wrote:
> > Returns total memory of guest in bytes, including hotplugged memory.
> > 
> > Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
> 
> Should this instead be merged with query-balloon output, so that we have
> a single command that shows all aspects of memory usage (both balloon
> and hotplug at once)?
> 
> 
> > @@ -1888,3 +1888,15 @@
> >  # Since: 1.1.3
> >  ##
> >  { 'command': 'query-memhp', 'returns': ['MemHpInfo'] }
> > +
> > +##
> > +# @query-memtotal:
> 
> A more generic name might be 'query-memory', especially if we merge
> balloon and hotplug information into one command.

"query-memory" sounds reasonable to me.

"query-balloon" should also be updated to show the correct memory. 
Do you foresee any issues with merging them?  the "query-memory" command
should work independently of the balloon driver.

> > +#
> > +# Returns total memory in bytes, including hotplugged dimms
> > +#
> > +# Returns: a l
> 
> truncated

sorry about that.

thanks,

- Vasilis

> 
> -- 
> Eric Blake   eblake@redhat.com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
> 
> 
>
diff mbox

Patch

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 3172cde..016062e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1461,6 +1461,8 @@  show qdev device model list
 show roms
 @item info memhp
 show memhp
+@item info memtotal
+show memtotal
 @end table
 ETEXI
 
diff --git a/hmp.c b/hmp.c
index ec25d9a..8f89c7d 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1017,3 +1017,10 @@  void hmp_info_memhp(Monitor *mon)
 
     qapi_free_MemHpInfoList(info);
 }
+
+void hmp_info_memtotal(Monitor *mon)
+{
+    uint64_t ram_total;
+    ram_total = (uint64_t)qmp_query_memtotal(NULL);
+    monitor_printf(mon, "MemTotal: %lu \n", ram_total);
+}
diff --git a/hmp.h b/hmp.h
index 971e7c4..d6e715e 100644
--- a/hmp.h
+++ b/hmp.h
@@ -65,5 +65,6 @@  void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
 void hmp_netdev_add(Monitor *mon, const QDict *qdict);
 void hmp_netdev_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memhp(Monitor *mon);
+void hmp_info_memtotal(Monitor *mon);
 
 #endif
diff --git a/hw/dimm.c b/hw/dimm.c
index 6e324d3..b544173 100644
--- a/hw/dimm.c
+++ b/hw/dimm.c
@@ -28,6 +28,7 @@  static dimm_hotplug_fn dimm_hotplug;
 static dimm_hotplug_fn dimm_revert;
 static QTAILQ_HEAD(Dimmlist, DimmState)  dimmlist;
 static QTAILQ_HEAD(dimm_hp_result_head, dimm_hp_result)  dimm_hp_result_queue;
+extern ram_addr_t ram_size;
 
 static Property dimm_properties[] = {
     DEFINE_PROP_END_OF_LIST()
@@ -292,6 +293,20 @@  MemHpInfoList *qmp_query_memhp(Error **errp)
 
     return head;
 }
+
+int64_t qmp_query_memtotal(Error **errp)
+{
+    DimmState *slot;
+    uint64_t info = ram_size;
+
+    QTAILQ_FOREACH(slot, &dimmlist, nextdimm) {
+        if (slot->populated) {
+            info += slot->size;
+        }
+    }
+    return (int64_t)info;
+}
+
 static int dimm_init(SysBusDevice *s)
 {
     DimmState *slot;
diff --git a/monitor.c b/monitor.c
index 4a14e26..1dd646c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2739,6 +2739,13 @@  static mon_cmd_t info_cmds[] = {
         .mhandler.info = hmp_info_memhp,
     },
     {
+        .name       = "memtotal",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show total memory size",
+        .mhandler.info = hmp_info_memtotal,
+    },
+    {
         .name       = NULL,
     },
 };
diff --git a/qapi-schema.json b/qapi-schema.json
index 049f6f9..5bbf2c0 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1888,3 +1888,15 @@ 
 # Since: 1.1.3
 ##
 { 'command': 'query-memhp', 'returns': ['MemHpInfo'] }
+
+##
+# @query-memtotal:
+#
+# Returns total memory in bytes, including hotplugged dimms
+#
+# Returns: a l
+#
+# Since: 1.2
+##
+{ 'command': 'query-memtotal', 'returns': 'int' }
+
diff --git a/qmp-commands.hx b/qmp-commands.hx
index cd1d5f0..6c71696 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2286,3 +2286,23 @@  Example:
    }
 
 EQMP
+
+    {
+        .name       = "query-memtotal",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_memtotal
+    },
+SQMP
+query-memtotal
+----------
+
+Return total memory in bytes, including hotplugged dimms
+
+Example:
+
+-> { "execute": "query-memtotal" }
+<- {
+      "return": 1073741824
+   }
+
+EQMP