Programmatically measure size and way-order of L1 and L2 caches

Posted by osgx on Stack Overflow See other posts from Stack Overflow or by osgx
Published on 2010-04-05T03:18:36Z Indexed on 2010/04/05 3:53 UTC
Read the original article Hit count: 390

Filed under:
|
|
|
|

How can I measure programmatically (not query the OS, but measure) the size and order of associativity of L1 and L2 caches (data caches)?

Assumptions about system:

  • It has L1 and L2 cache (may be L3 too, may be cache sharing),
  • It may have a hardware prefetch unit (just like P4+),
  • It has a stable clocksource (tickcounter or good HPET for gettimeofday).

There are no assumptions about OS (it can be Linux, Windows, or something non-standard), and we can't use POSIX queries.

Language is C. And compiler optimizations may be disabled.

© Stack Overflow or respective owner

Related posts about cache

Related posts about processor