【相关指令】

在ARMv8-A中,TLB flush/invalidate(通常ARM/x86处理器手册中称为invalidate,linux系统中称为flush,以下的讨论统称为flush)的指令为:

TLBI {IS} {, }
其中,"level"为1到3,对应ARMv8的三个exception level,即EL1,EL2,EL3,通常EL1运行linux等操作系统,EL2在虚拟化模式下运行hypervisor。

"type"相当于一个filter,指按照什么规则去选择被flush的item,包括VA(Virtual Address),IPA(Intermediate Physical Address),ASID(Adress Space Identifier),VMID(Virtual Mechine Identifier)等。在虚拟化模式下,IPA即EL1层的物理地址,它需要经过EL2层的转化才能成为最终的物理地址。ASID是区别有相同虚拟地址的不同进程的,VMID是区别有相同虚拟地址的不同虚拟机的。

"Xt"是可选参数,表示通用寄存器X0到X30。例如 “TLBI VAE1, X0”,表示将flush虚拟地址(type为VA)等于X0寄存器值的这个TLB entry。当然也可以使用“TLBI ALLELn”将TLB中的所有entries全部flush。

“IS”(Inner Shareable)也是可选参数。Inner和Outer是描述cache属性的,通常一个CPU独有的(比如L1 cache)和一个cluster下的CPU共享的(比如L2 cache)被定义为inner,不同cluster的CPU共享的(比如L3 cache)被定义为outer。

TLB也是一种cache,但不管是L1 data/instuction TLB,还是L2 LTB,都是每个CPU单独一份,所以都是inner的。Shareable是描述内存属性的,表示该内存区域是否可被多核共享。

对于多核共享的内存,当其中的某个核,比如,对共享内存中的某个page做了访问限制,它需要通过发出IPI(Inter Processor Interrupt)的方式,来通知其他核flush各自的TLB,这种方式被称为TLB击落(shootdown),在ARM指令上的体现就是TLBI IS。

和ARM使用一条指令配合不同参数来处理不同的TLB flush操作有所不同,作为CISC(复杂指令集)的典型代表,x86采用的是提供多条指令的方式:

INVLPG m - flush地址m所在的page对应的TLB entry,相当于ARM中的VA。
INVPCID - PCID相当于ARM中的ASID。
INVVPID - VPID相当于ARM中的VMID。
INVEPT - EPT是x86虚拟化中hypervisor(运行于ring0 - root级别)使用的页表,相当于ARM中的IPA。
好像没有像ARM的"TLBI ALLELn"那样的可以flush整个TLB的指令?其实上文提到过,只要写CR3寄存器就可以达到这一目的,可是它毕竟是和进程切换绑定的啊,我如果只是单纯想flush整个TLB呢?额,只要往CR3写入的物理地址与CR3现有的值相同就可以了。

【操作系统支持】

基于处理器提供的这些指令,操作系统根据软件应用的需要,封装了一系列的API供软件开发者使用。以Linux为例,

flush_tlb_all() , flush整个TLB,其调用的指令是TLBI VMALLE1IS

dsb(ishst); // ensure write has completed
__tlbi(vmalle1is); // invalidate all TLB entries
dsb(ish); // ensure completion of TLB invalidation
isb(); // synchronize context and ensure that no instructions are fetched using the old translation
flush_tlb_mm(struct mm_struct *mm),flush属于某个进程/address space的TLB,其调用的指令是TLBI ASIDE1IS

unsigned long asid = __TLBI_VADDR(0, ASID(mm));

dsb(ishst);
__tlbi(aside1is, asid);
__tlbi_user(aside1is, asid);
dsb(ish);

参考:

ARM Cortex-A Series Programmer’s Guide for ARMv8-A

/** Based on arch/arm/include/asm/tlbflush.h** Copyright (C) 1999-2003 Russell King* Copyright (C) 2012 ARM Ltd.** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
#ifndef __ASM_TLBFLUSH_H
#define __ASM_TLBFLUSH_H#ifndef __ASSEMBLY__#include <linux/sched.h>
#include <asm/cputype.h>/** Raw TLBI operations.** Where necessary, use the __tlbi() macro to avoid asm()* boilerplate. Drivers and most kernel code should use the TLB* management routines in preference to the macro below.** The macro can be used as __tlbi(op) or __tlbi(op, arg), depending* on whether a particular TLBI operation takes an argument or* not. The macros handles invoking the asm with or without the* register argument as appropriate.*/
#define __TLBI_0(op, arg)       asm ("tlbi " #op)
#define __TLBI_1(op, arg)       asm ("tlbi " #op ", %0" : : "r" (arg))
#define __TLBI_N(op, arg, n, ...)   __TLBI_##n(op, arg)#define __tlbi(op, ...)      __TLBI_N(op, ##__VA_ARGS__, 1, 0)/**    TLB Management* ==============**  The TLB specific code is expected to perform whatever tests it needs*   to determine if it should invalidate the TLB for each call.  Start* addresses are inclusive and end addresses are exclusive; it is safe to* round these addresses down.**   flush_tlb_all()**       Invalidate the entire TLB.**    flush_tlb_mm(mm)**      Invalidate all TLB entries in a particular address space.*      - mm    - mm_struct describing address space**  flush_tlb_range(mm,start,end)**     Invalidate a range of TLB entries in the specified address*     space.*     - mm    - mm_struct describing address space*       - start - start address (may not be aligned)*       - end   - end address (exclusive, may not be aligned)** flush_tlb_page(vaddr,vma)**     Invalidate the specified page in the specified address range.*      - vaddr - virtual address (may not be aligned)*     - vma   - vma_struct describing address range** flush_kern_tlb_page(kaddr)**        Invalidate the TLB entry for the specified page.  The address*      will be in the kernels virtual memory space.  Current uses*     only require the D-TLB to be invalidated.*      - kaddr - Kernel virtual memory address*/
static inline void local_flush_tlb_all(void)
{dsb(nshst);__tlbi(vmalle1);dsb(nsh);isb();
}static inline void flush_tlb_all(void)
{dsb(ishst);__tlbi(vmalle1is);dsb(ish);isb();
}static inline void flush_tlb_mm(struct mm_struct *mm)
{unsigned long asid = ASID(mm) << 48;dsb(ishst);__tlbi(aside1is, asid);dsb(ish);
}static inline void flush_tlb_page(struct vm_area_struct *vma,unsigned long uaddr)
{unsigned long addr = uaddr >> 12 | (ASID(vma->vm_mm) << 48);dsb(ishst);__tlbi(vale1is, addr);dsb(ish);
}/** This is meant to avoid soft lock-ups on large TLB flushing ranges and not* necessarily a performance improvement.*/
#define MAX_TLB_RANGE   (1024UL << PAGE_SHIFT)static inline void __flush_tlb_range(struct vm_area_struct *vma,unsigned long start, unsigned long end,bool last_level)
{unsigned long asid = ASID(vma->vm_mm) << 48;unsigned long addr;if ((end - start) > MAX_TLB_RANGE) {flush_tlb_mm(vma->vm_mm);return;}start = asid | (start >> 12);end = asid | (end >> 12);dsb(ishst);for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12)) {if (last_level)__tlbi(vale1is, addr);else__tlbi(vae1is, addr);}dsb(ish);
}static inline void flush_tlb_range(struct vm_area_struct *vma,unsigned long start, unsigned long end)
{__flush_tlb_range(vma, start, end, false);
}static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end)
{unsigned long addr;if ((end - start) > MAX_TLB_RANGE) {flush_tlb_all();return;}start >>= 12;end >>= 12;dsb(ishst);for (addr = start; addr < end; addr += 1 << (PAGE_SHIFT - 12))__tlbi(vaae1is, addr);dsb(ish);isb();
}/** Used to invalidate the TLB (walk caches) corresponding to intermediate page* table levels (pgd/pud/pmd).*/
static inline void __flush_tlb_pgtable(struct mm_struct *mm,unsigned long uaddr)
{unsigned long addr = uaddr >> 12 | (ASID(mm) << 48);__tlbi(vae1is, addr);dsb(ish);
}#endif#endif
在这里插入代码片

TLB之flush操作[二]相关推荐

  1. Linux内存管理:TLB flush操作

    目录 一.前言 二.基本概念 1.什么是TLB? 2.为什么有TLB? 3.TLB工作原理 三.ARMv8的TLB 1.TLB的组成结构 2.如何确定TLB match 3.进程切换和ASID(Add ...

  2. TLB flush操作

    http://www.wowotech.net/memory_management/tlb-flush.html 一.前言 Linux VM subsystem在很多场合都需要对TLB进行flush操 ...

  3. 深度学习(6)TensorFlow基础操作二: 创建Tensor

    深度学习(6)TensorFlow基础操作二: 创建Tensor 一. 创建方式 1. From Numpy,List 2. zeros,ones (1) tf.zeros() (2) tf.zero ...

  4. GIS基础软件及操作(二)

    原文 GIS基础软件及操作(二) 练习二.管理地理空间数据库 1.利用ArcCatalog 管理地理空间数据库 2.在ArcMap中编辑属性数据 第1步 启动 ArcCatalog 打开一个地理数据库 ...

  5. php 读取mysql 二维数组_PHP操作 二维数组模拟mysql函数

    PHP操作 二维数组模拟mysql函数 public function monimysqltest(){ $testarray=array( array('ss'=>'1','dd'=>' ...

  6. PHP设置谷歌验证器(Google Authenticator)实现操作二步验证

    使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码.实现Google Authenticator功能需要服务 ...

  7. 少儿编程Scratch学习教程5--基本操作(二)动画例子

    本篇介绍下动画相关例子 1.表情的转换 首先创建一个精灵角色 之后在外观选项中,选择"将造型切换为...",这样就可以在特定情况下就可以更换造型了 添加一个事件,当按下" ...

  8. 45-网上商城数据库-商品分类数据操作(二)

    45-网上商城数据库-商品分类数据操作(二) 项目描述 在电子商务兴起的大环境下,建立利用互联网开拓销售渠道,帮助企业及时调整商品结构,协助经销商打开货源的信息门户成为解决信息流通不畅的有效方案,电子 ...

  9. python图像数据是几维数据_Python图像处理库PIL的ImagePath模块被用于存储和操作二维向量数据...

    ImagePath模块被用于存储和操作二维向量数据.Path对象会被传递到ImageDraw模块中. 一.ImagePath模块的函数 1. Path 定义:ImagePath.Path(coordi ...

最新文章

  1. GitHub高效搜索
  2. Windows Azure Cloud Service (27) 在Windows Azure发送邮件(上)
  3. urllib post请求 cookie
  4. ES6学习(新增字符串方法)
  5. 使用过这么多年Hibernate,对底层原理你知多少?
  6. 11组软件工程组队项目失物招领系统——界面设计文档
  7. php怎么打印json数据,php输出json格式数据的例子
  8. Java-API:java.util.ArrayList
  9. Ubuntu各文件夹功能说明
  10. cvMorphologyEx() 多种图像形态学
  11. 软考中级网络工程师学习笔记(知识点汇总)普通版
  12. Shottr 免费好用的Mac 截屏软件
  13. docker搭建searx_『颜值即正义』看小睿“自建搜索引擎”
  14. Vue基础-输入文本框
  15. AppStore 新功能解读:自定义产品页面和 A/B Test 工具(iOS)
  16. Python的解包知识
  17. Android系统自定义关机充电图标
  18. 【读论文-笔记】——1.沐神读Alexnet
  19. SpringCloud Alibaba Sentinel实现熔断与断流
  20. 高并发架构系列:什么是流量削峰?如何解决秒杀业务的削峰场景

热门文章

  1. 不关闭防火墙 投屏方法
  2. java回调函数的生命_Java车票,车站,生命周期,龟兔赛跑,同步锁,礼让,守护线程,挖金矿【诗书画唱】...
  3. 即将上线的华为百花号自媒体平台 究竟值不值得期待?
  4. 安卓集成微信登录 无法调取微信页面的问题
  5. mate10android通知,Android P明日适配华为Mate10
  6. 观后感笔记-20211121沈定刚教授在valse上的特邀报告
  7. CSS三角形及其点击切换
  8. 个人成长的 15 种能力
  9. 时间同步:适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位
  10. oracle中如何查看端口号,Oracle EMGC查看端口