Skip to content

Commit 038ac18

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: mm: Broadcast kernel TLB flushes only when needed
__flush_tlb_range() avoids broadcasting TLB flushes when an mm context is only active on the local CPU. Apply this same optimization to TLB flushes of kernel memory when only one CPU is online. This check can be constant-folded when SMP is disabled. Reviewed-by: Alexandre Ghiti <[email protected]> Signed-off-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent dc892fb commit 038ac18

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

arch/riscv/mm/tlbflush.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,15 @@ static void __flush_tlb_range(struct cpumask *cmask, unsigned long asid,
103103
unsigned long start, unsigned long size,
104104
unsigned long stride)
105105
{
106-
bool broadcast;
106+
unsigned int cpu;
107107

108108
if (cpumask_empty(cmask))
109109
return;
110110

111-
if (cmask != cpu_online_mask) {
112-
unsigned int cpuid;
111+
cpu = get_cpu();
113112

114-
cpuid = get_cpu();
115-
/* check if the tlbflush needs to be sent to other CPUs */
116-
broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids;
117-
} else {
118-
broadcast = true;
119-
}
120-
121-
if (!broadcast) {
113+
/* Check if the TLB flush needs to be sent to other CPUs. */
114+
if (cpumask_any_but(cmask, cpu) >= nr_cpu_ids) {
122115
local_flush_tlb_range_asid(start, size, stride, asid);
123116
} else if (riscv_use_sbi_for_rfence()) {
124117
sbi_remote_sfence_vma_asid(cmask, start, size, asid);
@@ -132,8 +125,7 @@ static void __flush_tlb_range(struct cpumask *cmask, unsigned long asid,
132125
on_each_cpu_mask(cmask, __ipi_flush_tlb_range_asid, &ftd, 1);
133126
}
134127

135-
if (cmask != cpu_online_mask)
136-
put_cpu();
128+
put_cpu();
137129
}
138130

139131
static inline unsigned long get_mm_asid(struct mm_struct *mm)

0 commit comments

Comments
 (0)