如何在 Linux 中刷新地址空间区域的 CPU 缓存? [英] How to flush the CPU cache for a region of address space in Linux?

查看:35
本文介绍了如何在 Linux 中刷新地址空间区域的 CPU 缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对仅针对地址空间区域刷新缓存(L1、L2 和 L3)感兴趣,例如从地址 A 到地址 B 的所有缓存条目.在 Linux 中是否有这样做的机制,无论是来自用户还是内核空间?

解决方案

查看此页面以获取 linux 内核中可用的刷新方法列表:https://www.kernel.org/doc/Documentation/cachetlb.txt

<块引用>

Linux 下的缓存和 TLB 刷新.大卫·米勒

有一组范围刷新函数

2) flush_cache_range(vma, start, end);change_range_of_page_tables(毫米,开始,结束);flush_tlb_range(vma,开始,结束);

<块引用>

3) void flush_cache_range(struct vm_area_struct *vma,无符号长开始,无符号长结束)

这里我们正在刷新特定范围的(用户)虚拟来自缓存的地址.运行后就没有了'vma->vm_mm' 的缓存中的条目用于虚拟地址范围开始"到结束 1".

您还可以检查函数的实现 - http://lxr.free-electrons.com/ident?a=sh;i=flush_cache_range

例如,在 arm - 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, 开始, 结束);71返回;72 }7374 if (cache_is_vipt_aliasing()) {75 asm("mcr p15, 0, %0, c7, c14, 0
"76" mcr p15, 0, %0, c7, c10, 4"77:78:r"(0)79:抄送");80 }8182 if (vma->vm_flags & VM_EXEC)83 __flush_icache_all();84 }

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

Cache and TLB Flushing Under Linux. David S. Miller

There are set of range flushing functions

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'.

You can also check implementation of the function - http://lxr.free-electrons.com/ident?a=sh;i=flush_cache_range

For example, in arm - 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
"
 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆