1

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

2 Answers 2

0

Is that instruction supported by db410c?

Also, are you using 64-bits? I think pmccntr_el0 is not supported by 32-bits.

You can try the following code, to check if the problem is that db410c does not support that instruction. (The following code works on 32-bits):

unsigned int cc;
asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc));
return cc;

Here you can find more ways to play with monitoring performance http://wiki.dreamrunner.org/public_html/Embedded-System/Cortex-A8/PerformanceMonitorControlRegister.html

Also, remember that when you compile, adding the flag -O3 will yield extremely different performance results.

0
0

found out reason, it needs properly to be enabled user mode access bit.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 20, 2022 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .