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 vasilis.liaskovitis@profitbricks.com --- hmp-commands.hx | 2 ++ hmp.c | 7 +++++++ hmp.h | 1 + hw/dimm.c | 21 +++++++++++++++++++++ hw/dimm.h | 1 + monitor.c | 7 +++++++ qapi-schema.json | 11 +++++++++++ qmp-commands.hx | 20 ++++++++++++++++++++ 8 files changed, 70 insertions(+), 0 deletions(-)
diff --git a/hmp-commands.hx b/hmp-commands.hx index cfb1b67..988d207 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1464,6 +1464,8 @@ show qdev device model list show roms @item info memory-hotplug show memory-hotplug +@item info memory-total +show memory-total @end table ETEXI
diff --git a/hmp.c b/hmp.c index 4b3d63d..cc31ddc 100644 --- a/hmp.c +++ b/hmp.c @@ -1185,3 +1185,10 @@ void hmp_info_memory_hotplug(Monitor *mon)
qapi_free_MemHpInfoList(info); } + +void hmp_info_memory_total(Monitor *mon) +{ + uint64_t ram_total; + ram_total = (uint64_t)qmp_query_memory_total(NULL); + monitor_printf(mon, "MemTotal: %lu \n", ram_total); +} diff --git a/hmp.h b/hmp.h index 986705a..ab96dba 100644 --- a/hmp.h +++ b/hmp.h @@ -74,5 +74,6 @@ void hmp_closefd(Monitor *mon, const QDict *qdict); void hmp_send_key(Monitor *mon, const QDict *qdict); void hmp_screen_dump(Monitor *mon, const QDict *qdict); void hmp_info_memory_hotplug(Monitor *mon); +void hmp_info_memory_total(Monitor *mon);
#endif diff --git a/hw/dimm.c b/hw/dimm.c index fbd93a8..21626f6 100644 --- a/hw/dimm.c +++ b/hw/dimm.c @@ -28,6 +28,7 @@ static DimmBus *main_memory_bus; /* the following list is used to hold dimm config info before machine * initialization. After machine init, the list is emptied and not used anymore.*/ static DimmConfiglist dimmconfig_list = QTAILQ_HEAD_INITIALIZER(dimmconfig_list); +extern ram_addr_t ram_size;
static void dimmbus_dev_print(Monitor *mon, DeviceState *dev, int indent); static char *dimmbus_get_fw_dev_path(DeviceState *dev); @@ -233,6 +234,26 @@ void setup_fwcfg_hp_dimms(uint64_t *fw_cfg_slots) } }
+uint64_t get_hp_memory_total(void) +{ + DimmBus *bus = main_memory_bus; + DimmDevice *slot; + uint64_t info = 0; + + QTAILQ_FOREACH(slot, &bus->dimmlist, nextdimm) { + info += slot->size; + } + return info; +} + +int64_t qmp_query_memory_total(Error **errp) +{ + uint64_t info; + info = ram_size + get_hp_memory_total(); + + return (int64_t)info; +} + void dimm_notify(uint32_t idx, uint32_t event) { DimmBus *bus = main_memory_bus; diff --git a/hw/dimm.h b/hw/dimm.h index 95251ba..21225be 100644 --- a/hw/dimm.h +++ b/hw/dimm.h @@ -86,5 +86,6 @@ int dimm_add(char *id); void main_memory_bus_create(Object *parent); void dimm_config_create(char *id, uint64_t size, uint64_t node, uint32_t dimm_idx, uint32_t populated); +uint64_t get_hp_memory_total(void);
#endif diff --git a/monitor.c b/monitor.c index be9a1d9..4f5ea60 100644 --- a/monitor.c +++ b/monitor.c @@ -2747,6 +2747,13 @@ static mon_cmd_t info_cmds[] = { .mhandler.info = hmp_info_memory_hotplug, }, { + .name = "memory-total", + .args_type = "", + .params = "", + .help = "show total memory size", + .mhandler.info = hmp_info_memory_total, + }, + { .name = NULL, }, }; diff --git a/qapi-schema.json b/qapi-schema.json index 3706a2a..c1d2571 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2581,3 +2581,14 @@ # Since: 1.3 ## { 'command': 'query-memory-hotplug', 'returns': ['MemHpInfo'] } + +## +# @query-memory-total: +# +# Returns total memory in bytes, including hotplugged dimms +# +# Returns: int +# +# Since: 1.3 +## +{ 'command': 'query-memory-total', 'returns': 'int' } diff --git a/qmp-commands.hx b/qmp-commands.hx index e50dcc2..20b7eea 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2576,3 +2576,23 @@ Example: }
EQMP + + { + .name = "query-memory-total", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_memory_total + }, +SQMP +query-memory-total +---------- + +Return total memory in bytes, including hotplugged dimms + +Example: + +-> { "execute": "query-memory-total" } +<- { + "return": 1073741824 + } + +EQMP