Skip to content

Commit 9546f00

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Only send remote fences when some other CPU is online
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 <[email protected]> Reviewed-by: Alexandre Ghiti <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 038ac18 commit 9546f00

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

arch/riscv/mm/cacheflush.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ void flush_icache_all(void)
2121
{
2222
local_flush_icache_all();
2323

24-
if (riscv_use_sbi_for_rfence())
24+
if (num_online_cpus() < 2)
25+
return;
26+
else if (riscv_use_sbi_for_rfence())
2527
sbi_remote_fence_i(NULL);
2628
else
2729
on_each_cpu(ipi_remote_fence_i, NULL, 1);

arch/riscv/mm/tlbflush.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ static void __ipi_flush_tlb_all(void *info)
7979

8080
void flush_tlb_all(void)
8181
{
82-
if (riscv_use_sbi_for_rfence())
82+
if (num_online_cpus() < 2)
83+
local_flush_tlb_all();
84+
else if (riscv_use_sbi_for_rfence())
8385
sbi_remote_sfence_vma_asid(NULL, 0, FLUSH_TLB_MAX_SIZE, FLUSH_TLB_NO_ASID);
8486
else
8587
on_each_cpu(__ipi_flush_tlb_all, NULL, 1);

0 commit comments

Comments
 (0)