Skip to contentSkip to conversation

vl: verify if combination of cpus, sockets, cores and threads is sane

PATCH In review Peter Lieven 3 participants 5 messages Nov 21, 2013 – Nov 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl: verify if combination of cpus, sockets, cores and threads is sane

---
 vl.c |   34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
vl.c +20 -14
index 8d5d874..dc0b41a 100644
@@ -1385,35 +1385,41 @@ static QemuOptsList qemu_smp_opts = {
 static void smp_parse(QemuOpts *opts)
 {
     if (opts) {
-
         unsigned cpus    = qemu_opt_get_number(opts, "cpus", 0);
         unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
         unsigned cores   = qemu_opt_get_number(opts, "cores", 0);
         unsigned threads = qemu_opt_get_number(opts, "threads", 0);
 
         /* compute missing values, prefer sockets over cores over threads */
-        if (cpus == 0 || sockets == 0) {
+        if (cpus == 0) {
             sockets = sockets > 0 ? sockets : 1;
             cores = cores > 0 ? cores : 1;
             threads = threads > 0 ? threads : 1;
-            if (cpus == 0) {
-                cpus = cores * threads * sockets;
-            }
+            cpus = cores * threads * sockets;
+        } else if (sockets == 0) {
+            cores = cores > 0 ? cores : 1;
+            threads = threads > 0 ? threads : 1;
+            sockets = cpus / (cores * threads);
+        } else if (cores == 0) {
+            threads = threads > 0 ? threads : 1;
+            cores = cpus / (sockets * threads);
         } else {
-            if (cores == 0) {
-                threads = threads > 0 ? threads : 1;
-                cores = cpus / (sockets * threads);
-            } else {
-                threads = cpus / (cores * sockets);
-            }
+            threads = cpus / (sockets * cores);
         }
 
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        if (cpus != sockets * cores * threads) {
+            fprintf(stderr, "Illegal CPU layout: %d cpus with %d sockets,"
+                            " %d cores per socket and %d threads per core"
+                            " (cpus != sockets * cores * threads)\n",
+                            cpus, sockets, cores, threads);
+            exit(1);
+        }
 
         smp_cpus = cpus;
-        smp_cores = cores > 0 ? cores : 1;
-        smp_threads = threads > 0 ? threads : 1;
+        smp_cores = cores;
+        smp_threads = threads;
 
+        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
     }
 
     if (max_cpus == 0) {
Signature · 1 line
1.7.9.5
#1 lore raw

Il 21/11/2013 15:37, Peter Lieven ha scritto:

vl.c static QemuOptsList qemu_smp_opts = { · line 1416

Quoted 8 lines
vl.c +7 -1
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        if (cpus != sockets * cores * threads) {
+            fprintf(stderr, "Illegal CPU layout: %d cpus with %d sockets,"
+                            " %d cores per socket and %d threads per core"
+                            " (cpus != sockets * cores * threads)\n",
+                            cpus, sockets, cores, threads);
+            exit(1);
+        }

Should max_cpus be checked instead if non-zero?

I see where you come from, but I think the potential for this patch to break some working configuration (for some definition of working) is too high. Can you split out the fixes to the "fill in the blanks" logic?

Paolo

#2 lore raw
Quoted 9 lines · Paolo Bonzini

Il 21/11/2013 15:37, Peter Lieven ha scritto:

vl.c static QemuOptsList qemu_smp_opts = { · line 1416

Quoted 8 lines
vl.c +7 -1
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+        if (cpus != sockets * cores * threads) {
+            fprintf(stderr, "Illegal CPU layout: %d cpus with %d sockets,"
+                            " %d cores per socket and %d threads per core"
+                            " (cpus != sockets * cores * threads)\n",
+                            cpus, sockets, cores, threads);
+            exit(1);
+        }
Quoted 5 lines

Should max_cpus be checked instead if non-zero?

I see where you come from, but I think the potential for this patch to break some working configuration (for some definition of working) is too high. Can you split out the fixes to the "fill in the blanks" logic?

I can, but the number of sockets is logal to the parse function.

What would you think is it okay to just send a warning about the illegal config and drop the exit(1).

Peter

#3 lore raw

Il 22/11/2013 12:13, Peter Lieven ha scritto:

Quoted 5 lines
Quoted 3 lines

I see where you come from, but I think the potential for this patch to break some working configuration (for some definition of working) is too high. Can you split out the fixes to the "fill in the blanks" logic?

I can, but the number of sockets is logal to the parse function.

Not sure why that matters, just make two patches instead of one.

Quoted 2 lines

What would you think is it okay to just send a warning about the illegal config and drop the exit(1).

Yes, that would be okay.

Paolo

#4 lore raw

Am 22.11.2013 12:20, schrieb Paolo Bonzini:

Quoted 8 lines

Il 22/11/2013 12:13, Peter Lieven ha scritto:

Quoted 5 lines
Quoted 3 lines

I see where you come from, but I think the potential for this patch to break some working configuration (for some definition of working) is too high. Can you split out the fixes to the "fill in the blanks" logic?

I can, but the number of sockets is logal to the parse function.

Not sure why that matters, just make two patches instead of one.

...and please CC me and possibly Eduardo who refactored it last IIRC.

Andreas

Quoted 6 lines
Quoted 2 lines

What would you think is it okay to just send a warning about the illegal config and drop the exit(1).

Yes, that would be okay.

Paolo

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