Skip to content

Commit 997153b

Browse files
committed
csky: Add flush_icache_mm to defer flush icache all
Some CPUs don't support icache.va instruction to maintain the whole smp cores' icache. Using icache.all + IPI casue a lot on performace and using defer mechanism could reduce the number of calling icache _flush_all functions. Signed-off-by: Guo Ren <[email protected]>
1 parent cc1f656 commit 997153b

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

arch/csky/abiv1/inc/abi/cacheflush.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, u
4848

4949
#define flush_icache_page(vma, page) do {} while (0);
5050
#define flush_icache_range(start, end) cache_wbinv_range(start, end)
51+
#define flush_icache_mm_range(mm, start, end) cache_wbinv_range(start, end)
52+
#define flush_icache_deferred(mm) do {} while (0);
5153

5254
#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
5355
do { \

arch/csky/abiv2/cacheflush.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,58 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
2828

2929
kunmap_atomic((void *) addr);
3030
}
31+
32+
void flush_icache_deferred(struct mm_struct *mm)
33+
{
34+
unsigned int cpu = smp_processor_id();
35+
cpumask_t *mask = &mm->context.icache_stale_mask;
36+
37+
if (cpumask_test_cpu(cpu, mask)) {
38+
cpumask_clear_cpu(cpu, mask);
39+
/*
40+
* Ensure the remote hart's writes are visible to this hart.
41+
* This pairs with a barrier in flush_icache_mm.
42+
*/
43+
smp_mb();
44+
local_icache_inv_all(NULL);
45+
}
46+
}
47+
48+
void flush_icache_mm_range(struct mm_struct *mm,
49+
unsigned long start, unsigned long end)
50+
{
51+
unsigned int cpu;
52+
cpumask_t others, *mask;
53+
54+
preempt_disable();
55+
56+
#ifdef CONFIG_CPU_HAS_ICACHE_INS
57+
if (mm == current->mm) {
58+
icache_inv_range(start, end);
59+
preempt_enable();
60+
return;
61+
}
62+
#endif
63+
64+
/* Mark every hart's icache as needing a flush for this MM. */
65+
mask = &mm->context.icache_stale_mask;
66+
cpumask_setall(mask);
67+
68+
/* Flush this hart's I$ now, and mark it as flushed. */
69+
cpu = smp_processor_id();
70+
cpumask_clear_cpu(cpu, mask);
71+
local_icache_inv_all(NULL);
72+
73+
/*
74+
* Flush the I$ of other harts concurrently executing, and mark them as
75+
* flushed.
76+
*/
77+
cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu));
78+
79+
if (mm != current->active_mm || !cpumask_empty(&others)) {
80+
on_each_cpu_mask(&others, local_icache_inv_all, NULL, 1);
81+
cpumask_clear(mask);
82+
}
83+
84+
preempt_enable();
85+
}

arch/csky/abiv2/inc/abi/cacheflush.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ static inline void flush_dcache_page(struct page *page)
3131

3232
#define flush_icache_range(start, end) cache_wbinv_range(start, end)
3333

34+
void flush_icache_mm_range(struct mm_struct *mm,
35+
unsigned long start, unsigned long end);
36+
void flush_icache_deferred(struct mm_struct *mm);
37+
3438
#define flush_cache_vmap(start, end) do { } while (0)
3539
#define flush_cache_vunmap(start, end) do { } while (0)
3640

3741
#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
3842
do { \
3943
memcpy(dst, src, len); \
40-
if (vma->vm_flags & VM_EXEC) \
41-
cache_wbinv_range((unsigned long)dst, \
42-
(unsigned long)dst + len); \
44+
if (vma->vm_flags & VM_EXEC) { \
45+
dcache_wb_range((unsigned long)dst, \
46+
(unsigned long)dst + len); \
47+
flush_icache_mm_range(current->mm, \
48+
(unsigned long)dst, \
49+
(unsigned long)dst + len); \
50+
} \
4351
} while (0)
4452
#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
4553
memcpy(dst, src, len)

arch/csky/include/asm/cacheflush.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef __ASM_CSKY_CACHEFLUSH_H
55
#define __ASM_CSKY_CACHEFLUSH_H
66

7+
#include <linux/mm.h>
78
#include <abi/cacheflush.h>
89

910
#endif /* __ASM_CSKY_CACHEFLUSH_H */

arch/csky/include/asm/mmu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
typedef struct {
88
atomic64_t asid;
99
void *vdso;
10+
cpumask_t icache_stale_mask;
1011
} mm_context_t;
1112

1213
#endif /* __ASM_CSKY_MMU_H */

arch/csky/include/asm/mmu_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,
4343

4444
TLBMISS_HANDLER_SETUP_PGD(next->pgd);
4545
write_mmu_entryhi(next->context.asid.counter);
46+
47+
flush_icache_deferred(next);
4648
}
4749
#endif /* __ASM_CSKY_MMU_CONTEXT_H */

arch/csky/mm/syscache.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <linux/syscalls.h>
55
#include <asm/page.h>
6-
#include <asm/cache.h>
6+
#include <asm/cacheflush.h>
77
#include <asm/cachectl.h>
88

99
SYSCALL_DEFINE3(cacheflush,
@@ -13,17 +13,14 @@ SYSCALL_DEFINE3(cacheflush,
1313
{
1414
switch (cache) {
1515
case ICACHE:
16-
icache_inv_range((unsigned long)addr,
17-
(unsigned long)addr + bytes);
18-
break;
16+
case BCACHE:
17+
flush_icache_mm_range(current->mm,
18+
(unsigned long)addr,
19+
(unsigned long)addr + bytes);
1920
case DCACHE:
2021
dcache_wb_range((unsigned long)addr,
2122
(unsigned long)addr + bytes);
2223
break;
23-
case BCACHE:
24-
cache_wbinv_range((unsigned long)addr,
25-
(unsigned long)addr + bytes);
26-
break;
2724
default:
2825
return -EINVAL;
2926
}

0 commit comments

Comments
 (0)