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》

相关推荐
嵌入式×边缘AI:打怪升级日志1 天前
USB描述符
学习笔记·嵌入式·usb
铜豌豆_Y2 天前
【实用】GDB调试保姆级教程|常用操作|附笔记
linux·c语言·驱动开发·笔记·嵌入式
zhuanshulz2 天前
Gem5 预取机制介绍
cache·gem5·prefetcher
星源~2 天前
VsCode-单片机开发环境配置指定编译器
ide·vscode·单片机·物联网·嵌入式
迷人的星空2 天前
用对这些常识,嵌入式文件系统少踩坑?
物联网·嵌入式
charlie1145141913 天前
现代嵌入式C++教程:C++98——从C向C++的演化(2)
c语言·开发语言·c++·学习·嵌入式·教程·现代c++
月光技术杂谈3 天前
Linux发展到6.0了,其在嵌入式应用中,实时性方面有没有一些改进?
linux·嵌入式·实时性
切糕师学AI5 天前
Azure RTOS ThreadX 简介
microsoft·嵌入式·azure·rtos
飞凌嵌入式5 天前
AIoT出海背景下,嵌入式主控的国际认证之路与价值思考
大数据·人工智能·嵌入式硬件·区块链·嵌入式
小柯博客5 天前
从零开始打造 OpenSTLinux 6.6 Yocto 系统 - STM32MP2(基于STM32CubeMX)(九)
c语言·stm32·单片机·嵌入式硬件·物联网·嵌入式·yocto