osgx osgx - 1 year ago 126
C Question

Measure size and way-order of L1 and L2 caches

How can I programmatically measure (not query the OS) 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 else), and we can't use POSIX queries.

Language is C, and compiler optimizations may be disabled.

Answer Source

There is a program on Figure 5.32 on page 352 in Computer Architecture: A Quantitative Approach, 4th Edition. This was used at my university for a lab together with question 5.18 in the same book.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download