riscv: Only send remote fences when some other CPU is online
authorSamuel Holland <samuel.holland@sifive.com>
Wed, 27 Mar 2024 04:49:46 +0000 (21:49 -0700)
committerPalmer Dabbelt <palmer@rivosinc.com>
Mon, 29 Apr 2024 17:49:28 +0000 (10:49 -0700)
If no other CPU is online, a local cache or TLB flush is sufficient.
These checks can be constant-folded when SMP is disabled.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240327045035.368512-6-samuel.holland@sifive.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/mm/cacheflush.c
arch/riscv/mm/tlbflush.c

index d76fc73e594b291c57e8f7fb55ad9398faeed01c..f5be1fec8191c32b7ea0164e359ca750f68cad43 100644 (file)
@@ -21,7 +21,9 @@ void flush_icache_all(void)
 {
        local_flush_icache_all();
 
-       if (riscv_use_sbi_for_rfence())
+       if (num_online_cpus() < 2)
+               return;
+       else if (riscv_use_sbi_for_rfence())
                sbi_remote_fence_i(NULL);
        else
                on_each_cpu(ipi_remote_fence_i, NULL, 1);
index da821315d43ee3ac0af23588fe7250d6f922972b..0901aa47b58fe7e18b517b014af9df672ce29d32 100644 (file)
@@ -79,7 +79,9 @@ static void __ipi_flush_tlb_all(void *info)
 
 void flush_tlb_all(void)
 {
-       if (riscv_use_sbi_for_rfence())
+       if (num_online_cpus() < 2)
+               local_flush_tlb_all();
+       else if (riscv_use_sbi_for_rfence())
                sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID);
        else
                on_each_cpu(__ipi_flush_tlb_all, NULL, 1);