Created
January 31, 2020 22:17
-
-
Save bradley-evans/ecdac395a1a0302aed7474b6cf0f45df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int loop(int n, int a) { | |
int b = 0; | |
for(int i=0; i<n; i++) { | |
b = a + b; | |
} | |
return b; | |
} | |
int main() { | |
int a = 1; | |
int n = 200; | |
int count = 0; | |
// initialize counters here | |
// should start tracking cache misses with 0x100 | |
__asm__ volatile("csrw mhpmevent00, 0x100"); | |
loop(n, a); | |
// read counters here | |
__asm__ volatile("csrr %0, mhpmcounter00" | |
: "=r"(count) | |
); | |
printf("Cache misses: %d\n", count); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment