My goal is to read CPU cycle with ARMv8 registers, and both kmod and my test program works fine on my ARM laptop. However, on my db410c board after loading the kmod, when executing the binary to access the pmccntr_el0 I get Illegal instruction.
Anyone could help me understand why? Since I have already enable the user mode access via PMUSERENR_EL0_EN bit.
This is the example code for the testing program
#include <stdio.h> #include <stdint.h> static inline uint64_t read_pmccntr(void) { uint64_t val; asm volatile("mrs %0, pmccntr_el0" : "=r"(val)); return val; } int main(){ uint64_t counter = read_pmccntr(); printf("value:%lu\n",counter); return 0; } os version:
- laptop: Linux debian-gnu-linux-10 4.19.0-18-arm64
- db410c: Linux linaro-developer 5.15.0-stm-qcomlt-arm64