天天看点

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字节