【轉載】[mmu/cache]-Cache Type Register(CTR)暫存器介紹-InProgress
版權宣告:本文為CSDN博主「程式碼改變世界ctw」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/weixin_42135087/article/details/109383407
在ARMV8中,只有CTR_EL0,沒有CTR_EL1/2/3
1、CTR_EL0暫存器介紹
(1)、DminLine/IminLine
Log2 of the number of words in the smallest cache line of all the data caches and unified caches that are controlled by the PE.x
cache line的大小,cache_line_size = 4 * ( 2 x 2^x 2x), x=[19:16], [3:0]
獲取d-cache cache-line的示例程式碼:
.macro dcache_line_size, reg, tmp
mrs \tmp, ctr_el0 // read CTR
ubfm \tmp, \tmp, #16, #19 // cache line size encoding
mov \reg, #4 // bytes per word
lsl \reg, \reg, \tmp // actual cache line size
.endm
其演算法就是:
a. 讀取ctr_el0位元16到19的數值 : tmp = ctr_el0[19:16]
b. 計算cache line大小 : reg = (4 << tmp) = 4 * (2^tmp)
(2)、TminLine
Tag minimum Line. Log2 of the number of words covered by Allocation Tags in the smallest cache
line of all caches which can contain Allocation tags that are controlled by the PE
cache line的大小,tag_size = 4 * ( 2 x 2^x 2x), x=[37:32]
(3)、DIC
Instruction cache invalidation requirements for data to instruction coherence
0b0 Instruction cache invalidation to the Point of Unification is required for data to instruction coherence.
0b1 Instruction cache invalidation to the Point of Unification is not required for data to instruction coherence.
(4)、IDC
Data cache clean requirements for instruction to data coherence
0b0 Data cache clean to the Point of Unification is required for instruction to data coherence,
unless CLIDR_EL1.LoC == 0b000 or (CLIDR_EL1.LoUIS == 0b000 &&
CLIDR_EL1.LoUU == 0b000).
0b1 Data cache clean to the Point of Unification is not required for instruction to data
coherence.
(5)、CWG
Cache writeback granule. Log2 of the number of words of the maximum size of memory
(6)、ERG
Exclusives reservation granule. Log2 of the number of words of the maximum size of the reservation granule
(7)、L1Ip
Level 1 instruction cache policy
0b00 VMID aware Physical Index, Physical tag (VPIPT)
0b01 ASID-tagged Virtual Index, Virtual Tag (AIVIVT)
0b10 Virtual Index, Physical Tag (VIPT)
0b11 Physical Index, Physical Tag (PIPT)
2、程式碼示例
在Linux Kernel程式碼中,讀取CTR_EL0的地方只有三處,分別是:
- raw_icache_line_size
- raw_dcache_line_size
- read_ctr
(**arch/arm64/include/asm/assembler.h**)
/*
* raw_icache_line_size - get the minimum I-cache line size on this CPU
* from the CTR register.
*/
.macro raw_icache_line_size, reg, tmp
mrs \tmp, ctr_el0 // read CTR
and \tmp, \tmp, #0xf // cache line size encoding
mov \reg, #4 // bytes per word
lsl \reg, \reg, \tmp // actual cache line size
.endm
/*
/*
* raw_dcache_line_size - get the minimum D-cache line size on this CPU
* from the CTR register.
*/
.macro raw_dcache_line_size, reg, tmp
mrs \tmp, ctr_el0 // read CTR
ubfm \tmp, \tmp, #16, #19 // cache line size encoding
mov \reg, #4 // bytes per word
lsl \reg, \reg, \tmp // actual cache line size
.endm
.macro read_ctr, reg
alternative_if_not ARM64_MISMATCHED_CACHE_LINE_SIZE
mrs \reg, ctr_el0 // read CTR
nop
alternative_else
ldr_l \reg, arm64_ftr_reg_ctrel0 + ARM64_FTR_SYSVAL
alternative_endif
.endm
而raw_icache_line_size和raw_dcache_line_size並沒有人直接呼叫;
read_ctr被 dcache_line_size 和 icache_line_size呼叫
/*
* dcache_line_size - get the safe D-cache line size across all CPUs
*/
.macro dcache_line_size, reg, tmp
read_ctr \tmp
ubfm \tmp, \tmp, #16, #19 // cache line size encoding
mov \reg, #4 // bytes per word
lsl \reg, \reg, \tmp // actual cache line size
.endm
/*
* raw_icache_line_size - get the minimum I-cache line size on this CPU
* from the CTR register.
*/
.macro raw_icache_line_size, reg, tmp
mrs \tmp, ctr_el0 // read CTR
and \tmp, \tmp, #0xf // cache line size encoding
mov \reg, #4 // bytes per word
lsl \reg, \reg, \tmp // actual cache line size
.endm