ami*_*far 14 c linux x86 arm linux-kernel
我感兴趣的是仅针对地址空间区域刷新缓存(L1,L2和L3),例如从地址A到地址B的所有缓存条目.在Linux中是否存在从用户或内核空间执行此操作的机制?
osg*_*sgx 10
查看此页面以获取linux内核中可用的刷新方法列表:https://www.kernel.org/doc/Documentation/cachetlb.txt
Linux下的缓存和TLB刷新.大卫·米勒
有一套范围冲洗功能
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,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
例如,在手臂 - 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 }
这是针对ARM的.
GCC提供__builtin___clear_cache其不应该做的系统调用cacheflush.然而,它可能有其警告.
这里重要的是Linux提供了一个系统调用(特定于ARM)来刷新缓存.您可以查看Android/Bionic flushcache以了解如何使用此系统调用.但是我不确定Linux在你调用它时给出了什么样的保证,或者它是如何通过它的内部工作来实现的.
此博客文章缓存和自我修改代码可能会有所帮助.