Skip to contentSkip to conversation

Deprecate QMP & HMP `cpu-add`; document vCPU hotplug

PATCH In review Kashyap Chamarthy 5 participants 16 messages Oct 30, 2018 – Dec 13, 2018

lore
Share & tools
lore
#0 lore raw

v3 cover Deprecate QMP & HMP `cpu-add`; document vCPU hotplug

The first patch deprecates the QMP cpu-add, the second its HMP equivalent, and the third documents vCPU hotplug procedure using QMP device_add et al.

v2: https://lists.gnu.org/archive/html/qemu-devel/2018-09/msg03191.html

Kashyap Chamarthy (3):
Deprecate QMP cpu-add
Deprecate HMP cpu-add
docs: Document vCPU hotplug procedure

 docs/cpu-hotplug.rst | 142 +++++++++++++++++++++++++++++++++++++++++++
 hmp-commands.hx      |   6 +-
 hmp.c                |   2 +
 qapi/misc.json       |   8 ++-
 qemu-deprecated.texi |   5 ++
 5 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 docs/cpu-hotplug.rst
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/3 Deprecate QMP `cpu-add`

The intended functionality of QMP cpu-add is replaced with device_add (and query-hotpluggable-cpus). So let's deprecate cpu-add.

A complete example of vCPU hotplug with the recommended way (using device_add) is provided as part of a seperate docs patch.

---

---
 qapi/misc.json       | 8 +++++++-
 qemu-deprecated.texi | 5 +++++
 2 files changed, 12 insertions(+), 1 deletion(-)
qapi/misc.json +7 -1
index d450cfef21..fbee1e6d34 100644
@@ -1104,7 +1104,7 @@
 ##
 # @cpu-add:
 #
-# Adds CPU with specified ID
+# Adds CPU with specified ID.
 #
 # @id: ID of CPU to be created, valid values [0..max_cpus)
 #
@@ -1112,6 +1112,10 @@
 #
 # Since: 1.5
 #
+# Note: This command is deprecated.  The `device_add` command should be
+#       used instead.  See the `query-hotpluggable-cpus` command for
+#       details.
+#
 # Example:
 #
 # -> { "execute": "cpu-add", "arguments": { "id": 2 } }
@@ -3213,6 +3217,8 @@
 ##
 # @query-hotpluggable-cpus:
 #
+# TODO: Better documentation; currently there is none.
+#
 # Returns: a list of HotpluggableCPU objects.
 #
 # Since: 2.7
qemu-deprecated.texi +5 -0
index 1b9c007f12..c86924ad9a 100644
@@ -155,6 +155,11 @@ The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command.
 The ``arch'' output member of the ``query-cpus-fast'' command is
 replaced by the ``target'' output member.
 
+@subsection cpu-add (since 3.1)
+
+Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
+documentation of ``query-hotpluggable-cpus'' for additional details.
+
 @section System emulator devices
 
 @subsection ivshmem (since 2.6.0)
Signature · 1 line
2.17.1
#6 lore raw

PATCH v3 2/3 Deprecate HMP `cpu-add`

In reply to Kashyap Chamarthy

Since we're deprecating the QMP cpu-add, let's deprecate its HMP equivalent, too.

---
 hmp-commands.hx | 6 ++++--
 hmp.c           | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
hmp-commands.hx +4 -2
index db0c681f74..ba71558c25 100644
@@ -1849,14 +1849,16 @@ ETEXI
         .name       = "cpu-add",
         .args_type  = "id:i",
         .params     = "id",
-        .help       = "add cpu",
+        .help       = "add cpu (deprecated, use device_add instead)",
         .cmd        = hmp_cpu_add,
     },
 
 STEXI
 @item cpu-add @var{id}
 @findex cpu-add
-Add CPU with id @var{id}
+Add CPU with id @var{id}.  This command is deprecated, please
++use @code{device_add} instead. For details, refer to
+'docs/cpu-hotplug.rst'.
 ETEXI
 
     {
hmp.c +2 -0
index 4975fa56b0..c3f3db7795 100644
@@ -2353,6 +2353,8 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
     int cpuid;
     Error *err = NULL;
 
+    error_report("cpu_add is deprecated, please use device_add instead");
+
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
     hmp_handle_error(mon, &err);
Signature · 1 line
2.17.1
#11 lore raw

PATCH v3 3/3 docs: Document vCPU hotplug procedure

In reply to Kashyap Chamarthy
---
 docs/cpu-hotplug.rst | 142 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 142 insertions(+)
 create mode 100644 docs/cpu-hotplug.rst
docs/cpu-hotplug.rst new file +142 -0
new file mode 100644
index 0000000000..1c268e00b4
@@ -0,0 +1,142 @@
+===================
+Virtual CPU hotplug
+===================
+
+A complete example of vCPU hotplug (and hot-unplug) using QMP
+``device_add`` and ``device_del``.
+
+vCPU hotplug
+------------
+
+(1) Launch QEMU as follows (note that the "maxcpus" is mandatory to
+    allow vCPU hotplug)::
+
+      $ qemu-system-x86_64 -display none -no-user-config -m 2048 \
+          -nodefaults -monitor stdio -machine pc,accel=kvm,usb=off \
+          -smp 1,maxcpus=2 -cpu IvyBridge-IBRS \
+          -qmp unix:/tmp/qmp-sock,server,nowait
+
+(2) Run 'qmp-shell' (located in the source tree, under: "scripts/qmp/)
+    to connect to the just-launched QEMU::
+
+      $> ./qmp-shell -p -v /tmp/qmp-sock
+      [...]
+      (QEMU)
+
+(3) Find out which CPU types could be plugged, and into which sockets::
+
+      (QEMU) query-hotpluggable-cpus
+      {
+          "execute": "query-hotpluggable-cpus",
+          "arguments": {}
+      }
+      {
+          "return": [
+              {
+                  "type": "IvyBridge-IBRS-x86_64-cpu",
+                  "vcpus-count": 1,
+                  "props": {
+                      "socket-id": 1,
+                      "core-id": 0,
+                      "thread-id": 0
+                  }
+              },
+              {
+                  "qom-path": "/machine/unattached/device[0]",
+                  "type": "IvyBridge-IBRS-x86_64-cpu",
+                  "vcpus-count": 1,
+                  "props": {
+                      "socket-id": 0,
+                      "core-id": 0,
+                      "thread-id": 0
+                  }
+              }
+          ]
+      }
+      (QEMU)
+
+(4) The ``query-hotpluggable-cpus`` command returns an object for CPUs
+    that are present (containing a "qom-path" member) or which may be
+    hot-plugged (no "qom-path" member).  From its output in step (3), we
+    can see that ``IvyBridge-IBRS-x86_64-cpu`` is present in socket 0,
+    while hot-plugging a CPU into socket 1 requires passing the listed
+    properties to QMP ``device_add``:
+
+      (QEMU) device_add id=cpu-2 driver=IvyBridge-IBRS-x86_64-cpu socket-id=1 core-id=0 thread-id=0
+      {
+          "execute": "device_add",
+          "arguments": {
+              "socket-id": 1,
+              "driver": "IvyBridge-IBRS-x86_64-cpu",
+              "id": "cpu-2",
+              "core-id": 0,
+              "thread-id": 0
+          }
+      }
+      {
+          "return": {}
+      }
+      (QEMU)
+
+(5) Optionally, run QMP `query-cpus-fast` for some details about the
+    vCPUs::
+
+      (QEMU) query-cpus-fast
+      {
+          "execute": "query-cpus-fast",
+          "arguments": {}
+      }
+      {
+          "return": [
+              {
+                  "qom-path": "/machine/unattached/device[0]",
+                  "target": "x86_64",
+                  "thread-id": 11534,
+                  "cpu-index": 0,
+                  "props": {
+                      "socket-id": 0,
+                      "core-id": 0,
+                      "thread-id": 0
+                  },
+                  "arch": "x86"
+              },
+              {
+                  "qom-path": "/machine/peripheral/cpu-2",
+                  "target": "x86_64",
+                  "thread-id": 12106,
+                  "cpu-index": 1,
+                  "props": {
+                      "socket-id": 1,
+                      "core-id": 0,
+                      "thread-id": 0
+                  },
+                  "arch": "x86"
+              }
+          ]
+      }
+      (QEMU)
+
+vCPU hot-unplug
+---------------
+
+From the 'qmp-shell', invoke the QMP ``device_del`` command::
+
+      (QEMU) device_del id=cpu-2
+      {
+          "execute": "device_del",
+          "arguments": {
+              "id": "cpu-2"
+          }
+      }
+      {
+          "return": {}
+      }
+      (QEMU)
+
+.. note::
+    vCPU hot-unplug requires guest cooperation; so the ``device_del``
+    command above does not guarantee vCPU removal -- it's a "request to
+    unplug".  At this point, the guest will get a System Control
+    Interupt (SCI) and calls the ACPI handler for the affected vCPU
+    device.  Then the guest kernel will bring the vCPU offline and tell
+    QEMU to unplug it.
Signature · 1 line
2.17.1
#12 lore raw
In reply to Kashyap Chamarthy

[Cc: libvir-list]

Quoted 22 lines · Kashyap Chamarthy

The first patch deprecates the QMP cpu-add, the second its HMP equivalent, and the third documents vCPU hotplug procedure using QMP device_add et al.

v2: https://lists.gnu.org/archive/html/qemu-devel/2018-09/msg03191.html

Kashyap Chamarthy (3):
Deprecate QMP cpu-add
Deprecate HMP cpu-add
docs: Document vCPU hotplug procedure

 docs/cpu-hotplug.rst | 142 +++++++++++++++++++++++++++++++++++++++++++
 hmp-commands.hx      |   6 +-
 hmp.c                |   2 +
 qapi/misc.json       |   8 ++-
 qemu-deprecated.texi |   5 ++
 5 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 docs/cpu-hotplug.rst
Signature · 1 line
2.17.1
Signature · 1 line
/kashyap
#13 lore raw
Quoted 6 lines · Kashyap Chamarthy

[Cc: libvir-list]

Quoted 3 lines · Kashyap Chamarthy

The first patch deprecates the QMP cpu-add, the second its HMP equivalent, and the third documents vCPU hotplug procedure using QMP device_add et al.

Thanks for heads up. Libvirt already uses device_add if 'query-hotpluggable-cpus' command is available and 'query-machines' returns 'hotpluggable-cpus: yes' for given machine type. It only falls back to cpu-add.

Michal

#7 lore raw

Re: [Qemu-devel] [PATCH v3 2/3] Deprecate HMP `cpu-add`

In reply to Kashyap Chamarthy
Quoted 20 lines · Kashyap Chamarthy

Since we're deprecating the QMP cpu-add, let's deprecate its HMP equivalent, too.

---
 hmp-commands.hx | 6 ++++--
 hmp.c           | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
hmp-commands.hx +1 -1
index db0c681f74..ba71558c25 100644
@@ -1849,14 +1849,16 @@ ETEXI
         .name       = "cpu-add",
         .args_type  = "id:i",
         .params     = "id",
-        .help       = "add cpu",
+        .help       = "add cpu (deprecated, use device_add instead)",

hmp-commands.hx ETEXI · line 1861

Quoted 10 lines
hmp-commands.hx +3 -1
         .cmd        = hmp_cpu_add,
     },
 
 STEXI
 @item cpu-add @var{id}
 @findex cpu-add
-Add CPU with id @var{id}
+Add CPU with id @var{id}.  This command is deprecated, please
++use @code{device_add} instead. For details, refer to
+'docs/cpu-hotplug.rst'.

File gets created only in PATCH 3. Let's apply PATCH 3 before 1 & 2. Perhaps the maintainer is willing to do that for you, so you don't have to respin.

Quoted 16 lines
hmp-commands.hx +0 -0
 ETEXI
 
     {
hmp.c +2 -0
index 4975fa56b0..c3f3db7795 100644
@@ -2353,6 +2353,8 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
     int cpuid;
     Error *err = NULL;
 
+    error_report("cpu_add is deprecated, please use device_add instead");
+
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
     hmp_handle_error(mon, &err);
#15 lore raw
Quoted 10 lines · Markus Armbruster
Quoted 5 lines · Kashyap Chamarthy

The first patch deprecates the QMP cpu-add, the second its HMP equivalent, and the third documents vCPU hotplug procedure using QMP device_add et al.

v2: https://lists.gnu.org/archive/html/qemu-devel/2018-09/msg03191.html

Preferably reordered so that PATCH 3 comes before 1 & 2, series

Thanks, queued on machine-next.

Being only documentation updates, I consider it to be reasonable to be included after soft freeze.

Signature · 1 line
Eduardo
Reviewed-by on v3 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] Deprecate QMP `cpu-add`

In reply to Kashyap Chamarthy
Quoted 11 lines · Kashyap Chamarthy

The intended functionality of QMP cpu-add is replaced with device_add (and query-hotpluggable-cpus). So let's deprecate cpu-add.

A complete example of vCPU hotplug with the recommended way (using device_add) is provided as part of a seperate docs patch.

---
---

Duplicated "---" line ... but I think this should not be a problem for the usual tools.

#8 lore raw

Re: [Qemu-devel] [PATCH v3 2/3] Deprecate HMP `cpu-add`

In reply to Kashyap Chamarthy
Quoted 39 lines · Kashyap Chamarthy

Since we're deprecating the QMP cpu-add, let's deprecate its HMP equivalent, too.

---
 hmp-commands.hx | 6 ++++--
 hmp.c           | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
hmp-commands.hx +4 -2
index db0c681f74..ba71558c25 100644
@@ -1849,14 +1849,16 @@ ETEXI
         .name       = "cpu-add",
         .args_type  = "id:i",
         .params     = "id",
-        .help       = "add cpu",
+        .help       = "add cpu (deprecated, use device_add instead)",
         .cmd        = hmp_cpu_add,
     },
 
 STEXI
 @item cpu-add @var{id}
 @findex cpu-add
-Add CPU with id @var{id}
+Add CPU with id @var{id}.  This command is deprecated, please
++use @code{device_add} instead. For details, refer to
+'docs/cpu-hotplug.rst'.
 ETEXI
 
     {
hmp.c +0 -0
index 4975fa56b0..c3f3db7795 100644

hmp.c void hmp_cpu_add(Monitor *mon, const QDict *qdict) · line 2360

Quoted 8 lines
hmp.c +2 -0
@@ -2353,6 +2353,8 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
     int cpuid;
     Error *err = NULL;
 
+    error_report("cpu_add is deprecated, please use device_add instead");
+
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
     hmp_handle_error(mon, &err);

I think you should also mention this explicitly in qemu-deprecated.texi, too.

Thomas

#9 lore raw

Re: [Qemu-devel] [PATCH v3 2/3] Deprecate HMP `cpu-add`

Quoted 6 lines · Thomas Huth
Quoted 5 lines · Kashyap Chamarthy

Since we're deprecating the QMP cpu-add, let's deprecate its HMP equivalent, too.

[...]

Quoted 8 lines
Quoted 8 lines
hmp.c +0 -0
index 4975fa56b0..c3f3db7795 100644
@@ -2353,6 +2353,8 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
     int cpuid;
     Error *err = NULL;
 
Quoted 9 lines

hmp.c void hmp_cpu_add(Monitor *mon, const QDict *qdict) · line 2360

Quoted 6 lines
hmp.c +2 -0
+    error_report("cpu_add is deprecated, please use device_add instead");
+
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
     hmp_handle_error(mon, &err);

I think you should also mention this explicitly in qemu-deprecated.texi, too.

I think you mean I should explicitly mention that the HMP equivalent is also deprecated -- currently I only call out the QMP command:
'qemu-deprecated.texi'.

I saw that Eduardo already queued this series; maybe I can add a follow-up if it can't be tweaked before submitting a pull request.

Thanks for the review!

Signature · 1 line
/kashyap
#10 lore raw

Re: [Qemu-devel] [PATCH v3 2/3] Deprecate HMP `cpu-add`

Quoted 28 lines · Kashyap Chamarthy
Quoted 6 lines · Thomas Huth
Quoted 5 lines · Kashyap Chamarthy

Since we're deprecating the QMP cpu-add, let's deprecate its HMP equivalent, too.

[...]

Quoted 8 lines
Quoted 8 lines
hmp.c +0 -0
index 4975fa56b0..c3f3db7795 100644
@@ -2353,6 +2353,8 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
     int cpuid;
     Error *err = NULL;
 
Quoted 9 lines

hmp.c void hmp_cpu_add(Monitor *mon, const QDict *qdict) · line 2360

Quoted 6 lines
hmp.c +2 -0
+    error_report("cpu_add is deprecated, please use device_add instead");
+
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
     hmp_handle_error(mon, &err);

I think you should also mention this explicitly in qemu-deprecated.texi, too.

Quoted 6 lines

I think you mean I should explicitly mention that the HMP equivalent is also deprecated -- currently I only call out the QMP command:
'qemu-deprecated.texi'.

I saw that Eduardo already queued this series; maybe I can add a follow-up if it can't be tweaked before submitting a pull request.

Yes, a follow-up patch is perfectly fine for this.

Thanks,
Thomas

#3 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] Deprecate QMP `cpu-add`

In reply to Kashyap Chamarthy
Quoted 10 lines · Kashyap Chamarthy

The intended functionality of QMP cpu-add is replaced with device_add (and query-hotpluggable-cpus). So let's deprecate cpu-add.

A complete example of vCPU hotplug with the recommended way (using device_add) is provided as part of a seperate docs patch.

---

[...]

qemu-deprecated.texi The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command. · line 158

Quoted 9 lines
qemu-deprecated.texi +1 -0
index 1b9c007f12..c86924ad9a 100644
@@ -155,6 +155,11 @@ The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command.
 The ``arch'' output member of the ``query-cpus-fast'' command is
 replaced by the ``target'' output member.
 
+@subsection cpu-add (since 3.1)

Hi Kashyap,

could you please send a follow-up patch to change this into 4.0 now?

Please also provide a patch to add the HMP command to qemu-deprecated.texi, too.

Thanks,
Thomas

#4 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] Deprecate QMP `cpu-add`

Quoted 20 lines · Thomas Huth
Quoted 10 lines · Kashyap Chamarthy

The intended functionality of QMP cpu-add is replaced with device_add (and query-hotpluggable-cpus). So let's deprecate cpu-add.

A complete example of vCPU hotplug with the recommended way (using device_add) is provided as part of a seperate docs patch.

---

[...]

Quoted 8 lines
qemu-deprecated.texi +0 -0
index 1b9c007f12..c86924ad9a 100644
@@ -155,6 +155,11 @@ The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command.
 The ``arch'' output member of the ``query-cpus-fast'' command is
 replaced by the ``target'' output member.
 
Quoted 5 lines

qemu-deprecated.texi The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command. · line 158

Quoted 1 line
qemu-deprecated.texi +1 -0
+@subsection cpu-add (since 3.1)

Hi Kashyap,

could you please send a follow-up patch to change this into 4.0 now?

Ah, sure.

Quoted 2 lines

Please also provide a patch to add the HMP command to qemu-deprecated.texi, too.

Is it okay if both the above are done in the same patch? Since they're related. Or am I missing a reason to do them separately?

Signature · 1 line
/kashyap
#5 lore raw

Re: [Qemu-devel] [PATCH v3 1/3] Deprecate QMP `cpu-add`

Quoted 2 lines · Kashyap Chamarthy
Quoted 1 line · Thomas Huth

On 2018-10-30 13:35, Kashyap Chamarthy wrote:

[...]

Quoted 13 lines
Quoted 7 lines
Quoted 7 lines

index 1b9c007f12..c86924ad9a 100644

qemu-deprecated.texi +0 -0
@@ -155,6 +155,11 @@ The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command.
 The ``arch'' output member of the ``query-cpus-fast'' command is
 replaced by the ``target'' output member.
 
Quoted 5 lines

qemu-deprecated.texi The ``query-cpus'' command is replaced by the ``query-cpus-fast'' command. · line 158

Quoted 1 line
qemu-deprecated.texi +1 -0
+@subsection cpu-add (since 3.1)

Hi Kashyap,

could you please send a follow-up patch to change this into 4.0 now?

Quoted 7 lines

Ah, sure.

Quoted 2 lines

Please also provide a patch to add the HMP command to qemu-deprecated.texi, too.

Is it okay if both the above are done in the same patch? Since they're related. Or am I missing a reason to do them separately?

Okay, please disregard the above; Dave Gilbert reminded that it's preferable that I send two separate patches (part of a "series"), as they're different things.

Signature · 1 line
/kashyap