No longer builds, but this is a good intermediate save point.
[akaros.git] / kern / arch / x86 / perfmon.c
1 #include <arch/perfmon.h> 
2
3
4 static void setup_counter(int index, uint8_t mask, uint8_t event) {
5         //just a magic number for now to indicate the most common case
6         uint32_t os_user_enabled = 0x43;
7         write_msr(IA32_PERFEVTSEL_BASE + index, (os_user_enabled<<16 | mask<<8 | event));
8 }
9
10 void perfmon_init() {
11 #if 0
12         // Examples of how to set up for cache misses:
13         setup_counter(0, LLCACHE_REF_MASK, LLCACHE_EVENT);
14         setup_counter(1, LLCACHE_MISS_MASK, LLCACHE_EVENT);
15 #endif
16
17         /* Enable user level access to the performance counters */
18         lcr4(rcr4() | CR4_PCE);
19 }