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》

相关推荐
K成长日志14 小时前
BLE协议之设备地址
网络·物联网·网络协议·嵌入式·蓝牙·ble
凉、介16 小时前
ARMv8 架构下的刷 Cache 操作
c语言·笔记·学习·架构·嵌入式·arm
会周易的程序员1 天前
microLog 的本地日志读取接口 log_reader — 本地日志文件读取工具开发指南
linux·物联网·架构·嵌入式·日志·iot·aiot
charlie1145141911 天前
Cinux: 加载第一个内核:从 bootloader 跳进 C++
linux·开发语言·c++·嵌入式
dddwjzx2 天前
嵌入式Linux C应用编程入门——标准IO库
嵌入式
pai同学2 天前
ESP-IDF+vscode开发ESP32第十二讲——event
嵌入式
凉、介2 天前
KVM + QEMU 虚拟化
笔记·学习·嵌入式·arm·qemu·虚拟化·kvm
dddwjzx2 天前
嵌入式Linux C应用编程入门——文件IO进阶
嵌入式
2023自学中3 天前
imx6ull 开发板, mame 模拟器,运行游戏 测试
linux·游戏·嵌入式·开发板
dddwjzx3 天前
嵌入式Linux C应用编程入门——文件IO
嵌入式