The intended functionality of QMP command `cpu-add` is replaced by
`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`:
(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 \
-blockdev node-name=node-Base,driver=qcow2,file.driver=file,file.filename=./base.qcow2 \
-device virtio-blk,drive=node-Base,id=virtio0 -qmp unix:/tmp/qmp-sock,server,nowait
(2) Run 'qmp-shell' (located in the source tree) to connect to the
just-launched QEMU:
$> ./qmp/qmp-shell -p -v /tmp/qmp-sock
[...]
(QEMU)
(3) Check which socket is free to allow hotplugging a CPU:
(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) We can see that socket 1 is free, so use `device_add` to hotplug
"IvyBridge-IBRS-x86_64-cpu":
(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.
Suggested-by: Eduardo Habkost <ehabkost@redhat.com
Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
---
Also shouldn't we update tests/cpu-plug-test.c to make it use
`device_add`. Can take a stab at it, if you'd like me to.
---
qapi/misc.json | 6 +++++-
qemu-deprecated.texi | 5 +++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/qapi/misc.json b/qapi/misc.json
index d450cfef21..83bc9ad0ee 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -1104,7 +1104,11 @@
##
# @cpu-add:
#
-# Adds CPU with specified ID
+# Adds CPU with specified ID.
+#
+# Notes: This command is deprecated. The `device_add` command should be
+# used instead. See the `query-hotpluggable-cpus` command for
+# details.
#
# @id: ID of CPU to be created, valid values [0..max_cpus)
#
diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
index 1b9c007f12..9c6d70d43a 100644
--- a/qemu-deprecated.texi
+++ b/qemu-deprecated.texi
@@ -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)
+
+The intended functionality of ``cpu-add'' command, which is the ability
+to hot-plug vCPUs, can now be achieved by the ``device_add'' command.
+
@section System emulator devices
@subsection ivshmem (since 2.6.0)
--
2.17.1
Kashyap Chamarthy <kchamart@redhat.com> writes:
> The intended functionality of QMP command `cpu-add` is replaced by
> `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`:
>
> (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 \
> -blockdev node-name=node-Base,driver=qcow2,file.driver=file,file.filename=./base.qcow2 \
> -device virtio-blk,drive=node-Base,id=virtio0 -qmp unix:/tmp/qmp-sock,server,nowait
>
> (2) Run 'qmp-shell' (located in the source tree) to connect to the
> just-launched QEMU:
>
> $> ./qmp/qmp-shell -p -v /tmp/qmp-sock
> [...]
> (QEMU)
>
> (3) Check which socket is free to allow hotplugging a CPU:
>
> (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)
When I try this, JSON gets formatted slightly differently:
{
"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
}
}
]
}
How come?
>
> (4) We can see that socket 1 is free, so use `device_add` to hotplug
> "IvyBridge-IBRS-x86_64-cpu":
>
> (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.
Publishing this in a commit message is much better than not publishing
it. Still, can we find a better home somewhere under docs/?
> Suggested-by: Eduardo Habkost <ehabkost@redhat.com
> Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
> ---
> Also shouldn't we update tests/cpu-plug-test.c to make it use
> `device_add`. Can take a stab at it, if you'd like me to.
Yes, please.
> ---
> qapi/misc.json | 6 +++++-
> qemu-deprecated.texi | 5 +++++
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/qapi/misc.json b/qapi/misc.json
> index d450cfef21..83bc9ad0ee 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -1104,7 +1104,11 @@
> ##
> # @cpu-add:
> #
> -# Adds CPU with specified ID
> +# Adds CPU with specified ID.
> +#
> +# Notes: This command is deprecated. The `device_add` command should be
> +# used instead. See the `query-hotpluggable-cpus` command for
> +# details.
> #
> # @id: ID of CPU to be created, valid values [0..max_cpus)
> #
Eduardo pointed out that query-hotpluggable-cpus's documentation is
lacking. Add a suitable TODO there?
> diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> index 1b9c007f12..9c6d70d43a 100644
> --- a/qemu-deprecated.texi
> +++ b/qemu-deprecated.texi
> @@ -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)
> +
> +The intended functionality of ``cpu-add'' command, which is the ability
> +to hot-plug vCPUs, can now be achieved by the ``device_add'' command.
> +
For me, "now" suggests device_add can achieve this since 3.1. Scratch
"now"?
> @section System emulator devices
>
> @subsection ivshmem (since 2.6.0)
On Thu, Sep 20, 2018 at 02:27:02PM +0200, Markus Armbruster wrote:
> Kashyap Chamarthy <kchamart@redhat.com> writes:
[...]
> When I try this, JSON gets formatted slightly differently:
>
> {
> "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
> }
> }
> ]
> }
>
> How come?
You caught me :-). I actually get the same as you well. But I fudged
the output by running it through:
https://jsonformatter.curiousconcept.com/ with "2 Space Tab", but it
doesn't make any difference.
So I'll actually retain the original raw output from 'qmp-shell'.
> > (4) We can see that socket 1 is free, so use `device_add` to hotplug
> > "IvyBridge-IBRS-x86_64-cpu":
> >
> > (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.
>
> Publishing this in a commit message is much better than not publishing
> it. Still, can we find a better home somewhere under docs/?
Good point. I'll make an 'cpu-hotplug.rst' in docs/ and submit it
as a patch in v2. Hope that's okay with you.
[...]
> > ---
> > Also shouldn't we update tests/cpu-plug-test.c to make it use
> > `device_add`. Can take a stab at it, if you'd like me to.
>
> Yes, please.
Igor was saying on IRC that we can fix the test when we _actually_ do
the deprecation. So I'll make a TODO (and won't forget) to make it as a
separate patch after we deprecate this.
[...]
> > # @id: ID of CPU to be created, valid values [0..max_cpus)
> > #
>
> Eduardo pointed out that query-hotpluggable-cpus's documentation is
> lacking. Add a suitable TODO there?
Yes, will do.
> > diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> > index 1b9c007f12..9c6d70d43a 100644
> > --- a/qemu-deprecated.texi
> > +++ b/qemu-deprecated.texi
> > @@ -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)
> > +
> > +The intended functionality of ``cpu-add'' command, which is the ability
> > +to hot-plug vCPUs, can now be achieved by the ``device_add'' command.
> > +
>
> For me, "now" suggests device_add can achieve this since 3.1. Scratch
> "now"?
Yes, will do.
Thanks for the quick review!
--
/kashyap
On Thu, Sep 20, 2018 at 02:27:02PM +0200, Markus Armbruster wrote: > Kashyap Chamarthy <kchamart@redhat.com> writes: [...] > > --- > > qapi/misc.json | 6 +++++- > > qemu-deprecated.texi | 5 +++++ > > 2 files changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/qapi/misc.json b/qapi/misc.json > > index d450cfef21..83bc9ad0ee 100644 > > --- a/qapi/misc.json > > +++ b/qapi/misc.json > > @@ -1104,7 +1104,11 @@ > > ## > > # @cpu-add: > > # > > -# Adds CPU with specified ID > > +# Adds CPU with specified ID. > > +# > > +# Notes: This command is deprecated. The `device_add` command should be > > +# used instead. See the `query-hotpluggable-cpus` command for > > +# details. > > # > > # @id: ID of CPU to be created, valid values [0..max_cpus) > > # > > Eduardo pointed out that query-hotpluggable-cpus's documentation is > lacking. Add a suitable TODO there? Yes, please. > > > diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi > > index 1b9c007f12..9c6d70d43a 100644 > > --- a/qemu-deprecated.texi > > +++ b/qemu-deprecated.texi > > @@ -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) > > + > > +The intended functionality of ``cpu-add'' command, which is the ability > > +to hot-plug vCPUs, can now be achieved by the ``device_add'' command. > > + > > For me, "now" suggests device_add can achieve this since 3.1. Scratch > "now"? Agreed. I would also try to write a shorter and simpler sentence, and mention query-hotpluggable-cpus. e.g.: The ``device_add'' command should be used for hotplugging VCPUs instead of ``cpu-add''. See the documentation of the ``query-hotpluggable-cpus'' command for additional details. > > > @section System emulator devices > > > > @subsection ivshmem (since 2.6.0) -- Eduardo
Eduardo Habkost <ehabkost@redhat.com> writes:
> On Thu, Sep 20, 2018 at 02:27:02PM +0200, Markus Armbruster wrote:
>> Kashyap Chamarthy <kchamart@redhat.com> writes:
> [...]
>> > ---
>> > qapi/misc.json | 6 +++++-
>> > qemu-deprecated.texi | 5 +++++
>> > 2 files changed, 10 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/qapi/misc.json b/qapi/misc.json
>> > index d450cfef21..83bc9ad0ee 100644
>> > --- a/qapi/misc.json
>> > +++ b/qapi/misc.json
>> > @@ -1104,7 +1104,11 @@
>> > ##
>> > # @cpu-add:
>> > #
>> > -# Adds CPU with specified ID
>> > +# Adds CPU with specified ID.
>> > +#
>> > +# Notes: This command is deprecated. The `device_add` command should be
>> > +# used instead. See the `query-hotpluggable-cpus` command for
>> > +# details.
>> > #
>> > # @id: ID of CPU to be created, valid values [0..max_cpus)
>> > #
>>
>> Eduardo pointed out that query-hotpluggable-cpus's documentation is
>> lacking. Add a suitable TODO there?
>
> Yes, please.
>
>>
>> > diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
>> > index 1b9c007f12..9c6d70d43a 100644
>> > --- a/qemu-deprecated.texi
>> > +++ b/qemu-deprecated.texi
>> > @@ -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)
>> > +
>> > +The intended functionality of ``cpu-add'' command, which is the ability
>> > +to hot-plug vCPUs, can now be achieved by the ``device_add'' command.
>> > +
>>
>> For me, "now" suggests device_add can achieve this since 3.1. Scratch
>> "now"?
>
> Agreed.
>
> I would also try to write a shorter and simpler sentence, and
> mention query-hotpluggable-cpus. e.g.:
>
> The ``device_add'' command should be used for hotplugging VCPUs
> instead of ``cpu-add''. See the documentation of the
> ``query-hotpluggable-cpus'' command for additional details.
Perhaps even
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)
On Fri, Sep 21, 2018 at 08:30:54AM +0200, Markus Armbruster wrote: > Eduardo Habkost <ehabkost@redhat.com> writes: > > > On Thu, Sep 20, 2018 at 02:27:02PM +0200, Markus Armbruster wrote: > >> Kashyap Chamarthy <kchamart@redhat.com> writes: > > [...] > >> > --- > >> > qapi/misc.json | 6 +++++- > >> > qemu-deprecated.texi | 5 +++++ > >> > 2 files changed, 10 insertions(+), 1 deletion(-) > >> > > >> > diff --git a/qapi/misc.json b/qapi/misc.json > >> > index d450cfef21..83bc9ad0ee 100644 > >> > --- a/qapi/misc.json > >> > +++ b/qapi/misc.json > >> > @@ -1104,7 +1104,11 @@ > >> > ## > >> > # @cpu-add: > >> > # > >> > -# Adds CPU with specified ID > >> > +# Adds CPU with specified ID. > >> > +# > >> > +# Notes: This command is deprecated. The `device_add` command should be > >> > +# used instead. See the `query-hotpluggable-cpus` command for > >> > +# details. > >> > # > >> > # @id: ID of CPU to be created, valid values [0..max_cpus) > >> > # > >> > >> Eduardo pointed out that query-hotpluggable-cpus's documentation is > >> lacking. Add a suitable TODO there? > > > > Yes, please. > > > >> > >> > diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi > >> > index 1b9c007f12..9c6d70d43a 100644 > >> > --- a/qemu-deprecated.texi > >> > +++ b/qemu-deprecated.texi > >> > @@ -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) > >> > + > >> > +The intended functionality of ``cpu-add'' command, which is the ability > >> > +to hot-plug vCPUs, can now be achieved by the ``device_add'' command. > >> > + > >> > >> For me, "now" suggests device_add can achieve this since 3.1. Scratch > >> "now"? > > > > Agreed. > > > > I would also try to write a shorter and simpler sentence, and > > mention query-hotpluggable-cpus. e.g.: > > > > The ``device_add'' command should be used for hotplugging VCPUs > > instead of ``cpu-add''. See the documentation of the > > ``query-hotpluggable-cpus'' command for additional details. > > Perhaps even > > Use ``device_add'' for hotplugging VCPUs instead of ``cpu-add''. > See documentation of ``query-hotpluggable-cpus'' for additional > details. Nice, that's even more straightforward and simple. -- Eduardo
© 2016 - 2025 Red Hat, Inc.