[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 04/14] machine: Set the value of cpus to match maxcpus if it's
From: |
Yanan Wang |
Subject: |
[PATCH v8 04/14] machine: Set the value of cpus to match maxcpus if it's omitted |
Date: |
Thu, 2 Sep 2021 19:03:20 +0800 |
Currently we directly calculate the omitted cpus based on the given
incomplete collection of 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 set the value of cpus to match maxcpus
if it's omitted, which will make above configs start to work.
So the calculation logic of cpus/maxcpus after this patch will be:
When both maxcpus and cpus are omitted, maxcpus will be calculated
from the given parameters and cpus will be set equal to maxcpus.
When only one of maxcpus and cpus is given then the omitted one
will be set to its counterpart's value. Both maxcpus and cpus may
be specified, but maxcpus must be equal to or greater than cpus.
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 <wangyanan55@huawei.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
---
hw/core/machine.c | 29 ++++++++++++++++-------------
hw/i386/pc.c | 29 ++++++++++++++++-------------
qemu-options.hx | 11 ++++++++---
3 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 56bd3033a5..fe935cb4a3 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -760,25 +760,28 @@ static void smp_parse(MachineState *ms, SMPConfiguration
*config, Error **errp)
}
/* compute missing values, prefer sockets over cores over threads */
- maxcpus = maxcpus > 0 ? maxcpus : cpus;
-
- if (cpus == 0) {
+ if (cpus == 0 && maxcpus == 0) {
sockets = sockets > 0 ? sockets : 1;
cores = cores > 0 ? cores : 1;
threads = threads > 0 ? threads : 1;
- cpus = sockets * cores * threads;
+ } else {
maxcpus = maxcpus > 0 ? maxcpus : cpus;
- } else if (sockets == 0) {
- cores = cores > 0 ? cores : 1;
- threads = threads > 0 ? threads : 1;
- sockets = maxcpus / (cores * threads);
- } else if (cores == 0) {
- threads = threads > 0 ? threads : 1;
- cores = maxcpus / (sockets * threads);
- } else if (threads == 0) {
- threads = maxcpus / (sockets * cores);
+
+ if (sockets == 0) {
+ cores = cores > 0 ? cores : 1;
+ threads = threads > 0 ? threads : 1;
+ sockets = maxcpus / (cores * threads);
+ } else if (cores == 0) {
+ threads = threads > 0 ? threads : 1;
+ cores = maxcpus / (sockets * threads);
+ } else if (threads == 0) {
+ threads = maxcpus / (sockets * cores);
+ }
}
+ maxcpus = maxcpus > 0 ? maxcpus : sockets * cores * threads;
+ cpus = cpus > 0 ? cpus : maxcpus;
+
if (sockets * cores * threads < cpus) {
error_setg(errp, "cpu topology: "
"sockets (%u) * cores (%u) * threads (%u) < "
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 4b67c49f38..cf75fa5c7a 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -727,25 +727,28 @@ static void pc_smp_parse(MachineState *ms,
SMPConfiguration *config, Error **err
dies = dies > 0 ? dies : 1;
/* compute missing values, prefer sockets over cores over threads */
- maxcpus = maxcpus > 0 ? maxcpus : cpus;
-
- if (cpus == 0) {
+ if (cpus == 0 && maxcpus == 0) {
sockets = sockets > 0 ? sockets : 1;
cores = cores > 0 ? cores : 1;
threads = threads > 0 ? threads : 1;
- cpus = sockets * dies * cores * threads;
+ } else {
maxcpus = maxcpus > 0 ? maxcpus : cpus;
- } else if (sockets == 0) {
- cores = cores > 0 ? cores : 1;
- threads = threads > 0 ? threads : 1;
- sockets = maxcpus / (dies * cores * threads);
- } else if (cores == 0) {
- threads = threads > 0 ? threads : 1;
- cores = maxcpus / (sockets * dies * threads);
- } else if (threads == 0) {
- threads = maxcpus / (sockets * dies * cores);
+
+ if (sockets == 0) {
+ cores = cores > 0 ? cores : 1;
+ threads = threads > 0 ? threads : 1;
+ sockets = maxcpus / (dies * cores * threads);
+ } else if (cores == 0) {
+ threads = threads > 0 ? threads : 1;
+ cores = maxcpus / (sockets * dies * threads);
+ } else if (threads == 0) {
+ threads = maxcpus / (sockets * dies * cores);
+ }
}
+ maxcpus = maxcpus > 0 ? maxcpus : sockets * dies * cores * threads;
+ cpus = cpus > 0 ? cpus : maxcpus;
+
if (sockets * dies * cores * threads < cpus) {
error_setg(errp, "cpu topology: "
"sockets (%u) * dies (%u) * cores (%u) * threads (%u) < "
diff --git a/qemu-options.hx b/qemu-options.hx
index aee622f577..06f819177e 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -214,9 +214,14 @@ SRST
Simulate a SMP system with '\ ``n``\ ' CPUs initially present on
the machine type board. On boards supporting CPU hotplug, the optional
'\ ``maxcpus``\ ' parameter can be set to enable further CPUs to be
- added at runtime. If omitted the maximum number of CPUs will be
- set to match the initial CPU count. Both parameters are subject to
- an upper limit that is determined by the specific machine type chosen.
+ added at runtime. When both parameters are omitted, the maximum number
+ of CPUs will be calculated from the provided topology members and the
+ initial CPU count will match the maximum number. When only one of them
+ is given then the omitted one will be set to its counterpart's value.
+ Both parameters may be specified, but the maximum number of CPUs must
+ be equal to or greater than the initial CPU count. Both parameters are
+ subject to an upper limit that is determined by the specific machine
+ type chosen.
To control reporting of CPU topology information, the number of sockets,
dies per socket, cores per die, and threads per core can be specified.
--
2.19.1
- [PATCH v8 01/14] machine: Deprecate "parameter=0" SMP configurations, (continued)
- [PATCH v8 01/14] machine: Deprecate "parameter=0" SMP configurations, Yanan Wang, 2021/09/02
- [PATCH v8 06/14] machine: Prefer cores over sockets in smp parsing since 6.2, Yanan Wang, 2021/09/02
- [PATCH v8 08/14] machine: Tweak the order of topology members in struct CpuTopology, Yanan Wang, 2021/09/02
- [PATCH v8 10/14] machine: Remove smp_parse callback from MachineClass, Yanan Wang, 2021/09/02
- [PATCH v8 03/14] machine: Uniformly use maxcpus to calculate the omitted parameters, Yanan Wang, 2021/09/02
- [PATCH v8 02/14] machine: Minor refactor/fix for the smp parsers, Yanan Wang, 2021/09/02
- [PATCH v8 05/14] machine: Improve the error reporting of smp parsing, Yanan Wang, 2021/09/02
- [PATCH v8 07/14] machine: Use ms instead of global current_machine in sanity-check, Yanan Wang, 2021/09/02
- [PATCH v8 12/14] machine: Put all sanity-check in the generic SMP parser, Yanan Wang, 2021/09/02
- [PATCH v8 14/14] tests/unit: Add a unit test for smp parsing, Yanan Wang, 2021/09/02
- [PATCH v8 04/14] machine: Set the value of cpus to match maxcpus if it's omitted,
Yanan Wang <=
- [PATCH v8 11/14] machine: Move smp_prefer_sockets to struct SMPCompatProps, Yanan Wang, 2021/09/02
- [PATCH v8 09/14] machine: Make smp_parse generic enough for all arches, Yanan Wang, 2021/09/02
- [PATCH v8 13/14] machine: Split out the smp parsing code, Yanan Wang, 2021/09/02