Skip to contentSkip to conversation

vl.c: Check max_cpus limit instead of smp_cpus

PATCH In review Eduardo Habkost 3 participants 8 messages May 7, 2014 – May 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl.c: Check max_cpus limit instead of smp_cpus

If a given machine have max_cpus set, not just smp_cpus needs to be limited, but the total number of CPUs (considering CPU hotplug) for the machine.

As smp_parse() already ensures smp_cpus <= max_cpus, we just need to check if max_cpus exceeds the limit.

---
 vl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
vl.c +3 -3
index 236f95e..e317cc9 100644
@@ -4039,9 +4039,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+    if (max_cpus > machine->max_cpus) {
+        fprintf(stderr, "Total number of CPUs (%d), exceeds maximum "
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);
     }
Signature · 1 line
1.9.0
#1 lore raw
Quoted 18 lines · Eduardo Habkost

If a given machine have max_cpus set, not just smp_cpus needs to be limited, but the total number of CPUs (considering CPU hotplug) for the machine.

As smp_parse() already ensures smp_cpus <= max_cpus, we just need to check if max_cpus exceeds the limit.

---
 vl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
vl.c +0 -0
index 236f95e..e317cc9 100644
@@ -4039,9 +4039,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));

vl.c int main(int argc, char **argv, char **envp) · line 4046

Quoted 10 lines
vl.c +3 -3
 
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+    if (max_cpus > machine->max_cpus) {
+        fprintf(stderr, "Total number of CPUs (%d), exceeds maximum "
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);

This is confusing. What is max_cpus and why do we not just set max_cpus = machine->max_cpus ?

thanks
-- PMM

#2 lore raw

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 20 lines · Eduardo Habkost
Quoted 19 lines

If a given machine have max_cpus set, not just smp_cpus needs to be limited, but the total number of CPUs (considering CPU hotplug) for the machine.

As smp_parse() already ensures smp_cpus <= max_cpus, we just need to check if max_cpus exceeds the limit.

---
 vl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
vl.c +0 -0
index 236f95e..e317cc9 100644
@@ -4039,9 +4039,9 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
Quoted 12 lines

vl.c int main(int argc, char **argv, char **envp) · line 4046

Quoted 9 lines
vl.c +3 -3
     machine->max_cpus = machine->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,  machine->name,
+    if (max_cpus > machine->max_cpus) {
+        fprintf(stderr, "Total number of CPUs (%d), exceeds maximum "
+                "supported by machine `%s' (%d)\n", max_cpus,  machine->name,
                 machine->max_cpus);
         exit(1);

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

Quoted 2 lines

and why do we not
just set max_cpus = machine->max_cpus ?

For the PC, machine->max_cpus specifies the technical (APIC/ACPI/...) upper limit, whereas -smp limits it to saner values.

If you think KVM, then many machines today will have less than the maximum number of CPUs and you may want to run multiple VMs and you may not want their vCPUs competing too much for existing CPUs, so a limit makes sense.

An interesting question for the 2.x era would be whether we may want to change the default from no hot-add to machine maximum - does recent libvirt specify max_cpus by default?

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 4 lines · Andreas Färber

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 1 line

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

I thought that was smp_cpus ...

Quoted 10 lines
Quoted 2 lines

and why do we not
just set max_cpus = machine->max_cpus ?

For the PC, machine->max_cpus specifies the technical (APIC/ACPI/...) upper limit, whereas -smp limits it to saner values.

If you think KVM, then many machines today will have less than the maximum number of CPUs and you may want to run multiple VMs and you may not want their vCPUs competing too much for existing CPUs, so a limit makes sense.

That would imply that we want
max_cpus = MIN(command_line_max_cpus, machine->max_cpus);

thanks
-- PMM

#4 lore raw
Quoted 7 lines · Peter Maydell
Quoted 4 lines · Andreas Färber

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 1 line

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

I thought that was smp_cpus ...

smp_cpus is the first argument to -smp. max_cpus is the "maxcpus" option of -smp.

Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

and why do we not
just set max_cpus = machine->max_cpus ?

For the PC, machine->max_cpus specifies the technical (APIC/ACPI/...) upper limit, whereas -smp limits it to saner values.

Quoted 7 lines
Quoted 4 lines

If you think KVM, then many machines today will have less than the maximum number of CPUs and you may want to run multiple VMs and you may not want their vCPUs competing too much for existing CPUs, so a limit makes sense.

That would imply that we want
max_cpus = MIN(command_line_max_cpus, machine->max_cpus);

Please don't do this. If the maxcpus value from the command-line is not supported, QEMU should abort instead of silently ignoring the value provided by the user.

Signature · 1 line
Eduardo
#5 lore raw
Quoted 7 lines · Eduardo Habkost
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Andreas Färber

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 1 line

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

Quoted 8 lines
Quoted 1 line

I thought that was smp_cpus ...

smp_cpus is the first argument to -smp. max_cpus is the "maxcpus" option of -smp.

Please don't do this. If the maxcpus value from the command-line is not supported, QEMU should abort instead of silently ignoring the value provided by the user.

Ah, I see. This code is confusing because we've split the handling of user errors in the -smp argument between the smp_parse() function and this bit of inline code. Ideally we should put all the error handling in one place...

thanks
-- PMM

#6 lore raw
Quoted 17 lines · Peter Maydell
Quoted 7 lines · Eduardo Habkost
Quoted 6 lines · Peter Maydell
Quoted 4 lines · Andreas Färber

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 1 line

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

Quoted 8 lines
Quoted 1 line

I thought that was smp_cpus ...

smp_cpus is the first argument to -smp. max_cpus is the "maxcpus" option of -smp.

Please don't do this. If the maxcpus value from the command-line is not supported, QEMU should abort instead of silently ignoring the value provided by the user.

Quoted 5 lines

Ah, I see. This code is confusing because we've split the handling of user errors in the -smp argument between the smp_parse() function and this bit of inline code. Ideally we should put all the error handling in one place...

The split makes sense to me: smp_parse() is just for basic parsing that doesn't depend on any state other than the provided QemuOpts parameter, and can run at any point in time.

The machine->max_cpus check, on the other hand depend on the machine object to be created, and even changes the machine->max_cpus value. It is more dependent on ordering of initialization. To me, it makes sense to have it outside smp_parse().

But while looking at that code, I noticed that we can at least make the MAX_CPUMASK_BITS check and the machine->max_cpus check a single one. I will send a new patch.

Signature · 1 line
Eduardo
#7 lore raw
In reply to Peter Maydell

Am 08.05.2014 10:26, schrieb Peter Maydell:

Quoted 7 lines · Andreas Färber
Quoted 4 lines

Am 07.05.2014 23:48, schrieb Peter Maydell:

Quoted 1 line

This is confusing. What is max_cpus

Specified via -smp, defaults to actual CPUs.

I thought that was smp_cpus ...

smp_cpus determines how many CPUs are cold-added in a loop in the machine init functions.

max_cpus - smp_cpus is the amount of CPUs that may be hot-added later.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg