riscv: Introduce AVAILABLE_HARTS
authorRick Chen <rick@andestech.com>
Wed, 21 Sep 2022 06:34:54 +0000 (14:34 +0800)
committerLeo Yu-Chi Liang <ycliang@andestech.com>
Mon, 26 Sep 2022 06:29:13 +0000 (14:29 +0800)
In SMP all harts will register themself in available_hart
during start up. Then main hart will send IPI to other harts
according to this variables. But this mechanism may not
guarantee that all other harts can jump to next stage.

When main hart is sending IPI to other hart according to
available_harts, but other harts maybe still not finish the
registration. Then the SMP booting will miss some harts finally.
So let it become an option and it will be enabled by default.

Please refer to the discussion:
https://www.mail-archive.com/u-boot@lists.denx.de/msg449997.html

Signed-off-by: Rick Chen <rick@andestech.com>
Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
arch/riscv/Kconfig
arch/riscv/cpu/cpu.c
arch/riscv/cpu/start.S
arch/riscv/include/asm/global_data.h
arch/riscv/lib/asm-offsets.c
arch/riscv/lib/smp.c

index c042506..32a90b8 100644 (file)
@@ -276,6 +276,13 @@ config SPL_XIP
          rely on lock variables (for example hart_lottery and available_harts_lock),
          this affects only SPL, other stages should proceed as non-XIP.
 
+config AVAILABLE_HARTS
+       bool "Send IPI by available harts"
+       default y
+       help
+         By default, IPI sending mechanism will depend on available_harts.
+         If disable this, it will send IPI by CPUs node numbers of device tree.
+
 config SHOW_REGS
        bool "Show registers on unhandled exception"
 
index 0f323b2..52ab025 100644 (file)
 #if !CONFIG_IS_ENABLED(XIP)
 u32 hart_lottery __section(".data") = 0;
 
+#ifdef CONFIG_AVAILABLE_HARTS
 /*
  * The main hart running U-Boot has acquired available_harts_lock until it has
  * finished initialization of global data.
  */
 u32 available_harts_lock = 1;
 #endif
+#endif
 
 static inline bool supports_extension(char ext)
 {
index de9d078..4687bca 100644 (file)
@@ -153,21 +153,23 @@ call_harts_early_init:
        SREG    tp, GD_BOOT_HART(gp)
 
 #if !CONFIG_IS_ENABLED(XIP)
+#ifdef CONFIG_AVAILABLE_HARTS
        la      t0, available_harts_lock
        amoswap.w.rl zero, zero, 0(t0)
+#endif
 
 wait_for_gd_init:
-       la      t0, available_harts_lock
-       li      t1, 1
-1:     amoswap.w.aq t1, t1, 0(t0)
-       bnez    t1, 1b
-
        /*
         * Set the global data pointer only when gd_t has been initialized.
         * This was already set by arch_setup_gd on the boot hart, but all other
         * harts' global data pointers gets set here.
         */
        mv      gp, s0
+#ifdef CONFIG_AVAILABLE_HARTS
+       la      t0, available_harts_lock
+       li      t1, 1
+1:     amoswap.w.aq t1, t1, 0(t0)
+       bnez    t1, 1b
 
        /* register available harts in the available_harts mask */
        li      t1, 1
@@ -177,6 +179,7 @@ wait_for_gd_init:
        SREG    t2, GD_AVAILABLE_HARTS(gp)
 
        amoswap.w.rl zero, zero, 0(t0)
+#endif
 
        /*
         * Continue on hart lottery winner, others branch to
index b3c79e1..858594a 100644 (file)
@@ -28,8 +28,10 @@ struct arch_global_data {
        struct ipi_data ipi[CONFIG_NR_CPUS];
 #endif
 #if !CONFIG_IS_ENABLED(XIP)
+#ifdef CONFIG_AVAILABLE_HARTS
        ulong available_harts;
 #endif
+#endif
 };
 
 #include <asm-generic/global_data.h>
index c4f48c8..452dfce 100644 (file)
@@ -17,8 +17,10 @@ int main(void)
        DEFINE(GD_BOOT_HART, offsetof(gd_t, arch.boot_hart));
        DEFINE(GD_FIRMWARE_FDT_ADDR, offsetof(gd_t, arch.firmware_fdt_addr));
 #if !CONFIG_IS_ENABLED(XIP)
+#ifdef CONFIG_AVAILABLE_HARTS
        DEFINE(GD_AVAILABLE_HARTS, offsetof(gd_t, arch.available_harts));
 #endif
+#endif
 
        return 0;
 }
index f8b7562..c0f65af 100644 (file)
@@ -46,10 +46,12 @@ static int send_ipi_many(struct ipi_data *ipi, int wait)
                }
 
 #if !CONFIG_IS_ENABLED(XIP)
+#ifdef CONFIG_AVAILABLE_HARTS
                /* skip if hart is not available */
                if (!(gd->arch.available_harts & (1 << reg)))
                        continue;
 #endif
+#endif
 
                gd->arch.ipi[reg].addr = ipi->addr;
                gd->arch.ipi[reg].arg0 = ipi->arg0;