Skip to content

Commit 31738ed

Browse files
atishp04paul-walmsley-sifive
authored andcommitted
RISC-V: Issue a local tlbflush if possible.
In RISC-V, tlb flush happens via SBI which is expensive. If the local cpu is the only cpu in cpumask, there is no need to invoke a SBI call. Just do a local flush and return. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Paul Walmsley <[email protected]>
1 parent 6384423 commit 31738ed

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

arch/riscv/mm/tlbflush.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22

33
#include <linux/mm.h>
44
#include <linux/smp.h>
5+
#include <linux/sched.h>
56
#include <asm/sbi.h>
67

78
void flush_tlb_all(void)
89
{
910
sbi_remote_sfence_vma(NULL, 0, -1);
1011
}
1112

13+
/*
14+
* This function must not be called with cmask being null.
15+
* Kernel may panic if cmask is NULL.
16+
*/
1217
static void __sbi_tlb_flush_range(struct cpumask *cmask, unsigned long start,
1318
unsigned long size)
1419
{
1520
struct cpumask hmask;
21+
unsigned int cpuid;
1622

1723
if (cpumask_empty(cmask))
1824
return;
1925

20-
riscv_cpuid_to_hartid_mask(cmask, &hmask);
21-
sbi_remote_sfence_vma(hmask.bits, start, size);
26+
cpuid = get_cpu();
27+
28+
if (cpumask_any_but(cmask, cpuid) >= nr_cpu_ids) {
29+
/* local cpu is the only cpu present in cpumask */
30+
local_flush_tlb_all();
31+
} else {
32+
riscv_cpuid_to_hartid_mask(cmask, &hmask);
33+
sbi_remote_sfence_vma(cpumask_bits(&hmask), start, size);
34+
}
35+
36+
put_cpu();
2237
}
2338

2439
void flush_tlb_mm(struct mm_struct *mm)

0 commit comments

Comments
 (0)