]> www.infradead.org Git - users/hch/misc.git/commitdiff
csky: mmu: Prevent spurious page faults
authorGuo Ren <guoren@linux.alibaba.com>
Thu, 6 Apr 2023 08:46:49 +0000 (04:46 -0400)
committerGuo Ren <guoren@linux.alibaba.com>
Thu, 13 Apr 2023 06:36:14 +0000 (02:36 -0400)
C-SKY MMU would pre-fetch invalid pte entries, and it could work with
flush_tlb_fix_spurious_fault, but the additional page fault exceptions
would reduce performance. So flushing the entry of the TLB would prevent
the following spurious page faults. Here is the test code:

define DATA_LEN  4096
define COPY_NUM  (504*100)

unsigned char src[DATA_LEN*COPY_NUM] = {0};
unsigned char dst[DATA_LEN*COPY_NUM] = {0};

unsigned char func_src[DATA_LEN*COPY_NUM] = {0};
unsigned char func_dst[DATA_LEN*COPY_NUM] = {0};

void main(void)
{
int j;
for (j = 0; j < COPY_NUM; j++)
memcpy(&dst[j*DATA_LEN], &src[j*DATA_LEN], 4);
}

perf stat -e page-faults ./main.elf

The amount of page fault traps would be reduced in half with the patch.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
arch/csky/abiv1/cacheflush.c
arch/csky/abiv2/cacheflush.c

index fb91b069dc69f4d3283997288462f4a2340b329e..94fbc03cbe703dbb823d9e26e5703286a9f0dd55 100644 (file)
@@ -11,6 +11,7 @@
 #include <asm/cache.h>
 #include <asm/cacheflush.h>
 #include <asm/cachectl.h>
+#include <asm/tlbflush.h>
 
 #define PG_dcache_clean                PG_arch_1
 
@@ -40,6 +41,8 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
        unsigned long pfn = pte_pfn(*ptep);
        struct page *page;
 
+       flush_tlb_page(vma, addr);
+
        if (!pfn_valid(pfn))
                return;
 
index 39c51399dd81da57ef4d9c580bd31bdf5e2b6f0b..9923cd24db583274470e2d1cd33716e028b8fb13 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/highmem.h>
 #include <linux/mm.h>
 #include <asm/cache.h>
+#include <asm/tlbflush.h>
 
 void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
                      pte_t *pte)
@@ -12,6 +13,8 @@ void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
        unsigned long addr;
        struct page *page;
 
+       flush_tlb_page(vma, address);
+
        if (!pfn_valid(pte_pfn(*pte)))
                return;