plan9fox/sys/src/libc/arm64/cycles.s
cinap_lenrek c38fcb5dc3 arm64: use generic timer virtual counter for cycles()
We used to use performance cycle counter for cycles(),
but it is kind of useless in userspace as each core
has its own counter and hence not comparable between
cores. Also, the cycle counter stops counting when
the cores are idle.

Most callers expect cycles() to return a high resolution
timestamp instead, so do the best we can do here
and enable the userspace generic timer virtual counter.
2021-07-23 15:10:01 +00:00

8 lines
194 B
ArmAsm

#define SYSREG(op0,op1,Cn,Cm,op2) SPR(((op0)<<19|(op1)<<16|(Cn)<<12|(Cm)<<8|(op2)<<5))
#define CNTVCT_EL0 SYSREG(3,3,14,0,2)
TEXT cycles(SB), 1, $-4
MRS CNTVCT_EL0, R1
MOV R1, (R0)
RETURN