From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vasilis Liaskovitis Subject: [RFC PATCH v2 19/21] Implement "info memtotal" and "query-memtotal" Date: Wed, 11 Jul 2012 12:32:04 +0200 Message-ID: <1342002726-18258-20-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1342002726-18258-1-git-send-email-vasilis.liaskovitis@profitbricks.com> Cc: avi@redhat.com, anthony@codemonkey.ws, gleb@redhat.com, imammedo@redhat.com, kevin@koconnor.net, wency@cn.fujitsu.com, Vasilis Liaskovitis To: qemu-devel@nongnu.org, kvm@vger.kernel.org, seabios@seabios.org Return-path: Received: from mail-bk0-f46.google.com ([209.85.214.46]:40424 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757167Ab2GKKcZ (ORCPT ); Wed, 11 Jul 2012 06:32:25 -0400 Received: by mail-bk0-f46.google.com with SMTP id j10so891613bkw.19 for ; Wed, 11 Jul 2012 03:32:24 -0700 (PDT) In-Reply-To: <1342002726-18258-1-git-send-email-vasilis.liaskovitis@profitbricks.com> Sender: kvm-owner@vger.kernel.org List-ID: Returns total memory of guest in bytes, including hotplugged memory. Signed-off-by: Vasilis Liaskovitis --- 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(-) 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 -- 1.7.9 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SouDg-0003kO-TA for qemu-devel@nongnu.org; Wed, 11 Jul 2012 06:32:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SouDZ-0005uC-Ns for qemu-devel@nongnu.org; Wed, 11 Jul 2012 06:32:32 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:57641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SouDZ-0005nm-Hx for qemu-devel@nongnu.org; Wed, 11 Jul 2012 06:32:25 -0400 Received: by mail-bk0-f45.google.com with SMTP id ji1so712841bkc.4 for ; Wed, 11 Jul 2012 03:32:24 -0700 (PDT) From: Vasilis Liaskovitis Date: Wed, 11 Jul 2012 12:32:04 +0200 Message-Id: <1342002726-18258-20-git-send-email-vasilis.liaskovitis@profitbricks.com> In-Reply-To: <1342002726-18258-1-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1342002726-18258-1-git-send-email-vasilis.liaskovitis@profitbricks.com> Subject: [Qemu-devel] [RFC PATCH v2 19/21] Implement "info memtotal" and "query-memtotal" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvm@vger.kernel.org, seabios@seabios.org Cc: gleb@redhat.com, Vasilis Liaskovitis , kevin@koconnor.net, avi@redhat.com, anthony@codemonkey.ws, imammedo@redhat.com Returns total memory of guest in bytes, including hotplugged memory. Signed-off-by: Vasilis Liaskovitis --- 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(-) 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 -- 1.7.9