From nobody Wed Nov 5 13:50:18 2025 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 149745376560448.14819066651887; Wed, 14 Jun 2017 08:22:45 -0700 (PDT) Received: from localhost ([::1]:49573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLA83-0000vd-8g for importer@patchew.org; Wed, 14 Jun 2017 11:22:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dLA6o-0008W4-7f for qemu-devel@nongnu.org; Wed, 14 Jun 2017 11:21:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dLA6k-0008Bc-Vg for qemu-devel@nongnu.org; Wed, 14 Jun 2017 11:21:26 -0400 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]:32800) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dLA6k-0008BM-M9 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 11:21:22 -0400 Received: by mail-wr0-x22d.google.com with SMTP id r103so2909914wrb.0 for ; Wed, 14 Jun 2017 08:21:22 -0700 (PDT) Received: from debian-jessie.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id q98sm391571wrb.3.2017.06.14.08.21.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Jun 2017 08:21:20 -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; bh=JvV3CkI5rGud+ME1cs4yvmUXf0hEs6o7t5mW6LCJ+KI=; b=VUb95q024haUXWDCbfRnjthu1AjH+viKYEhkim9FDXGhFhOMPRF1hBQcyjFl4fRQRX L1WJo9o+vB6ORfFuKS2IbxtnhqAPW/sHWi4Lopr4h2Pnatw5T3hjnSA746WDxbjkMZUP iUoWlp+DSbmRNnxsBvlp9vHwg9rjmLJ/LausHVog7IlCacWmVG9hwjVLbAnevfezekXg evtzT1XC8sO0rGjC+9YO+CZTO+266KM0/bGYhLrdRoGtgfGKKdK7BmAkY8bcr1NXojDK AmAuq8yJMmTY4dWM6ntZvXMFouNPvfAHnM6suAU/8HcDrqAPSwhndY/qwPm4wKLEaieh qCQA== 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; bh=JvV3CkI5rGud+ME1cs4yvmUXf0hEs6o7t5mW6LCJ+KI=; b=TS4zxbwQrWbSosIkjC7RQFTke3x5e8Hk6BK39mvlI+Ra3HgGCULF32KbYoTtBZNW6R BeYIihWcxEunTGi5DNxxfOjX+vjP52hcNzjaEGEDjzfBDmqRcuI357XupnRPZq3lZGej 0pPwQgVkBEKtUK54wCsmRvbUzzSbnIHImH2+N64tkFFmf7VYLI3iQpQknqiTOyIOs0Iv 7m0EhU+8Eat2d8wpjcB6Z519RCzCz7wwkrwdN/kmF+yPEhYEp6mSYJ0+mX5KhbjofLIf qKBcNGWZ9GOXcG9vkh6ON3FleYIMc0km61o59FB1+E4VVKq/HMDR2SCvDpu+VLCigwRy Qzvw== X-Gm-Message-State: AKS2vOwl2/9wZ98NpSDGyXXaZtiBaT+Z0WC/qTAbetoHX00sBixSsqYX CkOUs6GQPc2rq1cM X-Received: by 10.223.163.208 with SMTP id m16mr427102wrb.61.1497453681629; Wed, 14 Jun 2017 08:21:21 -0700 (PDT) From: Vadim Galitsyn To: Date: Wed, 14 Jun 2017 17:21:06 +0200 Message-Id: <20170614152106.25533-1-vadim.galitsyn@profitbricks.com> X-Mailer: git-send-email 2.13.1.394.g41dd433 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 v3] hmp, qmp: introduce "info memory" and "query-memory" 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: Mohammed Gamal , Vadim Galitsyn , qemu-devel@nongnu.org, Markus Armbruster , "Dr . David Alan Gilbert" , Vasilis Liaskovitis , Eduardo Otubo 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 static memory specified with '-m' option at the start of the QEMU process. * hot-plug-memory - amount of memory that was hot-plugged. * ballooned-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, zero value is reported. NOTE: Parameter @ballooned-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: qemu-devel@nongnu.org --- 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 | 15 +++++++++++++++ hmp.c | 16 ++++++++++++++++ hmp.h | 1 + qapi-schema.json | 27 +++++++++++++++++++++++++++ qmp.c | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index ae169011b1..bc37525550 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -833,6 +833,21 @@ STEXI @end table ETEXI =20 +STEXI +@item info memory +@findex memory +Display total memory size in bytes (static, hotplugged, ballooned) +ETEXI + + { + .name =3D "memory", + .args_type =3D "", + .params =3D "", + .help =3D "show memory size information in bytes (static, " + "hotplugged, ballooned)", + .cmd =3D hmp_info_memory, + }, + STEXI @end table ETEXI diff --git a/hmp.c b/hmp.c index 8c72c58b20..d6ec686376 100644 --- a/hmp.c +++ b/hmp.c @@ -2817,3 +2817,19 @@ 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(Monitor *mon, const QDict *qdict) +{ + Error *err =3D NULL; + MemoryInfo *info =3D qmp_query_memory(&err); + if (info) { + monitor_printf(mon, "base-memory: %" PRIu64 "\n", + info->base_memory); + monitor_printf(mon, "hot-plug-memory: %" PRIu64 "\n", + info->hot_plug_memory); + monitor_printf(mon, "ballooned-actual-memory: %" PRIu64 "\n", + info->ballooned_actual_memory); + g_free(info); + } + hmp_handle_error(mon, &err); +} diff --git a/hmp.h b/hmp.h index d8b94ce9dc..c422aa2fac 100644 --- a/hmp.h +++ b/hmp.h @@ -143,5 +143,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(Monitor *mon, const QDict *qdict); =20 #endif diff --git a/qapi-schema.json b/qapi-schema.json index 4b50b652d3..33cd7cb3b8 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4324,6 +4324,33 @@ 'data': { 'name': 'str', '*migration-safe': 'bool', 'static': 'bool', '*unavailable-features': [ 'str' ], 'typename': 'str' } } =20 +## +# @MemoryInfo: +# +# Memory information in bytes. +# +# @base-memory: size of static memory which was specified on Qemu start. +# +# @hot-plug-memory: size of hot-plugged memory. +# +# @ballooned-actual-memory: amount of guest memory available after balloon= ing. +# +# Since: 2.10.0 +## +{ 'struct': 'MemoryInfo', + 'data' : { 'base-memory': 'int', 'hot-plug-memory': 'int', + 'ballooned-actual-memory': 'int' } } + +## +# @query-memory: +# +# Return memory size information which includes +# static, hotplugged and ballooned memory. +# +# Since: 2.10.0 +## +{ 'command': 'query-memory', 'returns': 'MemoryInfo' } + ## # @query-cpu-definitions: # diff --git a/qmp.c b/qmp.c index 7ee9bcfdcf..56b89ffbde 100644 --- a/qmp.c +++ b/qmp.c @@ -712,3 +712,39 @@ ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **er= rp) =20 return head; } + +MemoryInfo *qmp_query_memory(Error **errp) +{ + MemoryInfo *mem_info =3D g_malloc0(sizeof(MemoryInfo)); + BalloonInfo *balloon_info; + Error *local_err =3D NULL; + + mem_info->base_memory =3D ram_size; + + /* If current configuration does not have CONFIG_MEM_HOTPLUG + * enabled, report zero hot-plugged memory. + */ +#ifdef CONFIG_MEM_HOTPLUG + mem_info->hot_plug_memory =3D pc_existing_dimms_capacity(&local_err); + if (local_err) { + error_setg(errp, "could not get hot-plug memory info: %s", + error_get_pretty(local_err)); + g_free(mem_info); + return NULL; + } +#else + mem_info->hot_plug_memory =3D 0; +#endif + /* 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->ballooned_actual_memory =3D 0; + error_free(local_err); + } else { + mem_info->ballooned_actual_memory =3D balloon_info->actual; + } + + qapi_free_BalloonInfo(balloon_info); + + return mem_info; +} --=20 2.13.1.394.g41dd433