Profiling processor cache / memory from OS / application?

I want to write software that can substantially profile the CPU cache (L2, L3, possibly L1) and memory for performance analysis.

Am I right in thinking that this is impossible because there is no access to the software for the contents of the cache?

Another way to formulate my Q: is there any way to find out from the OS / Application level what data was loaded into the cache / memory?

EDIT: Windows or Linux operating system and Intel Desktop / Xeon processor

+7
source share
3 answers

You might want to take a look at the Intel PMU, i.e. performance monitoring unit. Some processors have one. This is a bunch of special purpose registers (Intel calls them specific model registries or MSRs) that you can program to count events, such as cache misses, using the RDMSR and WRMSR .

Here is a document on Performance Analysis on the i7 and Xeon 5500 .

You might want to check out the Intel Performance Counter Monitor , which basically consists of some procedures that abstract the PMU that you can use in a C ++ application to measure several real-time performance metrics, including cache misses. It also has some GUI / Commandline tools for offline use.

The Linux kernel seems to have a tool for managing MSR .

There are other utilities / APIs that also use PMU: perf , PAPI .

+7
source

Cache performance is usually measured in terms of speed and miss speed.

There are many tools for this. Check how Valgrind performs cache profiling .

Also , cache performance is usually evaluated for each program . Well-written programs will result in fewer cache misses and better cache performance and vice versa for poorly written code.

Measuring Actual Cache Speed is a headache for equipment manufacturers, and you can refer to their manuals to know this value.

Callgrind / Cachegrind Combination Helps You Track Cache Hits / Misses

+2
source

There are several examples in this. TAU, an open source profiler that works using PAPI, can also be used.

If, however, you want to write code to measure cache statistics, you can write a program using PAPI. PAPI allows the user to access equipment counters without having to know the system architecture. The PMU uses model-specific registers, so you must have the knwoledge of the registers used.

Perf allows you to measure L1 and LLC (this is L2), Cachegrind, on the other hand, allows the user to measure L1 and LLC (which can be L2 or L3, depending on which cache is at the highest level). Use Cachegrind only if you don't need faster results, because Cachegrind runs the program about 10X slower.

0
source

All Articles