mirror of https://github.com/xemu-project/xemu.git
machine: pass QAPI struct to mc->smp_parse
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. Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20210617155308.928754-10-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
abc2f51144
commit
1e63fe6858
|
@ -739,12 +739,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 cpus = config->has_cpus ? config->cpus : 0;
|
||||||
unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
|
unsigned sockets = config->has_sockets ? config->sockets : 0;
|
||||||
unsigned cores = qemu_opt_get_number(opts, "cores", 0);
|
unsigned cores = config->has_cores ? config->cores : 0;
|
||||||
unsigned threads = qemu_opt_get_number(opts, "threads", 0);
|
unsigned threads = config->has_threads ? config->threads : 0;
|
||||||
|
|
||||||
/* compute missing values, prefer sockets over cores over threads */
|
/* compute missing values, prefer sockets over cores over threads */
|
||||||
if (cpus == 0 || sockets == 0) {
|
if (cpus == 0 || sockets == 0) {
|
||||||
|
@ -754,8 +754,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||||
sockets = sockets > 0 ? sockets : 1;
|
sockets = sockets > 0 ? sockets : 1;
|
||||||
cpus = cores * threads * sockets;
|
cpus = cores * threads * sockets;
|
||||||
} else {
|
} else {
|
||||||
ms->smp.max_cpus =
|
ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
|
||||||
qemu_opt_get_number(opts, "maxcpus", cpus);
|
|
||||||
sockets = ms->smp.max_cpus / (cores * threads);
|
sockets = ms->smp.max_cpus / (cores * threads);
|
||||||
}
|
}
|
||||||
} else if (cores == 0) {
|
} else if (cores == 0) {
|
||||||
|
@ -773,8 +772,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ms->smp.max_cpus =
|
ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
|
||||||
qemu_opt_get_number(opts, "maxcpus", cpus);
|
|
||||||
|
|
||||||
if (ms->smp.max_cpus < cpus) {
|
if (ms->smp.max_cpus < cpus) {
|
||||||
error_setg(errp, "maxcpus must be equal to or greater than smp");
|
error_setg(errp, "maxcpus must be equal to or greater than smp");
|
||||||
|
@ -1129,7 +1127,22 @@ bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||||
ERRP_GUARD();
|
ERRP_GUARD();
|
||||||
|
|
||||||
if (opts) {
|
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) {
|
if (*errp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
18
hw/i386/pc.c
18
hw/i386/pc.c
|
@ -710,13 +710,13 @@ void pc_acpi_smi_interrupt(void *opaque, int irq, int level)
|
||||||
* This function is very similar to smp_parse()
|
* This function is very similar to smp_parse()
|
||||||
* in hw/core/machine.c but includes CPU die support.
|
* 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 cpus = config->has_cpus ? config->cpus : 0;
|
||||||
unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
|
unsigned sockets = config->has_sockets ? config->sockets : 0;
|
||||||
unsigned dies = qemu_opt_get_number(opts, "dies", 1);
|
unsigned dies = config->has_dies ? config->dies : 1;
|
||||||
unsigned cores = qemu_opt_get_number(opts, "cores", 0);
|
unsigned cores = config->has_cores ? config->cores : 0;
|
||||||
unsigned threads = qemu_opt_get_number(opts, "threads", 0);
|
unsigned threads = config->has_threads ? config->threads : 0;
|
||||||
|
|
||||||
/* compute missing values, prefer sockets over cores over threads */
|
/* compute missing values, prefer sockets over cores over threads */
|
||||||
if (cpus == 0 || sockets == 0) {
|
if (cpus == 0 || sockets == 0) {
|
||||||
|
@ -726,8 +726,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||||
sockets = sockets > 0 ? sockets : 1;
|
sockets = sockets > 0 ? sockets : 1;
|
||||||
cpus = cores * threads * dies * sockets;
|
cpus = cores * threads * dies * sockets;
|
||||||
} else {
|
} else {
|
||||||
ms->smp.max_cpus =
|
ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
|
||||||
qemu_opt_get_number(opts, "maxcpus", cpus);
|
|
||||||
sockets = ms->smp.max_cpus / (cores * threads * dies);
|
sockets = ms->smp.max_cpus / (cores * threads * dies);
|
||||||
}
|
}
|
||||||
} else if (cores == 0) {
|
} else if (cores == 0) {
|
||||||
|
@ -745,8 +744,7 @@ static void pc_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ms->smp.max_cpus =
|
ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus;
|
||||||
qemu_opt_get_number(opts, "maxcpus", cpus);
|
|
||||||
|
|
||||||
if (ms->smp.max_cpus < cpus) {
|
if (ms->smp.max_cpus < cpus) {
|
||||||
error_setg(errp, "maxcpus must be equal to or greater than smp");
|
error_setg(errp, "maxcpus must be equal to or greater than smp");
|
||||||
|
|
|
@ -210,7 +210,7 @@ struct MachineClass {
|
||||||
void (*reset)(MachineState *state);
|
void (*reset)(MachineState *state);
|
||||||
void (*wakeup)(MachineState *state);
|
void (*wakeup)(MachineState *state);
|
||||||
int (*kvm_type)(MachineState *machine, const char *arg);
|
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;
|
BlockInterfaceType block_default_type;
|
||||||
int units_per_default_bus;
|
int units_per_default_bus;
|
||||||
|
|
|
@ -1284,3 +1284,31 @@
|
||||||
##
|
##
|
||||||
{ 'event': 'MEM_UNPLUG_ERROR',
|
{ 'event': 'MEM_UNPLUG_ERROR',
|
||||||
'data': { 'device': 'str', 'msg': 'str' } }
|
'data': { 'device': 'str', 'msg': 'str' } }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @SMPConfiguration:
|
||||||
|
#
|
||||||
|
# Schema for CPU topology configuration. "0" or a missing value lets
|
||||||
|
# QEMU figure out a suitable value based on the ones that are provided.
|
||||||
|
#
|
||||||
|
# @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' } }
|
||||||
|
|
Loading…
Reference in New Issue