From patchwork Wed Jun 26 09:13:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 254644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D65B62C0090 for ; Wed, 26 Jun 2013 19:21:58 +1000 (EST) Received: from localhost ([::1]:52439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrlvI-0007qU-V3 for incoming@patchwork.ozlabs.org; Wed, 26 Jun 2013 05:21:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrloP-00051p-IJ for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:14:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrloM-0002aA-II for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:14:49 -0400 Received: from [222.73.24.84] (port=12697 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrloL-0002Y0-O2 for qemu-devel@nongnu.org; Wed, 26 Jun 2013 05:14:46 -0400 X-IronPort-AV: E=Sophos;i="4.87,943,1363104000"; d="scan'208";a="7688755" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Jun 2013 17:11:38 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r5Q9EUvL020395; Wed, 26 Jun 2013 17:14:33 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com ([10.167.233.156]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013062617131716-2496137 ; Wed, 26 Jun 2013 17:13:17 +0800 From: Hu Tao To: qemu-devel@nongnu.org Date: Wed, 26 Jun 2013 17:13:35 +0800 Message-Id: <28e0075bf7190eeb560b6f5fadc139c54710ea3b.1372234719.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/26 17:13:17, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/06/26 17:13:17, Serialize complete at 2013/06/26 17:13:17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Vasilis Liaskovitis Subject: [Qemu-devel] [PATCH v5 12/14] Implement "info memory" and "query-memory" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Vasilis Liaskovitis 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 Signed-off-by: Hu Tao --- 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 +@item 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 */