[U-Boot] [PATCH 08/10] x86: qemu: Add MP initialization

The existing MP initialization process works on QEMU multicore, except that we need increase delay time for BSP to wait APs to show up online. Use a Kconfig option to control the delay time factor to the normal one.
Signed-off-by: Bin Meng bmeng.cn@gmail.com ---
arch/x86/cpu/mp_init.c | 4 ++++ arch/x86/cpu/qemu/Kconfig | 11 +++++++++++ arch/x86/dts/qemu-x86_i440fx.dts | 20 ++++++++++++++++++++ arch/x86/dts/qemu-x86_q35.dts | 20 ++++++++++++++++++++ configs/qemu-x86_defconfig | 4 ++++ doc/README.x86 | 5 +++++ 6 files changed, 64 insertions(+)
diff --git a/arch/x86/cpu/mp_init.c b/arch/x86/cpu/mp_init.c index e686b28..f87201b 100644 --- a/arch/x86/cpu/mp_init.c +++ b/arch/x86/cpu/mp_init.c @@ -75,6 +75,10 @@ static int wait_for_aps(atomic_t *val, int target, int total_delay, int timeout = 0; int delayed = 0;
+#ifdef CONFIG_QEMU + total_delay *= CONFIG_MPINIT_DELAY_FACTOR; +#endif + while (atomic_read(val) != target) { udelay(delay_step); delayed += delay_step; diff --git a/arch/x86/cpu/qemu/Kconfig b/arch/x86/cpu/qemu/Kconfig index fb775d7..a690060 100644 --- a/arch/x86/cpu/qemu/Kconfig +++ b/arch/x86/cpu/qemu/Kconfig @@ -18,4 +18,15 @@ config SYS_CAR_SIZE hex default 0x10000
+config MPINIT_DELAY_FACTOR + int "QEMU multicore initialization delay factor" + depends on SMP + default 100 + help + During multicore initialization after BSP sends SIPI to wake up APs, + U-Boot needs to wait some time for AP to show up online. The delay + time is good for real hardware, but seems not enough for QEMU. The + value of this option will be used as the multiplier to the normal + delay time. + endif diff --git a/arch/x86/dts/qemu-x86_i440fx.dts b/arch/x86/dts/qemu-x86_i440fx.dts index 0c522c8..e3c6fc3 100644 --- a/arch/x86/dts/qemu-x86_i440fx.dts +++ b/arch/x86/dts/qemu-x86_i440fx.dts @@ -24,6 +24,26 @@ stdout-path = "/serial"; };
+ cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "cpu-x86"; + reg = <0>; + intel,apic-id = <0>; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "cpu-x86"; + reg = <1>; + intel,apic-id = <1>; + }; + + }; + pci { compatible = "pci-x86"; #address-cells = <3>; diff --git a/arch/x86/dts/qemu-x86_q35.dts b/arch/x86/dts/qemu-x86_q35.dts index 5fbabc2..0305864 100644 --- a/arch/x86/dts/qemu-x86_q35.dts +++ b/arch/x86/dts/qemu-x86_q35.dts @@ -35,6 +35,26 @@ stdout-path = "/serial"; };
+ cpus { + #address-cells = <1>; + #size-cells = <0>; + + cpu@0 { + device_type = "cpu"; + compatible = "cpu-x86"; + reg = <0>; + intel,apic-id = <0>; + }; + + cpu@1 { + device_type = "cpu"; + compatible = "cpu-x86"; + reg = <1>; + intel,apic-id = <1>; + }; + + }; + pci { compatible = "pci-x86"; #address-cells = <3>; diff --git a/configs/qemu-x86_defconfig b/configs/qemu-x86_defconfig index a4c20bd..62c3f35 100644 --- a/configs/qemu-x86_defconfig +++ b/configs/qemu-x86_defconfig @@ -1,6 +1,9 @@ CONFIG_X86=y CONFIG_DEFAULT_DEVICE_TREE="qemu-x86_i440fx" +CONFIG_SMP=y +CONFIG_MAX_CPUS=2 CONFIG_GENERATE_PIRQ_TABLE=y +CONFIG_CMD_CPU=y # CONFIG_CMD_IMLS is not set # CONFIG_CMD_FLASH is not set # CONFIG_CMD_SETEXPR is not set @@ -9,6 +12,7 @@ CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y CONFIG_CMD_BOOTSTAGE=y CONFIG_OF_CONTROL=y +CONFIG_CPU=y CONFIG_SPI_FLASH=y CONFIG_VIDEO_VESA=y CONFIG_FRAMEBUFFER_SET_VESA_MODE=y diff --git a/doc/README.x86 b/doc/README.x86 index 5d71244..1cab42c 100644 --- a/doc/README.x86 +++ b/doc/README.x86 @@ -281,6 +281,11 @@ QEMU emulates a graphic card which U-Boot supports. Removing '-nographic' will show QEMU's VGA console window. Note this will disable QEMU's serial output. If you want to check both consoles, use '-serial stdio'.
+Multicore is also supported by QEMU via '-smp n' where n is the number of cores +to instantiate. Currently the default U-Boot built for QEMU supports 2 cores. +In order to support more cores, you need add additional cpu nodes in the device +tree and change CONFIG_MAX_CPUS accordingly. + CPU Microcode ------------- Modern CPUs usually require a special bit stream called microcode [8] to be

Hi Bin,
On 15 July 2015 at 02:23, Bin Meng bmeng.cn@gmail.com wrote:
The existing MP initialization process works on QEMU multicore, except that we need increase delay time for BSP to wait APs to show up online. Use a Kconfig option to control the delay time factor to the normal one.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
arch/x86/cpu/mp_init.c | 4 ++++ arch/x86/cpu/qemu/Kconfig | 11 +++++++++++ arch/x86/dts/qemu-x86_i440fx.dts | 20 ++++++++++++++++++++ arch/x86/dts/qemu-x86_q35.dts | 20 ++++++++++++++++++++ configs/qemu-x86_defconfig | 4 ++++ doc/README.x86 | 5 +++++ 6 files changed, 64 insertions(+)
Why does qemu need a longer delay? Can we put this in as a property of the /cpus node instead?
Regards, Simon

Hi Simon,
On Sat, Jul 18, 2015 at 10:37 PM, Simon Glass sjg@chromium.org wrote:
Hi Bin,
On 15 July 2015 at 02:23, Bin Meng bmeng.cn@gmail.com wrote:
The existing MP initialization process works on QEMU multicore, except that we need increase delay time for BSP to wait APs to show up online. Use a Kconfig option to control the delay time factor to the normal one.
Signed-off-by: Bin Meng bmeng.cn@gmail.com
arch/x86/cpu/mp_init.c | 4 ++++ arch/x86/cpu/qemu/Kconfig | 11 +++++++++++ arch/x86/dts/qemu-x86_i440fx.dts | 20 ++++++++++++++++++++ arch/x86/dts/qemu-x86_q35.dts | 20 ++++++++++++++++++++ configs/qemu-x86_defconfig | 4 ++++ doc/README.x86 | 5 +++++ 6 files changed, 64 insertions(+)
Why does qemu need a longer delay? Can we put this in as a property of the /cpus node instead?
I have no idea. I suspect it is caused by QEMU's multicore simulation is not real paralleled. Yep, we can define a parameter in the /cpus node to control this.
Regards, Bin
participants (2)
-
Bin Meng
-
Simon Glass