Currently we directly calculate the omitted cpus based on the already
provided parameters. This makes some cmdlines like:
  -smp maxcpus=16
  -smp sockets=2,maxcpus=16
  -smp sockets=2,dies=2,maxcpus=16
  -smp sockets=2,cores=4,maxcpus=16
not work. We should probably use the computed paramters to calculate
cpus when maxcpus is provided while cpus is omitted, which will make
above configs start to work.

Note: change in this patch won't affect any existing working cmdlines
but allows more incomplete configs to be valid.

Signed-off-by: Yanan Wang <wangyana...@huawei.com>
---
 hw/core/machine.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index c9f15b15a5..668f0a1553 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -767,26 +767,27 @@ static void smp_parse(MachineState *ms, SMPConfiguration 
*config, Error **errp)
         return;
     }
 
-    /* compute missing values, prefer sockets over cores over threads */
     maxcpus = maxcpus > 0 ? maxcpus : cpus;
 
-    if (cpus == 0) {
-        sockets = sockets > 0 ? sockets : 1;
-        cores = cores > 0 ? cores : 1;
-        threads = threads > 0 ? threads : 1;
-        cpus = sockets * dies * cores * threads;
-        maxcpus = maxcpus > 0 ? maxcpus : cpus;
-    } else if (sockets == 0) {
+    /* compute missing values, prefer sockets over cores over threads */
+    if (sockets == 0) {
         cores = cores > 0 ? cores : 1;
         threads = threads > 0 ? threads : 1;
         sockets = maxcpus / (dies * cores * threads);
+        sockets = sockets > 0 ? sockets : 1;
     } else if (cores == 0) {
         threads = threads > 0 ? threads : 1;
         cores = maxcpus / (sockets * dies * threads);
+        cores = cores > 0 ? cores : 1;
     } else if (threads == 0) {
         threads = maxcpus / (sockets * dies * cores);
+        threads = threads > 0 ? threads : 1;
     }
 
+    /* use the computed parameters to calculate the omitted cpus */
+    cpus = cpus > 0 ? cpus : sockets * dies * cores * threads;
+    maxcpus = maxcpus > 0 ? maxcpus : cpus;
+
     if (sockets * dies * cores * threads < cpus) {
         g_autofree char *dies_msg = g_strdup_printf(
             mc->smp_dies_supported ? " * dies (%u)" : "", dies);
-- 
2.19.1


Reply via email to