cache操作:clean、invalidate与flush的含义

前言

本文试图搞清楚cache几个操作:clean、invalidate与flush的含义。由于只用过ARM和RISC-V,所以是从ARM和RISC-V的角度来说明。

cache line

cache line是cache的基本访问单元。

cache line一般都会包含valid和dirty两个状态位,如下图的v和d。

valid位表示当前cache line的内容是否有效。dirty位表示当前cache line的内容是否比内存上的要更新(即是否修改过)。

cache操作

clean和invalidata两个操作都可以在ARM官方文档上找到描述,但是flush没找到。而RISC-V则都没找到。

clean

clean表示把cache line的dirty位清0,并把cache line的数据同步到内存上,目的是保证cache与内存的数据一致性。仅适用于使用回写(write-back)策略的D-cache。

Applies to write-back data caches, and means that if the cache line contains stored data that has not yet been written out to main memory, it is written to main memory now, and the line is marked as clean.

invalidate

invalidate表示把cache line的valid位清0。

Means that the cache line (or all the lines in the cache) is marked as invalid, so that no cache hits occur for that line until it is re-allocated to an address. For write-back data caches, this does not include cleaning the cache line unless that is also stated.

flush

flush有查到两种含义:

  • flush = invalidate

在《arm system developer's guide》中有描述到:

The term invalidate is sometimes used in place of the term flush.

  • flush = clean + invalidate

SiFive(提供基于RISC-V指令集CPU IP的公司)关于cache有一条自定义命令:CFLUSH.D.L1,其中有描述:

writes back and invalidates line(s) in the L1 data cache

所以这里flush相当于clean + invalidate。

参考资料

《ARM Architecture Reference Manual (2nd Edition)》

《ARM System Developer's Guide》

《SiFive E76-MC Core Complex Manual》

相关推荐
大辉狼_音频架构16 小时前
AudioReach Plugin 机制问题解答
嵌入式·音视频开发
大辉狼_音频架构20 小时前
AudioReach:Tinyalsa PCM Plugin 机制
嵌入式·音视频开发
feasibility.1 天前
从数字智能到物理智能体:深度解构具身智能时代的边缘计算、嵌入式实时系统与多形态智能体
人工智能·机器人·自动驾驶·嵌入式·无人机·具身智能·智能体
ajassi20002 天前
AI语音智能体开发日记(一)如何为“小智”服务器启用并调试 License 功能
笔记·ai·嵌入式·ai编程
ARM+FPGA+AI工业主板定制专家3 天前
国产化RK3576+FPGA架构|晶圆传输机器人高速定位+AI瑕疵检测一体化方案
fpga开发·架构·机器人·嵌入式·fpga·工控·机器人运控
Discipline~Hai3 天前
ARM03-蜂鸣器和中断
c语言·arm开发·单片机·嵌入式硬件·嵌入式
一杯原谅绿茶3 天前
安卓烧录工具PhonixCard-4.2.8下载
嵌入式
青衫嵌入式4 天前
FreeRTOS中断优先级配置不对也会HardFault?这次用一个血的教训讲明白
嵌入式
零涂毕业设计5 天前
毕业设计模块开发-OLED显示屏(IIC协议0.96寸)STM32 ESP32 FPGA Linux驱动免费分享
linux·stm32·单片机·嵌入式·esp32·fpga·oled
wdfk_prog5 天前
嵌入式面试真题第 13 题:单硬件 Timer 下的高精度多路软件定时器架构设计
c语言·开发语言·面试·职场和发展·嵌入式