qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v5 12/14] Implement "info memory" and "query-memory"


From: Hu Tao
Subject: [Qemu-devel] [PATCH v5 12/14] Implement "info memory" and "query-memory"
Date: Wed, 26 Jun 2013 17:13:35 +0800

From: Vasilis Liaskovitis <address@hidden>

Returns total physical memory available to guest in bytes, including hotplugged
memory. Note that the number reported here may be different from what the guest
sees e.g. if the guest has not logically onlined hotplugged memory.

This functionality is provided independently of a balloon device, since a
guest can be using ACPI memory hotplug without using a balloon device.

Signed-off-by: Vasilis Liaskovitis <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
---
 hmp-commands.hx               |  2 ++
 hmp.c                         |  8 ++++++++
 hmp.h                         |  1 +
 hw/mem-hotplug/dimm.c         | 14 ++++++++++++++
 include/hw/mem-hotplug/dimm.h |  1 +
 monitor.c                     |  7 +++++++
 qapi-schema.json              | 13 +++++++++++++
 qmp-commands.hx               | 22 ++++++++++++++++++++++
 vl.c                          |  9 +++++++++
 9 files changed, 77 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 915b0d1..b2937c2 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1653,6 +1653,8 @@ show device tree
 show qdev device model list
 @item info roms
 show roms
address@hidden info memory-total
+show memory-total
 @item info tpm
 show the TPM device
 @end table
diff --git a/hmp.c b/hmp.c
index 494a9aa..0371da9 100644
--- a/hmp.c
+++ b/hmp.c
@@ -675,6 +675,14 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)
     qapi_free_TPMInfoList(info_list);
 }
 
+void hmp_info_memory(Monitor *mon, const QDict *qdict)
+{
+    MemoryInfo *mem;
+    mem = qmp_query_memory(NULL);
+    monitor_printf(mon, "MemTotal: %" PRIu64 "\n", mem->total);
+    qapi_free_MemoryInfo(mem);
+}
+
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
     monitor_suspend(mon);
diff --git a/hmp.h b/hmp.h
index 56d2e92..b5a5afb 100644
--- a/hmp.h
+++ b/hmp.h
@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_tpm(Monitor *mon, const QDict *qdict);
+void hmp_info_memory(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
diff --git a/hw/mem-hotplug/dimm.c b/hw/mem-hotplug/dimm.c
index 09cfc4b..da31a18 100644
--- a/hw/mem-hotplug/dimm.c
+++ b/hw/mem-hotplug/dimm.c
@@ -185,6 +185,20 @@ void dimm_setup_fwcfg_layout(uint64_t *fw_cfg_slots)
     }
 }
 
+uint64_t get_hp_memory_total(void)
+{
+    DimmBus *bus;
+    DimmDevice *slot;
+    uint64_t info = 0;
+
+    QLIST_FOREACH(bus, &memory_buses, next) {
+        QTAILQ_FOREACH(slot, &bus->dimmlist, nextdimm) {
+            info += slot->size;
+        }
+    }
+    return info;
+}
+
 static void dimm_realize(DeviceState *s, Error **errp)
 {
     DimmBus *bus = DIMM_BUS(qdev_get_parent_bus(s));
diff --git a/include/hw/mem-hotplug/dimm.h b/include/hw/mem-hotplug/dimm.h
index 8625ae6..3947539 100644
--- a/include/hw/mem-hotplug/dimm.h
+++ b/include/hw/mem-hotplug/dimm.h
@@ -73,5 +73,6 @@ DimmBus *dimm_bus_create(Object *parent, const char *name, 
uint32_t max_dimms,
     dimm_calcoffset_fn pmc_set_offset);
 void dimm_config_create(char *id, uint64_t size, const char *bus, uint64_t 
node,
         uint32_t dimm_idx);
+uint64_t get_hp_memory_total(void);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 70ae8f5..14a955e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2760,6 +2760,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_tpm,
     },
     {
+        .name       = "memory",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory informations including total memory size",
+        .mhandler.cmd = hmp_info_memory,
+    },
+    {
         .name       = NULL,
     },
 };
diff --git a/qapi-schema.json b/qapi-schema.json
index a80ee40..d2940dc 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3608,3 +3608,16 @@
             '*cpuid-input-ecx': 'int',
             'cpuid-register': 'X86CPURegister32',
             'features': 'int' } }
+
+##
+# @query-memory:
+#
+# Returns total memory in bytes, including hotplugged dimms
+#
+# Returns: int
+#
+# Since: 1.6
+##
+{ 'type': 'MemoryInfo',
+  'data': { 'total': 'int' } }
+{ 'command': 'query-memory', 'returns': 'MemoryInfo' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8cea5e5..58d7c7c 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2997,3 +2997,25 @@ Example:
 <- { "return": {} }
 
 EQMP
+
+    {
+        .name       = "query-memory",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_memory
+    },
+SQMP
+query-memory
+----------
+
+Return a json-object with the following information:
+
+- "total": total memory in bytes, including hotplugged dimms
+
+Example:
+
+-> { "execute": "query-memory" }
+<- {
+      "return": { "total": 1073741824 }
+   }
+
+EQMP
diff --git a/vl.c b/vl.c
index 9d88a79..8d2b129 100644
--- a/vl.c
+++ b/vl.c
@@ -671,6 +671,15 @@ StatusInfo *qmp_query_status(Error **errp)
     return info;
 }
 
+MemoryInfo *qmp_query_memory(Error **errp)
+{
+    MemoryInfo *info = g_malloc0(sizeof(*info));
+
+    info->total = ram_size + get_hp_memory_total();
+
+    return info;
+}
+
 /***********************************************************/
 /* real time host monotonic timer */
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]