Displaying CPU cache hierarchy on Linux

This is a note to myself as much as anything, since it took a minute to get the command right, but maybe someone else will find it useful. The following command will dump the cache hierarchy for CPU 0 in a fairly readable format (though I truncated the shared_cpu_map entries by hand for purposes of this blog post).

$ find /sys/devices/system/cpu/cpu0/cache/ -type f -printf '%P: ' -exec cat '{}' \;
index0/type: Data
index0/level: 1
index0/coherency_line_size: 64
index0/physical_line_partition: 1
index0/ways_of_associativity: 2
index0/number_of_sets: 512
index0/size: 64K
index0/shared_cpu_map: 00000001
index0/shared_cpu_list: 0
index1/type: Instruction
index1/level: 1
index1/coherency_line_size: 64
index1/physical_line_partition: 1
index1/ways_of_associativity: 2
index1/number_of_sets: 512
index1/size: 64K
index1/shared_cpu_map: 00000001
index1/shared_cpu_list: 0
index2/type: Unified
index2/level: 2
index2/coherency_line_size: 64
index2/physical_line_partition: 1
index2/ways_of_associativity: 16
index2/number_of_sets: 512
index2/size: 512K
index2/shared_cpu_map: 00000001
index2/shared_cpu_list: 0
index3/type: Unified
index3/level: 3
index3/coherency_line_size: 64
index3/physical_line_partition: 1
index3/ways_of_associativity: 48
index3/number_of_sets: 1706
index3/size: 5118K
index3/shared_cpu_map: 0000000f
index3/shared_cpu_list: 0-3
index3/cache_disable_0: FREE
index3/cache_disable_1: FREE

One Comment

Leave a Reply to Vivek Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.