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》

相关推荐
小嵌同学1 小时前
Linux 内核中的 Per-CPU 机制详解
linux·运维·arm开发·嵌入式
jufeng13074 小时前
【系列:uC/OS-II 内核源码精读:从 6736 行代码看懂一个 RTOS · 第 3 篇】
嵌入式·实时操作系统·rtos·uc/os-ii
捷瑞电子工坊14 小时前
FreeRTOS任务管理:从入门到实践(标准库版)
stm32·嵌入式·freertos·实时操作系统·任务管理·标准外设库·任务挂起与恢复
深念Y1 天前
JMS583 USB-NVMe 桥接芯片 LED 控制探索
嵌入式硬件·嵌入式·led·usb·电子·维修·硬盘盒
橘色的喵1 天前
USB MCU的固件烧写工具:从 vendor 命令到逐字节校验
单片机·嵌入式硬件·嵌入式
小僧景贤1 天前
嵌入式之队列解析(裸机/RTOS通用原理+实战场景+源码解析)
数据结构·嵌入式·队列·裸机开发·rtos开发·固件架构
国产化创客1 天前
AI时代全栈嵌入式开发学习路线
人工智能·嵌入式硬件·物联网·嵌入式·学习路线·知识体系·具身智能
BreezeJuvenile2 天前
嵌入式C语言常见考察点(2)
c语言·嵌入式
左手厨刀右手茼蒿3 天前
数据仓库的架构演进:从MySQL到ClickHouse到数据湖的工程化实践
linux·嵌入式·系统内核
左手厨刀右手茼蒿3 天前
创业团队技术选型:别用大厂架构解决小团队问题
linux·嵌入式·系统内核