如何在Linux中刷新地址空间区域的CPU缓存? [英] How to flush the CPU cache for a region of address space in Linux?
问题描述
我只对地址空间的某个区域刷新缓存(L1,L2和L3)感兴趣,例如,从地址A到地址B的所有缓存条目.在Linux中,有没有一种机制可以做到这一点?或内核空间?
I am interested in flushing cache (L1, L2, and L3) only for a region of address space, for example all cache entries from address A to address B. Is there a mechanism to do so in Linux, either from user or kernel space?
推荐答案
Check this page for list of available flushing methods in linux kernel: https://www.kernel.org/doc/Documentation/cachetlb.txt
Linux下的缓存和TLB刷新.大卫·米勒(David S. Miller)
Cache and TLB Flushing Under Linux. David S. Miller
有一组范围刷新功能
2) flush_cache_range(vma, start, end);
change_range_of_page_tables(mm, start, end);
flush_tlb_range(vma, start, end);
3)void flush_cache_range(struct vm_area_struct * vma, 无符号的长期开始,无符号的长期结束)
3) void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
Here we are flushing a specific range of (user) virtual
addresses from the cache. After running, there will be no
entries in the cache for 'vma->vm_mm' for virtual addresses in
the range 'start' to 'end-1'.
您还可以检查该功能的实现- http://lxr .free-electrons.com/ident?a = sh; i = flush_cache_range
You can also check implementation of the function - http://lxr.free-electrons.com/ident?a=sh;i=flush_cache_range
例如,在手臂中- http://lxr.free-electrons.com/source/arch/arm/mm/flush.c?a=sh&v=3.13#L67
67 void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
68 {
69 if (cache_is_vivt()) {
70 vivt_flush_cache_range(vma, start, end);
71 return;
72 }
73
74 if (cache_is_vipt_aliasing()) {
75 asm( "mcr p15, 0, %0, c7, c14, 0\n"
76 " mcr p15, 0, %0, c7, c10, 4"
77 :
78 : "r" (0)
79 : "cc");
80 }
81
82 if (vma->vm_flags & VM_EXEC)
83 __flush_icache_all();
84 }
这篇关于如何在Linux中刷新地址空间区域的CPU缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!