天天看點

cpu cache資訊檢視

近期的工作中需要對cpu的結構做更多的了解,項目中見到比較多cpu cache的資訊,想對其做一個基本的了解。

第一步肯定是希望知道哪裡能看到cpu cache的資訊呢?

有多種辦法,lscpu, cat /proc/cpuinfo等。

這裡發現通過檢視系統的/sys/目錄能看到一些更詳細的資訊。

tree /sys/devices/system/cpu/cpu0/cache/

/sys/devices/system/cpu/cpu0/cache/

├── index0 //L1 data cache

│   ├── coherency_line_size //記錄cache line大小

│   ├── level

│   ├── number_of_sets

│   ├── physical_line_partition

│   ├── shared_cpu_list

│   ├── shared_cpu_map

│   ├── size //cache 大小

│   ├── type  //cache類型

│   └── ways_of_associativity

├── index1 //L1 instruction cache

│   ├── coherency_line_size

│   ├── size

│   ├── type

├── index2 //L2 cache

└── index3 //L3 cache

    ├── coherency_line_size

    ├── level

    ├── number_of_sets

    ├── physical_line_partition

    ├── shared_cpu_list

    ├── shared_cpu_map

    ├── size

    ├── type

    └── ways_of_associativity

舉例:

cat /sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size 

64  //cache line 大小為64位元組