From nobody Thu May 2 11:04:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149882967159645.71862191426624; Fri, 30 Jun 2017 06:34:31 -0700 (PDT) Received: from localhost ([::1]:44579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQw43-0003Tb-WE for importer@patchew.org; Fri, 30 Jun 2017 09:34:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQw1o-000207-EF for qemu-devel@nongnu.org; Fri, 30 Jun 2017 09:32:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQw1i-00007C-3W for qemu-devel@nongnu.org; Fri, 30 Jun 2017 09:32:08 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:33070) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dQw1h-00005o-PS for qemu-devel@nongnu.org; Fri, 30 Jun 2017 09:32:02 -0400 Received: by mail-wr0-x22d.google.com with SMTP id r103so204569778wrb.0 for ; Fri, 30 Jun 2017 06:32:01 -0700 (PDT) Received: from debian-jessie.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id l8sm4495057wmd.15.2017.06.30.06.31.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jun 2017 06:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7bmqZUYJDLEqNvitSKHBd0p1taVi1HEDX+UprW93utQ=; b=lB/dSs/XnSMed4Ynwe4znjUXLZ5OiJYwezVtqXaMwfbYl/9iQUhxbHINFUi535lHdv BXM8HlVaUdIgpb9yapG42QoXhoG0cYXURqD76/qFeVodmB0AbegCyxCduk9u1+D1fNWq Dk0wUM37mZPtNSAGqQTkHBsfKNpnRcDZ/QQKTbv7+SyTOB7ukfG+4vQqof/JtbRS/cDo RFgL822qB8Es/XG6c4oYaLQz1mS37LO22BUci6oC6UTU6/8EwDXUl+w1Rvx589aw8p2x qfCPSSvz9sYOyVOpFs7ZXCBISvhErQ0LkmampA7BfRu+EjvcKULkqhFmO1Cqks+rcF5g N/7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7bmqZUYJDLEqNvitSKHBd0p1taVi1HEDX+UprW93utQ=; b=uL5QQ9CWoPaamRK6aeKNMU9Q+cPedRg0cxkYfbzi/wrTnzzK/84/y+8z4euhAAEOGi MKy/rbanp12sJ49OgDnSMldIPMZ3fMdkcpkFHGFgeZPXOlDHaekZZXqdhXQget45emeA djTq2YBmjKqzvWuKldjH2PiYVZXOS1Nu5/DYnv7ex1bUl5t3mBOYX4KQIb+7PAPq/cTH YXyHDXVkTL4Ff8Hcxm1p1d9uFqpUSsG6mleIjgpxlGpvZXzU8Oiox5l4GWuU7OfbfRrA 6iUmSza1UbnIKuWEUW9ga6jU9oGJFQor3h5v241AYvfhoJm7ymyrf2/yRDF2DzMY8xJh 9BIg== X-Gm-Message-State: AKS2vOz/qSSDMz4ELeKG1Wn7vlTjJRMDors6NX4fpd+fsxRox7OSSEdL 1qKYvQ3C2WLXGLYS X-Received: by 10.223.162.208 with SMTP id t16mr29798910wra.151.1498829520657; Fri, 30 Jun 2017 06:32:00 -0700 (PDT) From: Vadim Galitsyn To: Mohammed Gamal , "Dr . David Alan Gilbert" , Markus Armbruster , Igor Mammedov , Eric Blake , qemu-devel@nongnu.org Date: Fri, 30 Jun 2017 15:31:39 +0200 Message-Id: <20170630133139.7907-2-vadim.galitsyn@profitbricks.com> X-Mailer: git-send-email 2.13.1.394.g41dd433 In-Reply-To: <20170630133139.7907-1-vadim.galitsyn@profitbricks.com> References: <20170630133139.7907-1-vadim.galitsyn@profitbricks.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22d Subject: [Qemu-devel] [PATCH v4] hmp, qmp: introduce memory-size-summary commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vasilis Liaskovitis , Eduardo Otubo , Vadim Galitsyn Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Commands above provide the following memory information in bytes: * base-memory - amount of unremovable memory specified with '-m' option at the start of the QEMU process. * hotpluggable-memory - amount of memory that was hot-plugged. If target does not have CONFIG_MEM_HOTPLUG enabled, no value is reported. * balloon-actual-memory - size of the memory that remains available to the guest after ballooning, as reported by the guest. If the guest has not reported its memory, this value equals to @base-memory + @hot-plug-memory. If ballooning is not enabled, no value is reported. NOTE: Parameter @balloon-actual-memory reports the same as "info balloon" command when ballooning is enabled. The idea to have it in scope of this command(s) comes from https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01472.html. Signed-off-by: Vasilis Liaskovitis Signed-off-by: Mohammed Gamal Signed-off-by: Eduardo Otubo Signed-off-by: Vadim Galitsyn Reviewed-by: Eugene Crosser Cc: Dr. David Alan Gilbert Cc: Markus Armbruster Cc: Igor Mammedov Cc: Eric Blake Cc: qemu-devel@nongnu.org --- v4: * Commands "info memory" and "query-memory" were renamed to "info memory-size-summary" and "query-memory-size-summary" correspondingly. * Descriptions for both commands as well as MemoryInfo structure fields were updated/renamed according to http://lists.nongnu.org/archive/html/qemu-devel/2017-06/msg05972.html. * In MemoryInfo structure following fields are now optional: hotpluggable-memory and balloon-actual-memory. * Field "hotpluggable-memory" now not displayed in HMP if target has no CONFIG_MEM_HOTPLUG enabled. * Field "balloon-actual-memory" now not displayed in HMP if ballooning not enabled. * qapi_free_MemoryInfo() used in order to free corresponding memory instead of g_free(). * #ifdef CONFIG_MEM_HOTPLUG was removed and replaced with stubs/ approach. get_exiting_hotpluggable_memory_size() function was introduced in hw/mem/pc-dimm.c (available for all targets which have CONFIG_MEM_HOTPLUG enabled). For other targets, there is a stub in stubs/qmp_pc_dimm.c. In addition, stubs/qmp_pc_dimm_device_list.c was renamed to stubs/qmp_pc_dimm.c in order to reflect actual source file content. * Commit message was updated in order to reflect what was changed. v3: * Use PRIu64 instead of 'lu' when printing results via HMP. * Report zero hot-plugged memory instead of reporting error when target architecture has no CONFIG_MEM_HOTPLUG enabled. v2: * Fixed build for targets which do not have CONFIG_MEM_HOTPLUG enabled. hmp-commands-info.hx | 17 ++++++++++++ hmp.c | 23 ++++++++++++++++ hmp.h | 1 + hw/mem/pc-dimm.c | 6 +++++ include/hw/mem/pc-dimm.h | 1 + qapi-schema.json | 28 +++++++++++++++++++ qmp.c | 31 ++++++++++++++++++= ++++ stubs/Makefile.objs | 2 +- stubs/{qmp_pc_dimm_device_list.c =3D> qmp_pc_dimm.c} | 5 ++++ 9 files changed, 113 insertions(+), 1 deletion(-) rename stubs/{qmp_pc_dimm_device_list.c =3D> qmp_pc_dimm.c} (60%) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ba98e581ab..a535960157 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -829,6 +829,23 @@ ETEXI .cmd =3D hmp_info_vm_generation_id, }, =20 +STEXI +@item info memory-size-summary +@findex memory-size-summary +Display the amount of initially allocated, hot-plugged (if enabled) +and ballooned (if enabled) memory in bytes. +ETEXI + + { + .name =3D "memory-size-summary", + .args_type =3D "", + .params =3D "", + .help =3D "show the amount of initially allocated, " + "hot-plugged (if enabled) and ballooned (if enabled)= " + "memory in bytes.", + .cmd =3D hmp_info_memory_size_summary, + }, + STEXI @end table ETEXI diff --git a/hmp.c b/hmp.c index dee40284c1..15f632481c 100644 --- a/hmp.c +++ b/hmp.c @@ -2828,3 +2828,26 @@ void hmp_info_vm_generation_id(Monitor *mon, const Q= Dict *qdict) hmp_handle_error(mon, &err); qapi_free_GuidInfo(info); } + +void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + MemoryInfo *info =3D qmp_query_memory_size_summary(&err); + if (info) { + monitor_printf(mon, "base-memory: %" PRIu64 "\n", + info->base_memory); + + if (info->has_hotpluggable_memory) { + monitor_printf(mon, "hotpluggable-memory: %" PRIu64 "\n", + info->hotpluggable_memory); + } + + if (info->has_balloon_actual_memory) { + monitor_printf(mon, "balloon-actual-memory: %" PRIu64 "\n", + info->balloon_actual_memory); + } + + qapi_free_MemoryInfo(info); + } + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index 214b2617e7..8c5398ea7a 100644 --- a/hmp.h +++ b/hmp.h @@ -144,5 +144,6 @@ void hmp_info_dump(Monitor *mon, const QDict *qdict); void hmp_info_ramblock(Monitor *mon, const QDict *qdict); void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict); void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict); +void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index b72258e28f..ea81b1384a 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -159,6 +159,12 @@ uint64_t pc_existing_dimms_capacity(Error **errp) return cap.size; } =20 +bool get_exiting_hotpluggable_memory_size(uint64_t *mem_size, Error **errp) +{ + *mem_size =3D pc_existing_dimms_capacity(errp); + return true; +} + int qmp_pc_dimm_device_list(Object *obj, void *opaque) { MemoryDeviceInfoList ***prev =3D opaque; diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index 1e483f2670..738343df32 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -95,6 +95,7 @@ int pc_dimm_get_free_slot(const int *hint, int max_slots,= Error **errp); =20 int qmp_pc_dimm_device_list(Object *obj, void *opaque); uint64_t pc_existing_dimms_capacity(Error **errp); +bool get_exiting_hotpluggable_memory_size(uint64_t *mem_size, Error **errp= ); void pc_dimm_memory_plug(DeviceState *dev, MemoryHotplugState *hpms, MemoryRegion *mr, uint64_t align, Error **errp); void pc_dimm_memory_unplug(DeviceState *dev, MemoryHotplugState *hpms, diff --git a/qapi-schema.json b/qapi-schema.json index 37c4b95aad..683da8a711 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4327,6 +4327,34 @@ 'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool', '*unavailable-features': [ 'str' ], 'typename': 'str' } } =20 +## +# @MemoryInfo: +# +# Actual memory information in bytes. +# +# @base-memory: size of unremovable memory which is specified +# with '-m size' CLI option. +# +# @hotpluggable-memory: size of hot-plugged memory. +# +# @balloon-actual-memory: amount of guest memory available after balloonin= g. +# +# Since: 2.10.0 +## +{ 'struct': 'MemoryInfo', + 'data' : { 'base-memory': 'int', '*hotpluggable-memory': 'int', + '*balloon-actual-memory': 'int' } } + +## +# @query-memory-size-summary: +# +# Return the amount of initially allocated, hot-plugged (if enabled) +# and ballooned (if enabled) memory in bytes. +# +# Since: 2.10.0 +## +{ 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' } + ## # @query-cpu-definitions: # diff --git a/qmp.c b/qmp.c index 7ee9bcfdcf..a863726ad6 100644 --- a/qmp.c +++ b/qmp.c @@ -712,3 +712,34 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **er= rp) =20 return head; } + +MemoryInfo *qmp_query_memory_size_summary(Error **errp) +{ + MemoryInfo *mem_info =3D g_malloc0(sizeof(MemoryInfo)); + BalloonInfo *balloon_info; + uint64_t hotpluggable_memory =3D 0; + Error *local_err =3D NULL; + + mem_info->base_memory =3D ram_size; + + mem_info->has_hotpluggable_memory =3D + get_exiting_hotpluggable_memory_size(&hotpluggable_memory, + &error_abort); + if (mem_info->has_hotpluggable_memory) { + mem_info->hotpluggable_memory =3D hotpluggable_memory; + } + + /* In case if it is not possible to get balloon info, just ignore it. = */ + balloon_info =3D qmp_query_balloon(&local_err); + if (local_err) { + mem_info->has_balloon_actual_memory =3D false; + error_free(local_err); + } else { + mem_info->has_balloon_actual_memory =3D true; + mem_info->balloon_actual_memory =3D balloon_info->actual; + } + + qapi_free_BalloonInfo(balloon_info); + + return mem_info; +} diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index f5b47bfd74..f7cab5b11c 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -32,7 +32,7 @@ stub-obj-y +=3D uuid.o stub-obj-y +=3D vm-stop.o stub-obj-y +=3D vmstate.o stub-obj-$(CONFIG_WIN32) +=3D fd-register.o -stub-obj-y +=3D qmp_pc_dimm_device_list.o +stub-obj-y +=3D qmp_pc_dimm.o stub-obj-y +=3D target-monitor-defs.o stub-obj-y +=3D target-get-monitor-def.o stub-obj-y +=3D pc_madt_cpu_entry.o diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_pc_dimm.c similarity index 60% rename from stubs/qmp_pc_dimm_device_list.c rename to stubs/qmp_pc_dimm.c index def211564d..f50029326e 100644 --- a/stubs/qmp_pc_dimm_device_list.c +++ b/stubs/qmp_pc_dimm.c @@ -6,3 +6,8 @@ int qmp_pc_dimm_device_list(Object *obj, void *opaque) { return 0; } + +bool get_exiting_hotpluggable_memory_size(uint64_t *mem_size, Error **errp) +{ + return false; +} --=20 2.13.1.394.g41dd433