I have run this test code several times.
The code set up and start performance counter withing one of the processor cores. Reads the counter, sleep for a 1 sec and then it reads counter again. Returned values are meaningful only when the sleep() is commented out of the code. Otherwise read after sleep() returns 0.
most probably the counter is overflowing in 1 second delay.
Is that all of your code or just a sample for us to view?
Does it works fine when the sleep(1) is not used but maybe some other dummy code is used?
or you sleep/spin for lesser time, lets say in microseconds?
We are getting counter values after sleep also when we ran your test code.
Please check if EN bit[0] is set in “pmuserenr_el0” register from kernel space(EL1) for all cpu’s.
$ ./test
Starting test…
Value of counter 1: 0x20e6c3b9
Test successful (Value of counter 1 is: 0x20e8f733)
$ ./test
Starting test…
Value of counter 1: 0x21054bff
Test successful (Value of counter 1 is: 0x21078e84)
$ taskset 2 ./test
Starting test…
Value of counter 1: 0x7b2dba
Test successful (Value of counter 1 is: 0x7d1a37)
$ taskset 3 ./test
Starting test…
Value of counter 1: 0xa366c0
Test successful (Value of counter 1 is: 0xa5716f)
thank you for your attention. Have run the test on the original kernel? In my case it sometimes run correctly and most of the time it doesn’t. Would you mind to reflash the kernel and try it one more time?
Read from PMCNTENSET_EL0 register returns 0x0 after the sleep. That is why the counters are not counting anymore. I do not know why they are suddenly disabled and I cant find anything about it. All this behavior could be replicated in kernel mode with same result. I have posted user space aplication example just because it is little bit shorter.
I have tried to build my own kernel from sources provided by NVIDIA. I have modified the .config (disable/enable the perf API and so on) but the result was all the same. After many tries and reflashing the kernel I got a feeling that it does depend on the flashing itself. One version of the kernel worked but when I tried to reflash it with the SAME version counters stoped counting.
Counters do not overflow. If I use some busy loop instead of sleep it works. If I use usleep() it works for values less than 800. So, counters wont reset if delay is less than 800us.
Posted code and tar files are all that was flased into Jetson X1. Nothing else runned.
In case you directly want to use pmu counters instead of above mentioned syscall, then please disable cpuidle or pass “nohlt” parameter to kernel command line.