@@ -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
@@ -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);
+}
@@ -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
@@ -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;
@@ -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
@@ -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,
},
};
@@ -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' }
@@ -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
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(-)