Search code examples
cpu-cache

Get 2 different L1 icache line sizes


I am using Ubuntu 12.04 and intel i5 450 on my PC. I used two methods to get the cache line size of the level 1 instruction cache. But results are different.

firo@snow:~/ws$ getconf LEVEL1_ICACHE_LINESIZE

32


firo@snow:~/ws$ cat /sys/devices/system/cpu/cpu0/cache/index1/coherency_line_size 

64

Is there something wrong? It's so confused.


Solution

  • Given an Intel CPU and assuming standard Linux/glibc and no virtualization of cpuid...

    The cache values reported from getconf/sysconf() come from glibc's i386/sysconf.c. The ones in sysfs come from intel_cacheinfo.c.

    The most obvious difference is that sysfs only returns values from cpuid 4, whereas sysconf() first looks at cpuid 2 and only checks cpuid 4 if one of the bytes is 0xFF. There's a discrepancy between the entry for 0x09 in sysconf.c:

        { 0x09,  4, 32, M(_SC_LEVEL1_ICACHE_SIZE),   32768 },
    

    and table 3-22 of the Intel® 64 and IA-32 Architectures Software Developer’s Manual:

    09H | Cache | 1st-level instruction cache: 32KBytes, 4-way set associative, 64 byte line size

    so it looks like a bug in glibc.