Dervin Thunk
Dervin Thunk

Reputation: 20119

Simple cache profiling API

Is there a way I can access the (Intel]) hardware counters for each core programmatically? (that is, no perf, perfmon, or valgrind, and I should add "simple", so no PAPI, e.g.) I'd like to know (for each core) how many L1-LLC cache hits/misses it (= a certain program running on that core) incurred in. This is for Linux 3.2.0-32, C, and using GCC.

Upvotes: 6

Views: 157

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129314

The performance counters in the processor can not be read from "user-mode" code, so you need some sort of kernel module to do this. Once you have that, it's not terribly hard, there are a number of MSR's.

You can perhaps also use /dev/cpu/core-number/msr to read the values without a kernel module.

To describe all the details of how you do this is a little too much for an answer (unless I copy'n'paste the entire section of Intel's programmers manual (Vol3) - which I don't think is quite what we want here...)

Upvotes: 1

Related Questions