diff mbox

[v6,2/3] qmp: introduce query-memory-size-summary command

Message ID 1502881586-25044-2-git-send-email-vadim.galitsyn@profitbricks.com
State New
Headers show

Commit Message

Vadim Galitsyn Aug. 16, 2017, 11:06 a.m. UTC
Command above provides the following memory information in bytes:

  * base-memory - size of "base" memory specified with command line option -m.

  * plugged-memory - amount of memory that was hot-plugged.
    If target does not have CONFIG_MEM_HOTPLUG enabled, no
    value is reported.

Signed-off-by: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
Signed-off-by: Mohammed Gamal <mohammed.gamal@profitbricks.com>
Signed-off-by: Eduardo Otubo <eduardo.otubo@profitbricks.com>
Signed-off-by: Vadim Galitsyn <vadim.galitsyn@profitbricks.com>
Reviewed-by: Eugene Crosser <evgenii.cherkashin@profitbricks.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/mem/pc-dimm.c                |  5 +++++
 include/hw/mem/pc-dimm.h        |  1 +
 qapi-schema.json                | 25 +++++++++++++++++++++++++
 qmp.c                           | 13 +++++++++++++
 stubs/Makefile.objs             |  2 +-
 stubs/qmp_pc_dimm.c             | 13 +++++++++++++
 stubs/qmp_pc_dimm_device_list.c |  8 --------
 7 files changed, 58 insertions(+), 9 deletions(-)
 create mode 100644 stubs/qmp_pc_dimm.c
 delete mode 100644 stubs/qmp_pc_dimm_device_list.c

Comments

Eric Blake Aug. 16, 2017, 12:10 p.m. UTC | #1
On 08/16/2017 06:06 AM, Vadim Galitsyn wrote:
> Command above provides the following memory information in bytes:

My general preference for reading a commit message is to treat the
subject line as a one-line summary (the what), and then the commit
message body as something that can be read independently, starting with
an implicit "Apply this patch to...".  Your sentence reads awkwardly in
that light ("Apply this patch to command above provides...").  Better
might be:

Add a new query-memory-size-summary command which provides...

Yes, it repeats some of the subject line, but remember, not all mail
clients display the subject line immediately adjacent and in the same
font as the body, so making the reader refer back to the subject to get
context can be a distraction.

> 
>   * base-memory - size of "base" memory specified with command line option -m.
> 
>   * plugged-memory - amount of memory that was hot-plugged.
>     If target does not have CONFIG_MEM_HOTPLUG enabled, no
>     value is reported.
> 

> ---
>  hw/mem/pc-dimm.c                |  5 +++++
>  include/hw/mem/pc-dimm.h        |  1 +
>  qapi-schema.json                | 25 +++++++++++++++++++++++++
>  qmp.c                           | 13 +++++++++++++
>  stubs/Makefile.objs             |  2 +-
>  stubs/qmp_pc_dimm.c             | 13 +++++++++++++
>  stubs/qmp_pc_dimm_device_list.c |  8 --------
>  7 files changed, 58 insertions(+), 9 deletions(-)

You may want to look at using scripts/git.orderfile, to rearrange your
patch so that interface changes (.json, .h) occur before implementation
(.c).  For now, I'm just focusing on the interface:

> +++ b/qapi-schema.json
> @@ -4408,6 +4408,31 @@
>              '*unavailable-features': [ 'str' ], 'typename': 'str' } }
>  
>  ##
> +# @MemoryInfo:
> +#
> +# Actual memory information in bytes.
> +#
> +# @base-memory: size of "base" memory specified with command line
> +#               option -m.
> +#
> +# @plugged-memory: size memory that can be hot-unplugged.

Please also document when this field will be omitted.

> +#
> +# Since: 2.10.0

You missed 2.10.  This must be 2.11.

> +##
> +{ 'struct': 'MemoryInfo',
> +  'data'  : { 'base-memory': 'size', '*plugged-memory': 'size' } }
> +
> +##
> +# @query-memory-size-summary:
> +#
> +# Return the amount of initially allocated and hot-plugged (if
> +# enabled) memory in bytes.
> +#
> +# Since: 2.10.0

2.11

Also, consider including an example usage (there are efforts underway to
add automatic testing based on the examples, and a query-* command
should be easy to test in that manner).

> +##
> +{ 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' }
> +
> +##
>  # @query-cpu-definitions:
>  #
diff mbox

Patch

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index ea67b46..6ef2ccd 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -159,6 +159,11 @@  uint64_t pc_existing_dimms_capacity(Error **errp)
     return cap.size;
 }
 
+uint64_t get_plugged_memory_size(void)
+{
+    return pc_existing_dimms_capacity(&error_abort);
+}
+
 int qmp_pc_dimm_device_list(Object *obj, void *opaque)
 {
     MemoryDeviceInfoList ***prev = opaque;
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 1e483f2..a56f901 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);
 
 int qmp_pc_dimm_device_list(Object *obj, void *opaque);
 uint64_t pc_existing_dimms_capacity(Error **errp);
+uint64_t get_plugged_memory_size(void);
 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 802ea53..23916b7 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4408,6 +4408,31 @@ 
             '*unavailable-features': [ 'str' ], 'typename': 'str' } }
 
 ##
+# @MemoryInfo:
+#
+# Actual memory information in bytes.
+#
+# @base-memory: size of "base" memory specified with command line
+#               option -m.
+#
+# @plugged-memory: size memory that can be hot-unplugged.
+#
+# Since: 2.10.0
+##
+{ 'struct': 'MemoryInfo',
+  'data'  : { 'base-memory': 'size', '*plugged-memory': 'size' } }
+
+##
+# @query-memory-size-summary:
+#
+# Return the amount of initially allocated and hot-plugged (if
+# enabled) memory in bytes.
+#
+# Since: 2.10.0
+##
+{ 'command': 'query-memory-size-summary', 'returns': 'MemoryInfo' }
+
+##
 # @query-cpu-definitions:
 #
 # Return a list of supported virtual CPU definitions
diff --git a/qmp.c b/qmp.c
index b86201e..e8c3031 100644
--- a/qmp.c
+++ b/qmp.c
@@ -709,3 +709,16 @@  ACPIOSTInfoList *qmp_query_acpi_ospm_status(Error **errp)
 
     return head;
 }
+
+MemoryInfo *qmp_query_memory_size_summary(Error **errp)
+{
+    MemoryInfo *mem_info = g_malloc0(sizeof(MemoryInfo));
+
+    mem_info->base_memory = ram_size;
+
+    mem_info->plugged_memory = get_plugged_memory_size();
+    mem_info->has_plugged_memory =
+        mem_info->plugged_memory != (uint64_t)-1;
+
+    return mem_info;
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index f5b47bf..f7cab5b 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -32,7 +32,7 @@  stub-obj-y += uuid.o
 stub-obj-y += vm-stop.o
 stub-obj-y += vmstate.o
 stub-obj-$(CONFIG_WIN32) += fd-register.o
-stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += qmp_pc_dimm.o
 stub-obj-y += target-monitor-defs.o
 stub-obj-y += target-get-monitor-def.o
 stub-obj-y += pc_madt_cpu_entry.o
diff --git a/stubs/qmp_pc_dimm.c b/stubs/qmp_pc_dimm.c
new file mode 100644
index 0000000..9ddc4f6
--- /dev/null
+++ b/stubs/qmp_pc_dimm.c
@@ -0,0 +1,13 @@ 
+#include "qemu/osdep.h"
+#include "qom/object.h"
+#include "hw/mem/pc-dimm.h"
+
+int qmp_pc_dimm_device_list(Object *obj, void *opaque)
+{
+   return 0;
+}
+
+uint64_t get_plugged_memory_size(void)
+{
+    return (uint64_t)-1;
+}
diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_pc_dimm_device_list.c
deleted file mode 100644
index def2115..0000000
--- a/stubs/qmp_pc_dimm_device_list.c
+++ /dev/null
@@ -1,8 +0,0 @@ 
-#include "qemu/osdep.h"
-#include "qom/object.h"
-#include "hw/mem/pc-dimm.h"
-
-int qmp_pc_dimm_device_list(Object *obj, void *opaque)
-{
-   return 0;
-}