I'm trying to get an accurate description of the data cache hierarchy of the current CPU on Linux: not just the size of individual L1/L2/L3 (and possibly L4) data caches, but also the way they are split or shared across cores.
For instance, on my CPU (AMD Ryzen Threadripper 3970X), each core has its own 32 KB of L1 data cache and 512 KB of L2 cache, however the L3 cache is shared across cores within a core complex (CCX). In other words, there are 8 distinct L3 caches, each of 16 MB.
The "Cache" section of this screenshot of CPU-Z on Windows is basically what I'm trying to find out:
I have no problem getting these information on Windows with GetLogicalProcessorInformation()
.
However, on Linux, it appears that sysconf()
only gives me either the per-core cache size for L1 and L2 data caches (_SC_LEVEL1_DCACHE_SIZE
and _SC_LEVEL2_DCACHE_SIZE
), or the total L3 cache size (_SC_LEVEL3_CACHE_SIZE
).
EDIT: lstopo's output under VMWare. The virtual machine has 8 cores. L1 and L2 cache information are fine but L3 cache size does not appear to be correct: