From 6f02b6938f8e607d38ee8de5a59581d554af0d3f Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Fri, 21 Dec 2018 10:09:33 +0530 Subject: [PATCH] lib: Introduce bitmap to track HARTs waiting for coldboot On QEMU Virt, max supported HARTs are 8 but number of HARTs actually depend on "-smp" command-line parameter passed to QEMU. This creates problems in sbi_hart_wake_coldboot_harts() because when number of HARTs are less than 8. To tackle this, we introduce a bitmap to track HARTs waiting for coldboot to finish. We wake only those HARTs who have set their bit in coldboot bitmap. Signed-off-by: Anup Patel --- lib/sbi_hart.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/sbi_hart.c b/lib/sbi_hart.c index fd6d4d40..5b26aead 100644 --- a/lib/sbi_hart.c +++ b/lib/sbi_hart.c @@ -263,7 +263,9 @@ struct sbi_scratch *sbi_hart_id_to_scratch(struct sbi_scratch *scratch, return ((h2s)scratch->hartid_to_scratch)(hartid); } -#define NO_HOTPLUG_BITMAP_SIZE __riscv_xlen +#define COLDBOOT_WAIT_BITMAP_SIZE __riscv_xlen +static spinlock_t coldboot_wait_bitmap_lock = SPIN_LOCK_INITIALIZER; +static unsigned long coldboot_wait_bitmap = 0; void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) { @@ -271,13 +273,20 @@ void sbi_hart_wait_for_coldboot(struct sbi_scratch *scratch, u32 hartid) struct sbi_platform *plat = sbi_platform_ptr(scratch); if ((sbi_platform_hart_count(plat) <= hartid) || - (NO_HOTPLUG_BITMAP_SIZE <= hartid)) + (COLDBOOT_WAIT_BITMAP_SIZE <= hartid)) sbi_hart_hang(); do { + spin_lock(&coldboot_wait_bitmap_lock); + coldboot_wait_bitmap |= (1UL << hartid); + spin_unlock(&coldboot_wait_bitmap_lock); + wfi(); mipval = csr_read(mip); - /* Make sure the hart woke because of ipi */ - } while (!(mipval && MIP_MSIP) ); + + spin_lock(&coldboot_wait_bitmap_lock); + coldboot_wait_bitmap &= ~(1UL << hartid); + spin_unlock(&coldboot_wait_bitmap_lock); + } while (!(mipval && MIP_MSIP)); csr_clear(mip, MIP_MSIP); } @@ -289,7 +298,9 @@ void sbi_hart_wake_coldboot_harts(struct sbi_scratch *scratch, u32 hartid) for(int i = 0; i < max_hart ; i++) { /* send an IPI to every other hart */ - if (i != hartid) + spin_lock(&coldboot_wait_bitmap_lock); + if ((i != hartid) && (coldboot_wait_bitmap & (1UL << i))) sbi_platform_ipi_inject(plat, i, hartid); + spin_unlock(&coldboot_wait_bitmap_lock); } }