enabling performance monitoring register to user a

2019-09-14 09:56发布

问题:

I have written code to enable performance monitoring register as user accessible by setting bit as 1. I getting ARM_BAD_INSTRUCTION at MCR instruction and MRC is going fine.

I am using armv7(cortex a5)

.cfi_startproc

MRC     p15, 0, r0, c9, c14, 0  @ Read PMUSERENR Register
ORR     r0, r0, #0x01           @ Set EN bit (bit 0)
MCR     p15, 0, r0, c9, c14, 0  @ Write PMUSERENR Register
ISB                             @ Synchronize context

BX lr .cfi_endproc

回答1:

As per the documentation, PMUSERENR is only writeable from privileged modes, thus an attempt to write to it from unprivileged userspace will indeed raise an undefined instruction exception.

If you want to enable userspace access, you need to do it from the kernel (or possibly from a hypervisor/firmware in the case of a kernel which doesn't know about PMUs itself).

If you don't have control of any such privileged software, well then you're not getting yourself direct access, because that's rather the point of the notion of privilege. What you might have, however, is some userspace API provided by the OS - such as perf events on Linux - to let you profile and measure stuff without the hassle of managing the hardware directly; frankly that's usually the better option even if you could enable direct access, because userspace still has no way to properly handle all the necessary event filtering, scheduling, overflow interrupts, etc. on a multitasking system.



标签: arm