Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple cache profiling API

Tags:

c

linux

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.

like image 384
Dervin Thunk Avatar asked Nov 15 '12 12:11

Dervin Thunk


1 Answers

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...)

like image 159
Mats Petersson Avatar answered Oct 17 '22 19:10

Mats Petersson