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: 185721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 15FF32C007C for ; Fri, 21 Sep 2012 21:59:45 +1000 (EST) Received: from localhost ([::1]:50572 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF1GK-0002WP-7Y for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2012 07:19:12 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF1F9-0000CO-HR for qemu-devel@nongnu.org; Fri, 21 Sep 2012 07:18:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TF1F3-0003wc-Mt for qemu-devel@nongnu.org; Fri, 21 Sep 2012 07:17:59 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:58755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF1F3-0003rI-Fv for qemu-devel@nongnu.org; Fri, 21 Sep 2012 07:17:53 -0400 Received: by mail-bk0-f45.google.com with SMTP id jg9so1317042bkc.4 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=bbifHnpA3XqL9jahU/tzxjBRkzSNiQSiO3DR1JtAbZknvHEe2bNkY+ATUuOWHex1kA RtOdmRELE8d3niTAJjnytmD4MQVOe8IMxLztbPJZILKzFHcHhWRyuU/hs0TNMXr8gthA qZT1LsLjELpr/4j5mCZABv5mpXQyKPA0/wq/KcL7oYhqR+ZxSRGToyFYrtBqfdCi7tGx fxI4/jGRX1MfUSXtqJMvKVzgxtQ0e2qCj8nk++KuL6K6CyBKMWShOUqFepOEpewLYnGy 1wkTcHSwmsLeImT4b/KlV0QWfJwzDnRncGUySghFzzrHHNvLTIBA0eIyO7X3g5g3Sfil rJAA== 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 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: ALoCoQmMJDIfHJVZmlgy7Lb5zGG63ozYmW7trqDh3E33yX1OiGSobRL3FY8Hpzsil7U7QMNVT9+2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.45 Cc: Vasilis Liaskovitis , gleb@redhat.com, blauwirbel@gmail.com, kevin@koconnor.net, avi@redhat.com, anthony@codemonkey.ws, imammedo@redhat.com, eblake@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [RFC PATCH v3 12/19] Implement "info memory-total" and "query-memory-total" 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 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