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》

相关推荐
硬匠的博客6 小时前
一文读懂Type-C接口
嵌入式·pcb
大聪明-PLUS17 小时前
6 个 Docker 高级功能
linux·嵌入式·arm·smarc
华清远见IT开放实验室1 天前
STM32学习路线!软硬件兼修:裸机+RTOS+LVGL+硬件设计+项目实战 (STM32多核心开发板)
stm32·嵌入式·开发板·rtos·课程·软硬件·裸机开发
做一道光2 天前
2、SVPWM原理及实现学习笔记
笔记·学习·嵌入式·电机控制
华清远见成都中心2 天前
嵌入式需要掌握哪些核心技能?
物联网·学习·嵌入式·华清远见
DIY机器人工房2 天前
要解决 ESP32 与 STM32 之间 LoRa 通信无应答的问题,可从以下硬件、软件、参数匹配三个维度逐一排查:
stm32·单片机·嵌入式硬件·lora·嵌入式·diy机器人工房
大聪明-PLUS3 天前
Linux 中的 DNS 工作原理(二):各级 DNS 缓存
linux·嵌入式·arm·smarc
冷凝雨3 天前
FreeRTOS源码学习(一)内存管理heap_1、heap_3
嵌入式·c·freertos·内存管理·源码分析
Y unes3 天前
《i.MX6ULL LED 驱动实战:内核模块开发与 GPIO 控制》
linux·c语言·驱动开发·vscode·ubuntu·嵌入式
优信电子4 天前
电脑控制DFPlayer Mini MP3播放音乐
单片机·串口·嵌入式·mp3·语音播报·串口语音·mp3播报