2

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?

2
  • You are supposed to upvote an answer you find helpful, or just significant. Also, since you are the poster of the original question, you are supposed to accept it, if it really addressed fully your query. Oct 13, 2015 at 14:48
  • @Marius - I know how the Stack Exchange network works, so I'm not exactly sure what your point is... Two of the three questions were unanswered.
    – jww
    Oct 13, 2015 at 14:53

1 Answer 1

2

The CPUID instruction with EAX=2 returns cache and TLB information in the EAX, EBX, ECX, and EDX registers.

See for example, http://x86.renejeschke.de/html/file_module_x86_id_45.html with INPUT EAX=2 which documents the return values.

Note that it is possible to override the CPUID instruction such as inside a VM, though you may not care about that case.

1
  • Thanks. The processor I'm most interested in is ARM because (1) we have x86/x32/x64 code, and (2) ARM is a popular CPU in mobile. We also support MIPS and lesser knowns, like S/390. Hence the reason I was wondering if the kernel offered an API to retrieve it; and if it was really accurate (or just an estimate).
    – jww
    Oct 13, 2015 at 14:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .