From patchwork Fri Sep 21 11:17:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasilis Liaskovitis X-Patchwork-Id: 1491401 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id E71633FCFC for ; Fri, 21 Sep 2012 11:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933077Ab2IULSp (ORCPT ); Fri, 21 Sep 2012 07:18:45 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:64344 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933044Ab2IULRx (ORCPT ); Fri, 21 Sep 2012 07:17:53 -0400 Received: by mail-bk0-f46.google.com with SMTP id w11so743861bku.19 for ; Fri, 21 Sep 2012 04:17:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=pqrNX00RaU9SfMk33ab/ByLnSomIBWMyt7jGQrnPAE8=; b=EYt0zE5g3cfgeyi6xUdkMeE7jtO1hIH15mbzOm1vj/wOUGQxO4tgnKunUjcLNBj6ON 7PtIBMBTHPD2H1Phe5C/viixKxz2GaoAO+8qoPvHr5nFrEwK72SbXOunw8rHBl5G5emu zVxmhN8NWsP+1zm/J0UkxaQIxZzWKrqx4CHqfQMHa1gVArQixm3ChtcJQiZ5aQKKbg5+ YEUu7Vdlf1PpUk5Xy8Xmukr4WJHho8kKhpT3OVhtr1jDALgnpdNhROuLlzw4sEJcaFd8 HYjprGwPvELufZbhPllBY8blMsQGCIMFSqjOFPVx65tTXtM8GqBfDNpnalRiDjwDjIcB hzlA== Received: by 10.204.152.220 with SMTP id h28mr1977416bkw.30.1348226272924; Fri, 21 Sep 2012 04:17:52 -0700 (PDT) Received: from dhcp-192-168-178-175.ri.profitbricks.localdomain ([62.217.45.26]) by mx.google.com with ESMTPS id x13sm5271435bkv.16.2012.09.21.04.17.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Sep 2012 04:17:52 -0700 (PDT) From: Vasilis Liaskovitis To: qemu-devel@nongnu.org, kvm@vger.kernel.org, seabios@seabios.org Cc: avi@redhat.com, anthony@codemonkey.ws, kevin@koconnor.net, wency@cn.fujitsu.com, kraxel@redhat.com, eblake@redhat.com, blauwirbel@gmail.com, gleb@redhat.com, imammedo@redhat.com, Vasilis Liaskovitis Subject: [RFC PATCH v3 12/19] Implement "info memory-total" and "query-memory-total" Date: Fri, 21 Sep 2012 13:17:28 +0200 Message-Id: <1348226255-4226-13-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1348226255-4226-1-git-send-email-vasilis.liaskovitis@profitbricks.com> References: <1348226255-4226-1-git-send-email-vasilis.liaskovitis@profitbricks.com> X-Gm-Message-State: ALoCoQkGRAflfN0/ALlMGmPtyDl4g2Ymw61Ej5KgDlt/Qh/n44CBPLTCLeDZisIPU7gKXuBZBp6M Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 Reviewed-by: Eric Blake --- 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