TCG/ARM fixes for 2.11
Subsystems (2)
cover TCG/ARM fixes for 2.11
Some MachineClass changes to fix TCG initialization of some ARM boards for 2.11. This was originally reported by Thomas Huth in [1], where Peter suggested a way to fix it. Further discussion in another thread [2] followed up on this.
As a result of that follow-up discussion we also got some Zynq changes from Alistair [3], which I'm including here since in order to test them we need the first patch in this series.
Thanks,
Emilio
[1] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg00078.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg00502.html
[3] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg01842.html
Alistair Francis (2):
xlnx-zynqmp: Properly support the smp command line option
xlnx-zcu102: Add an info message deprecating the EP108
Emilio G. Cota (3):
qom: move CPUClass.tcg_initialize to a global
xlnx-zcu102: Specify the max number of CPUs for the EP108
hw: add .min_cpus and .default_cpus fields to machine_class
qemu-doc.texi | 7 +++++++ include/hw/boards.h | 5 +++++ include/qom/cpu.h | 1 - exec.c | 5 +++-- hw/arm/exynos4_boards.c | 12 ++++-------- hw/arm/raspi.c | 2 ++ hw/arm/xlnx-zcu102.c | 9 ++++++++- hw/arm/xlnx-zynqmp.c | 26 ++++++++++++++++---------- vl.c | 21 ++++++++++++++++++--- 9 files changed, 63 insertions(+), 25 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 qom: move CPUClass.tcg_initialize to a global
55c3cee ("qom: Introduce CPUClass.tcg_initialize", 2017-10-24) introduces a per-CPUClass bool that we check so that the target CPU is initialized for TCG only once. This works well except when we end up creating more than one CPUClass, in which case we end up incorrectly initializing TCG more than once, i.e. once for each CPUClass.
This can be replicated with:
$ aarch64-softmmu/qemu-system-aarch64 -machine xlnx-zcu102 -smp 6 \
-global driver=xlnx,,zynqmp,property=has_rpu,value=on
In this case the class name of the "RPUs" is prefixed by "cortex-r5-",
whereas the "regular" CPUs are prefixed by "cortex-a53-". This
results in two CPUClass instances being created.Fix it by introducing a static variable, so that only the first target CPU being initialized will initialize the target-dependent part of TCG, regardless of CPUClass instances.
--- include/qom/cpu.h | 1 - exec.c | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/qom/cpu.h +0 -1
@@ -209,7 +209,6 @@ typedef struct CPUClass {/* Keep non-pointer data at the end to minimize holes. */ int gdb_num_core_regs;bool gdb_stop_before_watchpoint; -bool tcg_initialized; } CPUClass;#ifdef HOST_WORDS_BIGENDIAN
exec.c +3 -2
@@ -792,11 +792,12 @@ void cpu_exec_initfn(CPUState *cpu)void cpu_exec_realizefn (CPUState *cpu,Error **errp) {CPUClass *cc =CPU_GET_CLASS (cpu); +static bool tcg_target_initialized;cpu_list_add (cpu); -if (tcg_enabled () && !cc->tcg_initialized) { - cc->tcg_initialized = true; +if (tcg_enabled () && !tcg_target_initialized) { + tcg_target_initialized = true; cc->tcg_initialize (); }
Signature · 1 line
2.7.4
Re: [Qemu-arm] [PATCH for 2.11 1/5] qom: move CPUClass.tcg_initialize to a global
Quoted 14 lines · Emilio G. Cota
55c3cee ("qom: Introduce CPUClass.tcg_initialize", 2017-10-24) introduces a per-CPUClass bool that we check so that the target CPU is initialized for TCG only once. This works well except when we end up creating more than one CPUClass, in which case we end up incorrectly initializing TCG more than once, i.e. once for each CPUClass.
This can be replicated with:
$ aarch64-softmmu/qemu-system-aarch64 -machine xlnx-zcu102 -smp 6 \ -global driver=xlnx,,zynqmp,property=has_rpu,value=on In this case the class name of the "RPUs" is prefixed by "cortex-r5-", whereas the "regular" CPUs are prefixed by "cortex-a53-". This results in two CPUClass instances being created.
Quoted 6 lines
Fix it by introducing a static variable, so that only the first target CPU being initialized will initialize the target-dependent part of TCG, regardless of CPUClass instances.
Fixes 55c3ceef61fcf06fc98ddc752b7cce788ce7680bSigned-off-by Emilio G. Cota <[email protected]>
Signature · 1 line
Eduardo
Re: [Qemu-arm] [Qemu-devel] [PATCH for 2.11 1/5] qom: move CPUClass.tcg_initialize to a global
Quoted 15 lines · Eduardo Habkost
Quoted 14 lines · Emilio G. Cota
55c3cee ("qom: Introduce CPUClass.tcg_initialize", 2017-10-24) introduces a per-CPUClass bool that we check so that the target CPU is initialized for TCG only once. This works well except when we end up creating more than one CPUClass, in which case we end up incorrectly initializing TCG more than once, i.e. once for each CPUClass.
This can be replicated with:
$ aarch64-softmmu/qemu-system-aarch64 -machine xlnx-zcu102 -smp 6 \ -global driver=xlnx,,zynqmp,property=has_rpu,value=on In this case the class name of the "RPUs" is prefixed by "cortex-r5-", whereas the "regular" CPUs are prefixed by "cortex-a53-". This results in two CPUClass instances being created.
Quoted 8 lines
Quoted 6 lines
Fix it by introducing a static variable, so that only the first target CPU being initialized will initialize the target-dependent part of TCG, regardless of CPUClass instances.
Fixes 55c3ceef61fcf06fc98ddc752b7cce788ce7680bSigned-off-by Emilio G. Cota <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>
Alistair
Quoted 4 lines
--
Eduardo
Re: [Qemu-arm] [PATCH for 2.11 1/5] qom: move CPUClass.tcg_initialize to a global
In reply to Emilio G. CotaQuoted 6 lines · Emilio G. Cota
55c3cee ("qom: Introduce CPUClass.tcg_initialize", 2017-10-24) introduces a per-CPUClass bool that we check so that the target CPU is initialized for TCG only once. This works well except when we end up creating more than one CPUClass, in which case we end up incorrectly initializing TCG more than once, i.e. once for each CPUClass.
... more than one CPUClass for a given translator.
Ideally, cortex-r5 and cortex-a53 would have a common parent class which would hold all of the bits that are common between them, including the translator.
That said,
r~
PATCH 2/5 xlnx-zynqmp: Properly support the smp command line option
In reply to Emilio G. CotaFrom: Alistair Francis <[email protected]>
Allow the -smp command line option to control the number of CPUs we create.
--- hw/arm/xlnx-zcu102.c | 3 ++- hw/arm/xlnx-zynqmp.c | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-)
hw/arm/xlnx-zcu102.c +2 -1
@@ -235,7 +235,8 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) {MachineClass *mc =MACHINE_CLASS (oc); - mc->desc ="Xilinx ZynqMP ZCU102 board" ; + mc->desc ="Xilinx ZynqMP ZCU102 board with 4xA53s and 2xR5s based on " \ +"the value of smp" ; mc->init = xlnx_zcu102_init; mc->block_default_type =IF_IDE ; mc->units_per_default_bus =1 ;
hw/arm/xlnx-zynqmp.c +16 -10
@@ -98,8 +98,9 @@ static void xlnx_zynqmp_create_rpu(XlnxZynqMPState *s, const char *boot_cpu, {Error *err =NULL ;int i; +int num_rpus =MIN (smp_cpus -XLNX_ZYNQMP_NUM_APU_CPUS ,XLNX_ZYNQMP_NUM_RPU_CPUS ); -for (i =0 ; i <XLNX_ZYNQMP_NUM_RPU_CPUS ; i++) { +for (i =0 ; i < num_rpus; i++) {char *name; object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]),
@@ -132,8 +133,9 @@ static void xlnx_zynqmp_init(Object *obj) {XlnxZynqMPState *s =XLNX_ZYNQMP (obj);int i; +int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS ); -for (i =0 ; i <XLNX_ZYNQMP_NUM_APU_CPUS ; i++) { +for (i =0 ; i < num_apus; i++) {object_initialize (&s->apu_cpu[i],sizeof (s->apu_cpu[i]),"cortex-a53-" TYPE_ARM_CPU ); object_property_add_child(obj, "apu-cpu[*]", OBJECT(&s->apu_cpu[i]),
@@ -182,6 +184,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)MemoryRegion *system_memory =get_system_memory ();uint8_t i;uint64_t ram_size; +int num_apus =MIN (smp_cpus,XLNX_ZYNQMP_NUM_APU_CPUS );const char *boot_cpu = s->boot_cpu ? s->boot_cpu :"apu-cpu[0]" ;ram_addr_t ddr_low_size, ddr_high_size;qemu_irq gic_spi[GIC_NUM_SPI_INTR ];
@@ -233,10 +236,10 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp)qdev_prop_set_uint32 (DEVICE (&s->gic),"num-irq" ,GIC_NUM_SPI_INTR +32 );qdev_prop_set_uint32 (DEVICE (&s->gic),"revision" ,2 ); -qdev_prop_set_uint32 (DEVICE (&s->gic),"num-cpu" ,XLNX_ZYNQMP_NUM_APU_CPUS ); +qdev_prop_set_uint32 (DEVICE (&s->gic),"num-cpu" , num_apus);/* Realize APUs before realizing the GIC. KVM requires this. */ -for (i =0 ; i <XLNX_ZYNQMP_NUM_APU_CPUS ; i++) { +for (i =0 ; i < num_apus; i++) {char *name; object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC,
@@ -292,7 +295,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) } } -for (i =0 ; i <XLNX_ZYNQMP_NUM_APU_CPUS ; i++) { +for (i =0 ; i < num_apus; i++) {qemu_irq irq; sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
@@ -307,11 +310,14 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }if (s->has_rpu) { -xlnx_zynqmp_create_rpu (s, boot_cpu, &err); -if (err) { -error_propagate (errp, err); -return ; - } +info_report ("The 'has_rpu' property is no longer required, to use the " +"RPUs just use -smp 6." ); + } + +xlnx_zynqmp_create_rpu (s, boot_cpu, &err); +if (err) { +error_propagate (errp, err); +return ; }if (!s->boot_cpu_ptr) {
Signature · 1 line
2.7.4
PATCH 3/5 xlnx-zcu102: Add an info message deprecating the EP108
In reply to Emilio G. CotaFrom: Alistair Francis <[email protected]>
The EP108 was an early access development board that is no longer used. Add an info message to convert any users to the ZCU102 instead. On QEMU they are both identical.
This patch also updated the qemu-doc.texi file to indicate that the EP108 has been deprecated.
--- qemu-doc.texi | 7 +++++++ hw/arm/xlnx-zcu102.c | 3 +++ 2 files changed, 10 insertions(+)
qemu-doc.texi +7 -0
@@ -2537,6 +2537,13 @@ or ``ivshmem-doorbell`` device types. The ``spapr-pci-vfio-host-bridge'' device type is replaced by the ``spapr-pci-host-bridge'' device type. +@section System emulator machines + +@subsection Xilinx EP108 (since 2.11.0) + +The ``xlnx-ep108'' machine has been replaced by the ``xlnx-zcu102'' machine. +The ``xlnx-zcu102'' machine has the same features and capabilites in QEMU. + @node License @appendix License
hw/arm/xlnx-zcu102.c +3 -0
@@ -164,6 +164,9 @@ static void xlnx_ep108_init(MachineState *machine) {XlnxZCU102 *s =EP108_MACHINE (machine); +info_report ("The Xilinx EP108 machine is deprecated, please use the " +"ZCU102 machine instead. It has the same features supported." ); +xlnx_zynqmp_init (s, machine); }
Signature · 1 line
2.7.4
PATCH 4/5 xlnx-zcu102: Specify the max number of CPUs for the EP108
In reply to Emilio G. CotaJust like the zcu102, the ep108 can instantiate several CPUs.
--- hw/arm/xlnx-zcu102.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/xlnx-zcu102.c +1 -0
@@ -188,6 +188,7 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_IDE ; mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; + mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
Signature · 1 line
2.7.4
Re: [Qemu-arm] [Qemu-devel] [PATCH for 2.11 4/5] xlnx-zcu102: Specify the max number of CPUs for the EP108
Quoted 3 lines · Emilio G. Cota
Just like the zcu102, the ep108 can instantiate several CPUs.
Signed-off-by Emilio G. Cota <[email protected]>
I completely missed this, thanks for the patch.
Alistair
Quoted 20 lines
--- hw/arm/xlnx-zcu102.c | 1 + 1 file changed, 1 insertion(+)hw/arm/xlnx-zcu102.c +1
-1@@ -188,6 +188,7 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->block_default_type =IF_IDE ; mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; + mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = { --2.7.4
PATCH 5/5 hw: add .min_cpus and .default_cpus fields to machine_class
In reply to Emilio G. Cotamax_cpus needs to be an upper bound on the number of vCPUs initialized; otherwise TCG region initialization breaks.
Some boards initialize a hard-coded number of vCPUs, which is not captured by the global max_cpus and therefore breaks TCG initialization. Fix it by adding the .min_cpus field to machine_class.
This commit also changes some user-facing behaviour: we now die if -smp is below this hard-coded vCPU minimum instead of silently ignoring the passed -smp value (sometimes announcing this by printing a warning). However, the introduction of .default_cpus lessens the likelihood that users will notice this: if -smp isn't set, we now assign the value in .default_cpus to both smp_cpus and max_cpus. IOW, if a user does not set -smp, they always get a correct number of vCPUs.
This change fixes 3468b59 ("tcg: enable multiple TCG contexts in softmmu", 2017-10-24), which broke TCG initialization for some ARM boards.
--- include/hw/boards.h | 5 +++++ hw/arm/exynos4_boards.c | 12 ++++-------- hw/arm/raspi.c | 2 ++ hw/arm/xlnx-zcu102.c | 2 ++ vl.c | 21 ++++++++++++++++++--- 5 files changed, 31 insertions(+), 11 deletions(-)
include/hw/boards.h +5 -0
@@ -102,6 +102,9 @@ typedef struct {/** * MachineClass: +* @max_cpus: maximum number of CPUs supported. Default: 1 +* @min_cpus: minimum number of CPUs supported. Default: 1 +* @default_cpus: number of CPUs instantiated if none are specified. Default: 1 * @get_hotplug_handler: this function is called during bus-less * device hotplug. If defined it returns pointer to an instance * of HotplugHandler object, which handles hotplug operation
@@ -167,6 +170,8 @@ struct MachineClass {BlockInterfaceType block_default_type;int units_per_default_bus;int max_cpus; +int min_cpus; +int default_cpus; unsigned int no_serial:1, no_parallel:1, use_virtcon:1,
hw/arm/exynos4_boards.c +4 -8
@@ -27,7 +27,6 @@#include "qemu-common.h" #include "cpu.h" #include "sysemu/sysemu.h" -#include "sysemu/qtest.h" #include "hw/sysbus.h" #include "net/net.h" #include "hw/arm/arm.h"
@@ -129,13 +128,6 @@ exynos4_boards_init_common(MachineState *machine, Exynos4BoardType board_type) {Exynos4BoardState *s =g_new (Exynos4BoardState,1 ); -MachineClass *mc =MACHINE_GET_CLASS (machine); - -if (smp_cpus !=EXYNOS4210_NCPUS && !qtest_enabled ()) { -error_report ("%s board supports only %d CPU cores, ignoring smp_cpus" -" value" , - mc->name,EXYNOS4210_NCPUS ); - } exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type]; exynos4_board_binfo.board_id = exynos4_board_id[board_type];
@@ -189,6 +181,8 @@ static void nuri_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung NURI board (Exynos4210)" ; mc->init = nuri_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }
@@ -205,6 +199,8 @@ static void smdkc210_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung SMDKC210 board (Exynos4210)" ; mc->init = smdkc210_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }
hw/arm/raspi.c +2 -0
@@ -167,6 +167,8 @@ static void raspi2_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->max_cpus =BCM2836_NCPUS ; + mc->min_cpus =BCM2836_NCPUS ; + mc->default_cpus =BCM2836_NCPUS ; mc->default_ram_size =1024 *1024 *1024 ; mc->ignore_memory_transaction_failures = true; };
hw/arm/xlnx-zcu102.c +2 -0
@@ -189,6 +189,7 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = {
@@ -246,6 +247,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {
vl.c +18 -3
@@ -160,8 +160,8 @@ Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];Chardev *sclp_hds[MAX_SCLP_CONSOLES ];int win2k_install_hack =0 ;int singlestep =0 ; -int smp_cpus =1 ; -unsigned int max_cpus =1 ; +int smp_cpus; +unsigned int max_cpus;int smp_cores =1 ;int smp_threads =1 ;int acpi_enabled =1 ;
@@ -4327,9 +4327,24 @@ int main(int argc, char **argv, char **envp)exit (0 ); } +/* machine_class: default to UP */ + machine_class->max_cpus = machine_class->max_cpus ?:1 ; + machine_class->min_cpus = machine_class->min_cpus ?:1 ; + machine_class->default_cpus = machine_class->default_cpus ?:1 ; + +/* default to machine_class->default_cpus */ + smp_cpus = machine_class->default_cpus; + max_cpus = machine_class->default_cpus; +smp_parse (qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL )); - machine_class->max_cpus = machine_class->max_cpus ?:1 ;/* Default to UP */ +/* sanity-check smp_cpus and max_cpus against machine_class */ +if (smp_cpus < machine_class->min_cpus) { +error_report ("Invalid SMP CPUs %d. The min CPUs " +"supported by machine '%s' is %d" , smp_cpus, + machine_class->name, machine_class->min_cpus); +exit (1 ); + }if (max_cpus > machine_class->max_cpus) { error_report("Invalid SMP CPUs %d. The max CPUs " "supported by machine '%s' is %d", max_cpus,
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH for 2.11 5/5] hw: add .min_cpus and .default_cpus fields to machine_class
Quoted 147 lines · Emilio G. Cota
max_cpusneeds to be an upper bound on the number of vCPUs initialized; otherwise TCG region initialization breaks.Some boards initialize a hard-coded number of vCPUs, which is not captured by the global
max_cpusand therefore breaks TCG initialization. Fix it by adding the .min_cpus field tomachine_class.This commit also changes some user-facing behaviour: we now die if -smp is below this hard-coded vCPU minimum instead of silently ignoring the passed -smp value (sometimes announcing this by printing a warning). However, the introduction of .default_cpus lessens the likelihood that users will notice this: if -smp isn't set, we now assign the value in .default_cpus to both
smp_cpusandmax_cpus. IOW, if a user does not set -smp, they always get a correct number of vCPUs.This change fixes 3468b59 ("tcg: enable multiple TCG contexts in softmmu", 2017-10-24), which broke TCG initialization for some ARM boards.
Fixes 3468b59e18b179bc63c7ce934de912dfa9596122Reported-by Thomas Huth <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>--- include/hw/boards.h | 5 +++++ hw/arm/exynos4_boards.c | 12 ++++-------- hw/arm/raspi.c | 2 ++ hw/arm/xlnx-zcu102.c | 2 ++ vl.c | 21 ++++++++++++++++++--- 5 files changed, 31 insertions(+), 11 deletions(-)include/hw/boards.h +5
-0@@ -102,6 +102,9 @@ typedef struct {/** * MachineClass: +* @max_cpus: maximum number of CPUs supported. Default: 1 +* @min_cpus: minimum number of CPUs supported. Default: 1 +* @default_cpus: number of CPUs instantiated if none are specified. Default: 1 * @get_hotplug_handler: this function is called during bus-less * device hotplug. If defined it returns pointer to an instance * of HotplugHandler object, which handles hotplug operation @@ -167,6 +170,8 @@ struct MachineClass {BlockInterfaceType block_default_type;int units_per_default_bus;int max_cpus; +int min_cpus; +int default_cpus; unsigned int no_serial:1, no_parallel:1, use_virtcon:1,hw/arm/exynos4_boards.c +4
-8@@ -27,7 +27,6 @@#include "qemu-common.h" #include "cpu.h" #include "sysemu/sysemu.h" -#include "sysemu/qtest.h" #include "hw/sysbus.h" #include "net/net.h" #include "hw/arm/arm.h" @@ -129,13 +128,6 @@ exynos4_boards_init_common(MachineState *machine, Exynos4BoardType board_type) {Exynos4BoardState *s =g_new (Exynos4BoardState,1 ); -MachineClass *mc =MACHINE_GET_CLASS (machine); - -if (smp_cpus !=EXYNOS4210_NCPUS && !qtest_enabled ()) { -error_report ("%s board supports only %d CPU cores, ignoring smp_cpus" -" value" , - mc->name,EXYNOS4210_NCPUS ); - } exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type]; exynos4_board_binfo.board_id = exynos4_board_id[board_type];@@ -189,6 +181,8 @@ static void nuri_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung NURI board (Exynos4210)" ; mc->init = nuri_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }@@ -205,6 +199,8 @@ static void smdkc210_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung SMDKC210 board (Exynos4210)" ; mc->init = smdkc210_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }hw/arm/raspi.c +2
-0@@ -167,6 +167,8 @@ static void raspi2_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->max_cpus =BCM2836_NCPUS ; + mc->min_cpus =BCM2836_NCPUS ; + mc->default_cpus =BCM2836_NCPUS ; mc->default_ram_size =1024 *1024 *1024 ; mc->ignore_memory_transaction_failures = true; };hw/arm/xlnx-zcu102.c +2
-0@@ -189,6 +189,7 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = {@@ -246,6 +247,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {vl.c +2
-2@@ -160,8 +160,8 @@ Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];Chardev *sclp_hds[MAX_SCLP_CONSOLES ];int win2k_install_hack =0 ;int singlestep =0 ; -int smp_cpus =1 ; -unsigned int max_cpus =1 ; +int smp_cpus; +unsigned int max_cpus;int smp_cores =1 ;int smp_threads =1 ;int acpi_enabled =1 ;
vl.c int main(int argc, char **argv, char **envp) · line 4333
Quoted 7 lines
vl.c +4
-0@@ -4327,9 +4327,24 @@ int main(int argc, char **argv, char **envp)exit (0 ); } +/* machine_class: default to UP */ + machine_class->max_cpus = machine_class->max_cpus ?:1 ; + machine_class->min_cpus = machine_class->min_cpus ?:1 ; + machine_class->default_cpus = machine_class->default_cpus ?:1 ;
This is consistent with the existing code that initialized max_cpus, but I'd prefer to initialize these defaults inside hw/core/machine.c:machine_class_init(). It can be done in a follow-up patch after 2.11, though.
Quoted 8 lines
vl.c +5
-1+ +/* default to machine_class->default_cpus */ + smp_cpus = machine_class->default_cpus; + max_cpus = machine_class->default_cpus; +smp_parse (qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL )); - machine_class->max_cpus = machine_class->max_cpus ?:1 ;/* Default to UP */
vl.c int main(int argc, char **argv, char **envp) · line 4350
Quoted 10 lines
vl.c +7
-0+/* sanity-check smp_cpus and max_cpus against machine_class */ +if (smp_cpus < machine_class->min_cpus) { +error_report ("Invalid SMP CPUs %d. The min CPUs " +"supported by machine '%s' is %d" , smp_cpus, + machine_class->name, machine_class->min_cpus); +exit (1 ); + }if (max_cpus > machine_class->max_cpus) { error_report("Invalid SMP CPUs %d. The max CPUs " "supported by machine '%s' is %d", max_cpus,
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH for 2.11 5/5] hw: add .min_cpus and .default_cpus fields to machine_class
In reply to Emilio G. CotaQuoted 15 lines · Emilio G. Cota
max_cpusneeds to be an upper bound on the number of vCPUs initialized; otherwise TCG region initialization breaks.Some boards initialize a hard-coded number of vCPUs, which is not captured by the global
max_cpusand therefore breaks TCG initialization. Fix it by adding the .min_cpus field tomachine_class.This commit also changes some user-facing behaviour: we now die if -smp is below this hard-coded vCPU minimum instead of silently ignoring the passed -smp value (sometimes announcing this by printing a warning). However, the introduction of .default_cpus lessens the likelihood that users will notice this: if -smp isn't set, we now assign the value in .default_cpus to both
smp_cpusandmax_cpus. IOW, if a user does not set -smp, they always get a correct number of vCPUs.
Quoted 8 lines
This change fixes 3468b59 ("tcg: enable multiple TCG contexts in softmmu", 2017-10-24), which broke TCG initialization for some ARM boards.
Fixes 3468b59e18b179bc63c7ce934de912dfa9596122Reported-by Thomas Huth <[email protected]>Suggested-by Peter Maydell <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>
Alistair
Quoted 153 lines
--- include/hw/boards.h | 5 +++++ hw/arm/exynos4_boards.c | 12 ++++-------- hw/arm/raspi.c | 2 ++ hw/arm/xlnx-zcu102.c | 2 ++ vl.c | 21 ++++++++++++++++++--- 5 files changed, 31 insertions(+), 11 deletions(-)include/hw/boards.h +5
-0@@ -102,6 +102,9 @@ typedef struct {/** * MachineClass: +* @max_cpus: maximum number of CPUs supported. Default: 1 +* @min_cpus: minimum number of CPUs supported. Default: 1 +* @default_cpus: number of CPUs instantiated if none are specified. Default: 1 * @get_hotplug_handler: this function is called during bus-less * device hotplug. If defined it returns pointer to an instance * of HotplugHandler object, which handles hotplug operation @@ -167,6 +170,8 @@ struct MachineClass {BlockInterfaceType block_default_type;int units_per_default_bus;int max_cpus; +int min_cpus; +int default_cpus; unsigned int no_serial:1, no_parallel:1, use_virtcon:1,hw/arm/exynos4_boards.c +4
-8@@ -27,7 +27,6 @@#include "qemu-common.h" #include "cpu.h" #include "sysemu/sysemu.h" -#include "sysemu/qtest.h" #include "hw/sysbus.h" #include "net/net.h" #include "hw/arm/arm.h" @@ -129,13 +128,6 @@ exynos4_boards_init_common(MachineState *machine, Exynos4BoardType board_type) {Exynos4BoardState *s =g_new (Exynos4BoardState,1 ); -MachineClass *mc =MACHINE_GET_CLASS (machine); - -if (smp_cpus !=EXYNOS4210_NCPUS && !qtest_enabled ()) { -error_report ("%s board supports only %d CPU cores, ignoring smp_cpus" -" value" , - mc->name,EXYNOS4210_NCPUS ); - } exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type]; exynos4_board_binfo.board_id = exynos4_board_id[board_type];@@ -189,6 +181,8 @@ static void nuri_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung NURI board (Exynos4210)" ; mc->init = nuri_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }@@ -205,6 +199,8 @@ static void smdkc210_class_init(ObjectClass *oc, void *data) mc->desc ="Samsung SMDKC210 board (Exynos4210)" ; mc->init = smdkc210_init; mc->max_cpus =EXYNOS4210_NCPUS ; + mc->min_cpus =EXYNOS4210_NCPUS ; + mc->default_cpus =EXYNOS4210_NCPUS ; mc->ignore_memory_transaction_failures = true; }hw/arm/raspi.c +2
-0@@ -167,6 +167,8 @@ static void raspi2_machine_init(MachineClass *mc) mc->no_floppy =1 ; mc->no_cdrom =1 ; mc->max_cpus =BCM2836_NCPUS ; + mc->min_cpus =BCM2836_NCPUS ; + mc->default_cpus =BCM2836_NCPUS ; mc->default_ram_size =1024 *1024 *1024 ; mc->ignore_memory_transaction_failures = true; };hw/arm/xlnx-zcu102.c +2
-0@@ -189,6 +189,7 @@ static void xlnx_ep108_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_ep108_machine_init_typeinfo = {@@ -246,6 +247,7 @@ static void xlnx_zcu102_machine_class_init(ObjectClass *oc, void *data) mc->units_per_default_bus =1 ; mc->ignore_memory_transaction_failures = true; mc->max_cpus =XLNX_ZYNQMP_NUM_APU_CPUS +XLNX_ZYNQMP_NUM_RPU_CPUS ; + mc->default_cpus =XLNX_ZYNQMP_NUM_APU_CPUS ; }static const TypeInfo xlnx_zcu102_machine_init_typeinfo = {vl.c +18
-4@@ -160,8 +160,8 @@ Chardev *virtcon_hds[MAX_VIRTIO_CONSOLES];Chardev *sclp_hds[MAX_SCLP_CONSOLES ];int win2k_install_hack =0 ;int singlestep =0 ; -int smp_cpus =1 ; -unsigned int max_cpus =1 ; +int smp_cpus; +unsigned int max_cpus;int smp_cores =1 ;int smp_threads =1 ;int acpi_enabled =1 ;@@ -4327,9 +4327,24 @@ int main(int argc, char **argv, char **envp)exit (0 ); } +/* machine_class: default to UP */ + machine_class->max_cpus = machine_class->max_cpus ?:1 ; + machine_class->min_cpus = machine_class->min_cpus ?:1 ; + machine_class->default_cpus = machine_class->default_cpus ?:1 ; + +/* default to machine_class->default_cpus */ + smp_cpus = machine_class->default_cpus; + max_cpus = machine_class->default_cpus; +smp_parse (qemu_opts_find (qemu_find_opts ("smp-opts" ),NULL )); - machine_class->max_cpus = machine_class->max_cpus ?:1 ;/* Default to UP */ +/* sanity-check smp_cpus and max_cpus against machine_class */ +if (smp_cpus < machine_class->min_cpus) { +error_report ("Invalid SMP CPUs %d. The min CPUs " +"supported by machine '%s' is %d" , smp_cpus, + machine_class->name, machine_class->min_cpus); +exit (1 ); + }if (max_cpus > machine_class->max_cpus) { error_report("Invalid SMP CPUs %d. The max CPUs " "supported by machine '%s' is %d", max_cpus, --2.7.4
Quoted 26 lines · Emilio G. Cota
Some MachineClass changes to fix TCG initialization of some ARM boards for 2.11. This was originally reported by Thomas Huth in [1], where Peter suggested a way to fix it. Further discussion in another thread [2] followed up on this.
As a result of that follow-up discussion we also got some Zynq changes from Alistair [3], which I'm including here since in order to test them we need the first patch in this series.
Thanks,
Emilio
[1] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg00078.html
[2] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg00502.html
[3] https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg01842.htmlAlistair Francis (2):
xlnx-zynqmp: Properly support the smp command line option
xlnx-zcu102: Add an info message deprecating the EP108Emilio G. Cota (3):
qom: move CPUClass.tcg_initialize to a global
xlnx-zcu102: Specify the max number of CPUs for the EP108
hw: add .min_cpus and .default_cpus fields tomachine_class
Quoted 10 lines
qemu-doc.texi | 7 +++++++ include/hw/boards.h | 5 +++++ include/qom/cpu.h | 1 - exec.c | 5 +++-- hw/arm/exynos4_boards.c | 12 ++++-------- hw/arm/raspi.c | 2 ++ hw/arm/xlnx-zcu102.c | 9 ++++++++- hw/arm/xlnx-zynqmp.c | 26 ++++++++++++++++---------- vl.c | 21 ++++++++++++++++++--- 9 files changed, 63 insertions(+), 25 deletions(-)
Since this is fixing Arm boards and I'm putting together an arm pullreq anyway, I'm applying this to target-arm.next. (Eduardo's reviewed the patches which touch the MachineClass and option parsing code.)
thanks
-- PMM