I noticed /proc/cpuinfo
offers a cache line size:
# cat /proc/cpuinfo | egrep "(cache|clflush)"
cache size : 6144 KB
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat
pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon
pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq
ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes xsave avx hypervisor lahf_lm ida arat
epb pln pts dtherm xsaveopt
clflush size : 64
cache_alignment : 64
I'm guessing the kernel uses a CPU instruction (or a CPUID feature for x86/x32/x64) or a table of values compiled offline. I'm interested in getting an accurate value in software to thwart some timing attacks.
I also know the kernel has a static value used at compile time. For example, the kernel uses a cache line length of 64 for ARM during build, but it also switches to a dynamic value at runtime.
How, exactly, does the kernel determine cache line size?
Does the kernel expose an API to retrieve it?
Is it always accurate?