[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 12/14] machine: pass QAPI struct to mc->smp_parse
From: |
Paolo Bonzini |
Subject: |
[PATCH 12/14] machine: pass QAPI struct to mc->smp_parse |
Date: |
Thu, 13 May 2021 12:28:59 -0400 |
As part of converting -smp to a property with a QAPI type, define
the struct and use it to do the actual parsing. machine_smp_parse
takes care of doing the QemuOpts->QAPI conversion by hand, for now.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/core/machine.c | 33 +++++++++++++++++++++++----------
hw/i386/pc.c | 18 ++++++++----------
include/hw/boards.h | 2 +-
qapi/machine.json | 27 +++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 21 deletions(-)
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 70c297a7de..7daca0b86a 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -738,12 +738,12 @@ void machine_set_cpu_numa_node(MachineState *machine,
}
}
-static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
+static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp)
{
- 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);
+ unsigned cpus = config->has_cpus ? config->cpus : 0;
+ unsigned sockets = config->has_sockets ? config->sockets : 0;
+ unsigned cores = config->has_cores ? config->cores : 0;
+ unsigned threads = config->has_threads ? config->threads : 0;
/* compute missing values, prefer sockets over cores over threads */
if (cpus == 0 || sockets == 0) {
@@ -753,8 +753,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,
Error **errp)
sockets = sockets > 0 ? sockets : 1;
cpus = cores * threads * sockets;
} else {
- ms->smp.max_cpus =
- qemu_opt_get_number(opts, "maxcpus", cpus);
+ ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
sockets = ms->smp.max_cpus / (cores * threads);
}
} else if (cores == 0) {
@@ -772,8 +771,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts,
Error **errp)
return;
}
- ms->smp.max_cpus =
- qemu_opt_get_number(opts, "maxcpus", cpus);
+ ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
if (ms->smp.max_cpus < cpus) {
error_setg(errp, "maxcpus must be equal to or greater than smp");
@@ -1128,7 +1126,22 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *opts,
Error **errp)
ERRP_GUARD();
if (opts) {
- mc->smp_parse(ms, opts, errp);
+ SMPConfiguration config = {
+ .has_cpus = !!qemu_opt_get(opts, "cpus"),
+ .cpus = qemu_opt_get_number(opts, "cpus", 0),
+ .has_sockets = !!qemu_opt_get(opts, "sockets"),
+ .sockets = qemu_opt_get_number(opts, "sockets", 0),
+ .has_dies = !!qemu_opt_get(opts, "dies"),
+ .dies = qemu_opt_get_number(opts, "dies", 0),
+ .has_cores = !!qemu_opt_get(opts, "cores"),
+ .cores = qemu_opt_get_number(opts, "cores", 0),
+ .has_threads = !!qemu_opt_get(opts, "threads"),
+ .threads = qemu_opt_get_number(opts, "threads", 0),
+ .has_maxcpus = !!qemu_opt_get(opts, "maxcpus"),
+ .maxcpus = qemu_opt_get_number(opts, "maxcpus", 0),
+ };
+
+ mc->smp_parse(ms, &config, errp);
if (*errp) {
return false;
}
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1760e94ff5..14ed30bb78 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -706,13 +706,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int
level)
* This function is very similar to smp_parse()
* in hw/core/machine.c but includes CPU die support.
*/
-static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
+static void pc_smp_parse(MachineState *ms, SMPConfiguration *config, Error
**errp)
{
- unsigned cpus = qemu_opt_get_number(opts, "cpus", 0);
- unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
- unsigned dies = qemu_opt_get_number(opts, "dies", 1);
- unsigned cores = qemu_opt_get_number(opts, "cores", 0);
- unsigned threads = qemu_opt_get_number(opts, "threads", 0);
+ unsigned cpus = config->has_cpus ? config->cpus : 0;
+ unsigned sockets = config->has_sockets ? config->sockets : 0;
+ unsigned dies = config->has_dies ? config->dies : 1;
+ unsigned cores = config->has_cores ? config->cores : 0;
+ unsigned threads = config->has_threads ? config->threads : 0;
/* compute missing values, prefer sockets over cores over threads */
if (cpus == 0 || sockets == 0) {
@@ -722,8 +722,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts,
Error **errp)
sockets = sockets > 0 ? sockets : 1;
cpus = cores * threads * dies * sockets;
} else {
- ms->smp.max_cpus =
- qemu_opt_get_number(opts, "maxcpus", cpus);
+ ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
sockets = ms->smp.max_cpus / (cores * threads * dies);
}
} else if (cores == 0) {
@@ -741,8 +740,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts,
Error **errp)
return;
}
- ms->smp.max_cpus =
- qemu_opt_get_number(opts, "maxcpus", cpus);
+ ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
if (ms->smp.max_cpus < cpus) {
error_setg(errp, "maxcpus must be equal to or greater than smp");
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 0483d6af86..1eae4427e8 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -210,7 +210,7 @@ struct MachineClass {
void (*reset)(MachineState *state);
void (*wakeup)(MachineState *state);
int (*kvm_type)(MachineState *machine, const char *arg);
- void (*smp_parse)(MachineState *ms, QemuOpts *opts, Error **errp);
+ void (*smp_parse)(MachineState *ms, SMPConfiguration *config, Error
**errp);
BlockInterfaceType block_default_type;
int units_per_default_bus;
diff --git a/qapi/machine.json b/qapi/machine.json
index 6e90d463fc..3a6a21fd01 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -1274,3 +1274,30 @@
##
{ 'event': 'MEM_UNPLUG_ERROR',
'data': { 'device': 'str', 'msg': 'str' } }
+
+##
+# @SMPConfiguration:
+#
+# Schema for CPU topology configuration.
+#
+# @cpus: number of virtual CPUs in the virtual machine
+#
+# @sockets: number of sockets in the CPU topology
+#
+# @dies: number of dies per socket in the CPU topology
+#
+# @cores: number of cores per thread in the CPU topology
+#
+# @threads: number of threads per core in the CPU topology
+#
+# @maxcpus: maximum number of hotpluggable virtual CPUs in the virtual machine
+#
+# Since: 6.1
+##
+{ 'struct': 'SMPConfiguration', 'data': {
+ '*cpus': 'int',
+ '*sockets': 'int',
+ '*dies': 'int',
+ '*cores': 'int',
+ '*threads': 'int',
+ '*maxcpus': 'int' } }
--
2.26.2
- [PATCH 09/14] machine: move dies from X86MachineState to CpuTopology, (continued)
- [PATCH 09/14] machine: move dies from X86MachineState to CpuTopology, Paolo Bonzini, 2021/05/13
- [PATCH 08/14] vl: switch -accel parsing to keyval, Paolo Bonzini, 2021/05/13
- [PATCH 07/14] qemu-option: remove now-dead code, Paolo Bonzini, 2021/05/13
- [PATCH 06/14] vl: switch -M parsing to keyval, Paolo Bonzini, 2021/05/13
- [PATCH 02/14] qemu-config: parse configuration files to a QDict, Paolo Bonzini, 2021/05/13
- [PATCH 04/14] qom: export more functions for use with non-UserCreatable objects, Paolo Bonzini, 2021/05/13
- [PATCH 14/14] machine: add smp compound property, Paolo Bonzini, 2021/05/13
- [PATCH 13/14] machine: reject -smp dies!=1 for non-PC machines, Paolo Bonzini, 2021/05/13
- [PATCH 10/14] machine: move common smp_parse code to caller, Paolo Bonzini, 2021/05/13
- [PATCH 12/14] machine: pass QAPI struct to mc->smp_parse,
Paolo Bonzini <=
- [PATCH 11/14] machine: add error propagation to mc->smp_parse, Paolo Bonzini, 2021/05/13
- Re: [PATCH 00/14] vl: compound properties for machines and accelerators, no-reply, 2021/05/13