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》

相关推荐
沧海一笑-dj11 小时前
【嵌入式】51单片机学习笔记-Keil5软件安装教程
51单片机·嵌入式·keil·keil5·51·keil安装·keil5软件
DIY机器人工房2 天前
关于LVGL中文输入法的设置步骤:
服务器·前端·数据库·stm32·嵌入式硬件·嵌入式·diy机器人工房
菜鸟12号5 天前
详解Linux下多进程与多线程通信(一)
linux·c语言·嵌入式·进程与线程
2301_781143565 天前
江协科技STM32入门教程——通信接口
c语言·嵌入式
网易独家音乐人Mike Zhou6 天前
【Linux应用】开发板USB共享网络,网线或USB以太网共享网络(局域网连接PC和开发板,实现PC给开发板共享网络,USB通过NDIS驱动共享)
linux·网络·单片机·mcu·物联网·嵌入式·iot
Freak嵌入式8 天前
一文速通 Python 并行计算:13 Python 异步编程-基本概念与事件循环和回调机制
开发语言·python·嵌入式·协程·硬件·异步编程
不脱发的程序猿8 天前
SoC程序如何使用单例模式运行
linux·嵌入式
鑫宇吖8 天前
Polyspace作为MISRA-C合规性检查工具,其检查规则会根据目标C语言标准(C90或C99)动态调整限值要求。
c语言·嵌入式·c99·c90·polyspace·misra-c合规性检查
用户1259265423209 天前
使用 Git LFS 管理大文件并上传至 GitHub
嵌入式
巫山老妖9 天前
Linux流量分析:tcpdump&wireshark
linux·嵌入式