diff mbox

[1/3] qapi: Report support for -device cpu hotplug in query-machines

Message ID 6a52d9a67cc72abb874c9906df039d11bfe1e18d.1466713052.git.pkrempa@redhat.com
State New
Headers show

Commit Message

Peter Krempa June 23, 2016, 8:23 p.m. UTC
For management apps it's very useful to know whether the selected
machine type supports cpu hotplug via the new -device approach. Using
the presence of 'query-hotpluggable-cpus' is enough for a withess.

Add a property to 'MachineInfo' called 'hotpluggable-cpus' that will
report the presence of this feature.

Example of output:
    {
        "hotpluggable-cpus": false,
        "name": "mac99",
        "cpu-max": 1
    },
    {
        "hotpluggable-cpus": true,
        "name": "pseries-2.7",
        "is-default": true,
        "cpu-max": 255,
        "alias": "pseries"
    },

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 qapi-schema.json | 5 ++++-
 vl.c             | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Eric Blake June 23, 2016, 9:05 p.m. UTC | #1
On 06/23/2016 02:23 PM, Peter Krempa wrote:
> For management apps it's very useful to know whether the selected
> machine type supports cpu hotplug via the new -device approach. Using
> the presence of 'query-hotpluggable-cpus' is enough for a withess.

s/is enough/alone is not enough/ ?

s/withess/witness/

> 
> Add a property to 'MachineInfo' called 'hotpluggable-cpus' that will
> report the presence of this feature.
> 
> Example of output:
>     {
>         "hotpluggable-cpus": false,
>         "name": "mac99",
>         "cpu-max": 1
>     },
>     {
>         "hotpluggable-cpus": true,
>         "name": "pseries-2.7",
>         "is-default": true,
>         "cpu-max": 255,
>         "alias": "pseries"
>     },
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  qapi-schema.json | 5 ++++-
>  vl.c             | 1 +
>  2 files changed, 5 insertions(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
David Gibson June 24, 2016, 2:56 a.m. UTC | #2
On Thu, 23 Jun 2016 22:23:23 +0200
Peter Krempa <pkrempa@redhat.com> wrote:

> For management apps it's very useful to know whether the selected
> machine type supports cpu hotplug via the new -device approach. Using
> the presence of 'query-hotpluggable-cpus' is enough for a withess.
> 
> Add a property to 'MachineInfo' called 'hotpluggable-cpus' that will
> report the presence of this feature.
> 
> Example of output:
>     {
>         "hotpluggable-cpus": false,
>         "name": "mac99",
>         "cpu-max": 1
>     },
>     {
>         "hotpluggable-cpus": true,
>         "name": "pseries-2.7",
>         "is-default": true,
>         "cpu-max": 255,
>         "alias": "pseries"
>     },

I'd been under the impression that there was a general way of detecting
the availability of a particular qmp command.  Was I mistaken?

> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  qapi-schema.json | 5 ++++-
>  vl.c             | 1 +
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 0964eec..24ede28 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2986,11 +2986,14 @@
>  # @cpu-max: maximum number of CPUs supported by the machine type
>  #           (since 1.5.0)
>  #
> +# @hotpluggable-cpus: cpu hotplug via -device is supported (since 2.7.0)
> +#
>  # Since: 1.2.0
>  ##
>  { 'struct': 'MachineInfo',
>    'data': { 'name': 'str', '*alias': 'str',
> -            '*is-default': 'bool', 'cpu-max': 'int' } }
> +            '*is-default': 'bool', 'cpu-max': 'int',
> +            'hotpluggable-cpus': 'bool'} }
> 
>  ##
>  # @query-machines:
> diff --git a/vl.c b/vl.c
> index c85833a..4c1f9ae 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1524,6 +1524,7 @@ MachineInfoList *qmp_query_machines(Error **errp)
> 
>          info->name = g_strdup(mc->name);
>          info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
> +        info->hotpluggable_cpus = !!mc->query_hotpluggable_cpus;
> 
>          entry = g_malloc0(sizeof(*entry));
>          entry->value = info;
> -- 
> 2.8.3
>
Eric Blake June 24, 2016, 3:49 a.m. UTC | #3
On 06/23/2016 08:56 PM, David Gibson wrote:
> On Thu, 23 Jun 2016 22:23:23 +0200
> Peter Krempa <pkrempa@redhat.com> wrote:
> 
>> For management apps it's very useful to know whether the selected
>> machine type supports cpu hotplug via the new -device approach. Using
>> the presence of 'query-hotpluggable-cpus' is enough for a withess.
>>

> 
> I'd been under the impression that there was a general way of detecting
> the availability of a particular qmp command.  Was I mistaken?

You are correct - query-commands says whether 'query-hotpluggable-cpus'
exists as a command.  But that is insufficient.  See my review, or the
v2 patch, where the above poor wording was corrected to say what was
really meant: knowing whether query-hotpluggable-cpus exists is
insufficient to tell you whether a given cpu type can be hotplugged.  So
adding one more piece of witness (for every type of cpu supported, we
also advertise if it is hotpluggable) is enough for libvirt to
efficiently take advantage of the new query-hotpluggable-cpus command.
David Gibson June 24, 2016, 4:56 a.m. UTC | #4
On Thu, 23 Jun 2016 21:49:25 -0600
Eric Blake <eblake@redhat.com> wrote:

> On 06/23/2016 08:56 PM, David Gibson wrote:
> > On Thu, 23 Jun 2016 22:23:23 +0200
> > Peter Krempa <pkrempa@redhat.com> wrote:
> >   
> >> For management apps it's very useful to know whether the selected
> >> machine type supports cpu hotplug via the new -device approach. Using
> >> the presence of 'query-hotpluggable-cpus' is enough for a withess.
> >>  
> 
> > 
> > I'd been under the impression that there was a general way of detecting
> > the availability of a particular qmp command.  Was I mistaken?  
> 
> You are correct - query-commands says whether 'query-hotpluggable-cpus'
> exists as a command.  But that is insufficient.  See my review, or the
> v2 patch, where the above poor wording was corrected to say what was
> really meant: knowing whether query-hotpluggable-cpus exists is
> insufficient to tell you whether a given cpu type can be hotplugged.  So
> adding one more piece of witness (for every type of cpu supported, we
> also advertise if it is hotpluggable) is enough for libvirt to
> efficiently take advantage of the new query-hotpluggable-cpus command.

Ah, right.  Or to put it another way, the availability of
query-hotpluggable-cpus is global across qemu, whereas actually being
able to use it for hotplug is per machine type.

Would it be possible to do this instead by attempting to invoke
query-hopluggable-cpus and seeing if it returns any information?
Igor Mammedov June 24, 2016, 5:28 a.m. UTC | #5
On Fri, 24 Jun 2016 14:56:51 +1000
David Gibson <dgibson@redhat.com> wrote:

> On Thu, 23 Jun 2016 21:49:25 -0600
> Eric Blake <eblake@redhat.com> wrote:
> 
> > On 06/23/2016 08:56 PM, David Gibson wrote:
> > > On Thu, 23 Jun 2016 22:23:23 +0200
> > > Peter Krempa <pkrempa@redhat.com> wrote:
> > >   
> > >> For management apps it's very useful to know whether the selected
> > >> machine type supports cpu hotplug via the new -device approach.
> > >> Using the presence of 'query-hotpluggable-cpus' is enough for a
> > >> withess. 
> > 
> > > 
> > > I'd been under the impression that there was a general way of
> > > detecting the availability of a particular qmp command.  Was I
> > > mistaken?  
> > 
> > You are correct - query-commands says whether
> > 'query-hotpluggable-cpus' exists as a command.  But that is
> > insufficient.  See my review, or the v2 patch, where the above poor
> > wording was corrected to say what was really meant: knowing whether
> > query-hotpluggable-cpus exists is insufficient to tell you whether
> > a given cpu type can be hotplugged.  So adding one more piece of
> > witness (for every type of cpu supported, we also advertise if it
> > is hotpluggable) is enough for libvirt to efficiently take
> > advantage of the new query-hotpluggable-cpus
> > command.
> 
> Ah, right.  Or to put it another way, the availability of
> query-hotpluggable-cpus is global across qemu, whereas actually being
> able to use it for hotplug is per machine type.
> 
> Would it be possible to do this instead by attempting to invoke
> query-hopluggable-cpus and seeing if it returns any information?
This sounds like a better way, for x86 we can set
query-hotpluggable-cpus hook to NULL for old machine types so that
it would return error that it's not supported.

> 
>
Peter Krempa June 24, 2016, 5:41 a.m. UTC | #6
On Fri, Jun 24, 2016 at 14:56:51 +1000, David Gibson wrote:

[...]

> > You are correct - query-commands says whether 'query-hotpluggable-cpus'
> > exists as a command.  But that is insufficient.  See my review, or the
> > v2 patch, where the above poor wording was corrected to say what was
> > really meant: knowing whether query-hotpluggable-cpus exists is
> > insufficient to tell you whether a given cpu type can be hotplugged.  So
> > adding one more piece of witness (for every type of cpu supported, we
> > also advertise if it is hotpluggable) is enough for libvirt to
> > efficiently take advantage of the new query-hotpluggable-cpus command.
> 
> Ah, right.  Or to put it another way, the availability of
> query-hotpluggable-cpus is global across qemu, whereas actually being
> able to use it for hotplug is per machine type.
> 
> Would it be possible to do this instead by attempting to invoke
> query-hopluggable-cpus and seeing if it returns any information?

It is not strictly necessary for us to have this in the context of
usability. If the user requests using the new hotplug feature we will
try it unconditionally and call query-hotpluggable-cpus before even
starting guest execution. A failure to query the state will then result
in termination of the VM.

It is necessary though to report the availability of the feature to the
user via our domain capabilities API which some higher layer management
apps use to make decisions.

This would also be necessary if we wanted to switch by default to the
new approach, but that's not really possible as libvirt tries to
guarantee that a config valid on certain version will be still valid
even when it was migrated to a newer version and then back.

My current plan is to start qemu with -smp cpus=1,... and then call
query-hotpluggable-cpus and then hotplug all of them until the requested
configuration is satisfied. This approach is necessary so that we can
query for the model and topology info so that we don't need to
re-implement all the numbering and naming logic from qemu.

Additionally this will require us to mark one CPU as non-hotpluggable as
-smp cpus=0,maxcpus=10 is basically translated to -smp
cpus=10,maxcpus=10.

Peter
David Gibson June 24, 2016, 6:56 a.m. UTC | #7
On Fri, 24 Jun 2016 07:41:11 +0200
Peter Krempa <pkrempa@redhat.com> wrote:

> On Fri, Jun 24, 2016 at 14:56:51 +1000, David Gibson wrote:
> 
> [...]
> 
> > > You are correct - query-commands says whether 'query-hotpluggable-cpus'
> > > exists as a command.  But that is insufficient.  See my review, or the
> > > v2 patch, where the above poor wording was corrected to say what was
> > > really meant: knowing whether query-hotpluggable-cpus exists is
> > > insufficient to tell you whether a given cpu type can be hotplugged.  So
> > > adding one more piece of witness (for every type of cpu supported, we
> > > also advertise if it is hotpluggable) is enough for libvirt to
> > > efficiently take advantage of the new query-hotpluggable-cpus command.  
> > 
> > Ah, right.  Or to put it another way, the availability of
> > query-hotpluggable-cpus is global across qemu, whereas actually being
> > able to use it for hotplug is per machine type.
> > 
> > Would it be possible to do this instead by attempting to invoke
> > query-hopluggable-cpus and seeing if it returns any information?  
> 
> It is not strictly necessary for us to have this in the context of
> usability. If the user requests using the new hotplug feature we will
> try it unconditionally and call query-hotpluggable-cpus before even
> starting guest execution. A failure to query the state will then result
> in termination of the VM.

Oh.. I wasn't expecting the feature would be enabled at user request -
I thought libvirt would just use it if available.

> It is necessary though to report the availability of the feature to the
> user via our domain capabilities API which some higher layer management
> apps use to make decisions.

Right... what advantage does adding the machine flag have over
attempting the query-hotpluggable-cpus?

> This would also be necessary if we wanted to switch by default to the
> new approach, but that's not really possible as libvirt tries to
> guarantee that a config valid on certain version will be still valid
> even when it was migrated to a newer version and then back.

Sorry, I've lost track of what the "This" is that would be necessary.

> My current plan is to start qemu with -smp cpus=1,... and then call
> query-hotpluggable-cpus and then hotplug all of them until the requested
> configuration is satisfied. This approach is necessary so that we can
> query for the model and topology info so that we don't need to
> re-implement all the numbering and naming logic from qemu.

Um.. why?  What's the problem with just staring with -smp cpus=whatever
and then using query-hotpluggable-cpus?

> Additionally this will require us to mark one CPU as non-hotpluggable as
> -smp cpus=0,maxcpus=10 is basically translated to -smp
> cpus=10,maxcpus=10.

The latter is true, but I'm not clear why it implies the former.
Peter Krempa June 24, 2016, 7:21 a.m. UTC | #8
On Fri, Jun 24, 2016 at 16:56:21 +1000, David Gibson wrote:
> On Fri, 24 Jun 2016 07:41:11 +0200
> Peter Krempa <pkrempa@redhat.com> wrote:
> 
> > On Fri, Jun 24, 2016 at 14:56:51 +1000, David Gibson wrote:
> > 
> > [...]
> > 
> > > > You are correct - query-commands says whether 'query-hotpluggable-cpus'
> > > > exists as a command.  But that is insufficient.  See my review, or the
> > > > v2 patch, where the above poor wording was corrected to say what was
> > > > really meant: knowing whether query-hotpluggable-cpus exists is
> > > > insufficient to tell you whether a given cpu type can be hotplugged.  So
> > > > adding one more piece of witness (for every type of cpu supported, we
> > > > also advertise if it is hotpluggable) is enough for libvirt to
> > > > efficiently take advantage of the new query-hotpluggable-cpus command.  
> > > 
> > > Ah, right.  Or to put it another way, the availability of
> > > query-hotpluggable-cpus is global across qemu, whereas actually being
> > > able to use it for hotplug is per machine type.
> > > 
> > > Would it be possible to do this instead by attempting to invoke
> > > query-hopluggable-cpus and seeing if it returns any information?  
> > 
> > It is not strictly necessary for us to have this in the context of
> > usability. If the user requests using the new hotplug feature we will
> > try it unconditionally and call query-hotpluggable-cpus before even
> > starting guest execution. A failure to query the state will then result
> > in termination of the VM.
> 
> Oh.. I wasn't expecting the feature would be enabled at user request -
> I thought libvirt would just use it if available.

Hmm, I think that will be possible to use the feature all the time after
all. I'll need to add multiple states for that though to track it in
the XML so that we can re-create it on migration the right way.

> > It is necessary though to report the availability of the feature to the
> > user via our domain capabilities API which some higher layer management
> > apps use to make decisions.
> 
> Right... what advantage does adding the machine flag have over
> attempting the query-hotpluggable-cpus?

Mostly the ability for oVirt or open stack being able to query whether
it's available for given machine type prior to even attempting to launch
the VM. Otherwise the'll be left to either guessing or re-implementing
the support matrix.

This means that the ability to query it with machine types is not
strictly necessary for implementing the feature in libvirt but a
very-nice-to-have thing to add to our capabilities queries.

> > This would also be necessary if we wanted to switch by default to the
> > new approach, but that's not really possible as libvirt tries to
> > guarantee that a config valid on certain version will be still valid
> > even when it was migrated to a newer version and then back.
> 
> Sorry, I've lost track of what the "This" is that would be necessary.

Never mind on this point. If I design the XML a bit differently it will
be possible to use this this feature if present all the time. Some cpus
just won't be available for unplug.

> > My current plan is to start qemu with -smp cpus=1,... and then call
> > query-hotpluggable-cpus and then hotplug all of them until the requested
> > configuration is satisfied. This approach is necessary so that we can
> > query for the model and topology info so that we don't need to
> > re-implement all the numbering and naming logic from qemu.
> 
> Um.. why?  What's the problem with just staring with -smp cpus=whatever
> and then using query-hotpluggable-cpus?
> 
> > Additionally this will require us to mark one CPU as non-hotpluggable as
> > -smp cpus=0,maxcpus=10 is basically translated to -smp
> > cpus=10,maxcpus=10.
> 
> The latter is true, but I'm not clear why it implies the former.

It necessarily doesn't imply it. I originally wanted to have most cpus
unpluggable but thinking again it is not really necessary I just need to
adapt the interface design.

Let's see how it turns out.

Peter
David Gibson June 27, 2016, 2:40 a.m. UTC | #9
On Fri, 24 Jun 2016 09:21:18 +0200
Peter Krempa <pkrempa@redhat.com> wrote:

> On Fri, Jun 24, 2016 at 16:56:21 +1000, David Gibson wrote:
> > On Fri, 24 Jun 2016 07:41:11 +0200
> > Peter Krempa <pkrempa@redhat.com> wrote:
> >   
> > > On Fri, Jun 24, 2016 at 14:56:51 +1000, David Gibson wrote:
> > > 
> > > [...]
> > >   
> > > > > You are correct - query-commands says whether 'query-hotpluggable-cpus'
> > > > > exists as a command.  But that is insufficient.  See my review, or the
> > > > > v2 patch, where the above poor wording was corrected to say what was
> > > > > really meant: knowing whether query-hotpluggable-cpus exists is
> > > > > insufficient to tell you whether a given cpu type can be hotplugged.  So
> > > > > adding one more piece of witness (for every type of cpu supported, we
> > > > > also advertise if it is hotpluggable) is enough for libvirt to
> > > > > efficiently take advantage of the new query-hotpluggable-cpus command.    
> > > > 
> > > > Ah, right.  Or to put it another way, the availability of
> > > > query-hotpluggable-cpus is global across qemu, whereas actually being
> > > > able to use it for hotplug is per machine type.
> > > > 
> > > > Would it be possible to do this instead by attempting to invoke
> > > > query-hopluggable-cpus and seeing if it returns any information?    
> > > 
> > > It is not strictly necessary for us to have this in the context of
> > > usability. If the user requests using the new hotplug feature we will
> > > try it unconditionally and call query-hotpluggable-cpus before even
> > > starting guest execution. A failure to query the state will then result
> > > in termination of the VM.  
> > 
> > Oh.. I wasn't expecting the feature would be enabled at user request -
> > I thought libvirt would just use it if available.  
> 
> Hmm, I think that will be possible to use the feature all the time after
> all. I'll need to add multiple states for that though to track it in
> the XML so that we can re-create it on migration the right way.

Hmm...

At least on Power, our intention is that just the machine type version
determines which approach is in use.  WIth machine type <= 2.6, the old
style initialization will be used and hotplug will not be available.
With machine type >= 2.7, new style will be used, and hotplug will be
theoretically available, whether or not you actually use it and
regardless of anything else on the command line.

So I'm not really understanding why you need to track anything extra
for migration here.

> > > It is necessary though to report the availability of the feature to the
> > > user via our domain capabilities API which some higher layer management
> > > apps use to make decisions.  
> > 
> > Right... what advantage does adding the machine flag have over
> > attempting the query-hotpluggable-cpus?  
> 
> Mostly the ability for oVirt or open stack being able to query whether
> it's available for given machine type prior to even attempting to launch
> the VM. Otherwise the'll be left to either guessing or re-implementing
> the support matrix.
> 
> This means that the ability to query it with machine types is not
> strictly necessary for implementing the feature in libvirt but a
> very-nice-to-have thing to add to our capabilities queries.

Ok, makes sense.  I'll merge the patch.

> > > This would also be necessary if we wanted to switch by default to the
> > > new approach, but that's not really possible as libvirt tries to
> > > guarantee that a config valid on certain version will be still valid
> > > even when it was migrated to a newer version and then back.  
> > 
> > Sorry, I've lost track of what the "This" is that would be necessary.  
> 
> Never mind on this point. If I design the XML a bit differently it will
> be possible to use this this feature if present all the time. Some cpus
> just won't be available for unplug.

Ok, still not seeing what any of this has to do with unplug.

> > > My current plan is to start qemu with -smp cpus=1,... and then call
> > > query-hotpluggable-cpus and then hotplug all of them until the requested
> > > configuration is satisfied. This approach is necessary so that we can
> > > query for the model and topology info so that we don't need to
> > > re-implement all the numbering and naming logic from qemu.  
> > 
> > Um.. why?  What's the problem with just staring with -smp cpus=whatever
> > and then using query-hotpluggable-cpus?
> >   
> > > Additionally this will require us to mark one CPU as non-hotpluggable as
> > > -smp cpus=0,maxcpus=10 is basically translated to -smp
> > > cpus=10,maxcpus=10.  
> > 
> > The latter is true, but I'm not clear why it implies the former.  
> 
> It necessarily doesn't imply it. I originally wanted to have most cpus
> unpluggable but thinking again it is not really necessary I just need to
> adapt the interface design.

Again, not seeing what prevents unplug here.

You do realise that query-hotpluggable-cpus lists already plugged as
well as can-be-plugged packages?  And those already plugged packages
(including ones constructed initially) can be unplugged..?
diff mbox

Patch

diff --git a/qapi-schema.json b/qapi-schema.json
index 0964eec..24ede28 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2986,11 +2986,14 @@ 
 # @cpu-max: maximum number of CPUs supported by the machine type
 #           (since 1.5.0)
 #
+# @hotpluggable-cpus: cpu hotplug via -device is supported (since 2.7.0)
+#
 # Since: 1.2.0
 ##
 { 'struct': 'MachineInfo',
   'data': { 'name': 'str', '*alias': 'str',
-            '*is-default': 'bool', 'cpu-max': 'int' } }
+            '*is-default': 'bool', 'cpu-max': 'int',
+            'hotpluggable-cpus': 'bool'} }

 ##
 # @query-machines:
diff --git a/vl.c b/vl.c
index c85833a..4c1f9ae 100644
--- a/vl.c
+++ b/vl.c
@@ -1524,6 +1524,7 @@  MachineInfoList *qmp_query_machines(Error **errp)

         info->name = g_strdup(mc->name);
         info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
+        info->hotpluggable_cpus = !!mc->query_hotpluggable_cpus;

         entry = g_malloc0(sizeof(*entry));
         entry->value = info;