Unable to Set Performance Counter

I’m using Hikey960 running the minimized buildroot OPTEE Linux. I want to configure some PMU events so that firstly I choose to get the value of cycle counter. But I failed to configure the PMU register well: it seems that PMU registers are reset soon. So I did some experiments for your reference.

In kernel init I write the values I want into PMU register like pmintenset_el1, pmcntenset_el0, pmuserenr_el0, pmcr_el0, pmccfiltr_el0 …Also I read and print their values after I set them. All registers above are set well and I successfully get the cycle count from pmccntr_el0 just in kernel’s init function. Then so strange is that I can only get 0 from pmccntr_el0 in any other kernel module(and I have no right to access it from userspace, inferring that pmuserenr_el0 is not configured well).

And when I code some reading of PMU registers I set before in the kernel exit and print them out: the result shows that like I never have set anyone of them!!!

btw, I tried the on_each_cpu() to set all 8 cores and the result is the same.

Anyone’s ideas would be extremely helpful!