I'm trying to get timestamp counter (TSC) of CPU. I've succeeded on my PC with Intel i7 CPU. Assembly code in this links helped me.
Now, I want to do it on my Raspberry Pi model B. The problem is ARmv6 has a different instruction set from Intel CPU. And user-mode
prvents me from using some instructions. So I've searched some article to solve it.
But it didnt' work well as I expected. When I run the following two codes (with sudo privilege):
int main(void){
// printf("try to enable user mode access to performance counter\n");
asm("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1));
// printf("disable counter overflow interrupts (just in case)\n");
asm("MCR p15, 0, %0, C9, C14, 2\n\t" :: "r"(0x8000000f));
return 0;
}
and
#include <stdio.h>
static inline unsigned int get_cyclecount(void) {
unsigned int value;
// Read CCNT Register
asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));
return value;
}
int main(void){
unsigned int t = get_cyclecount();
printf("%d\n", t);
return 0;
}
It prints nothing even there is printf