Read Cycle Counter

Read a monotonically increasing hardware counter for timing.

System

Semantics

Every architecture provides one, but they differ in whether the counter measures core cycles or a fixed-rate clock, and in whether user code may read it without the OS enabling access.

Architecture Instructions Expressed as How this architecture does it
x86 one instruction Returns the time-stamp counter in EDX:EAX. On modern parts the TSC is invariant to frequency scaling and sleep states, which is what lets it be used as a clock rather than a cycle count. It can be restricted to privileged code by a control register bit.
ARM one instruction MRS reading CNTVCT_EL0 gives the virtual counter, a fixed-frequency system counter rather than core cycles, and is normally readable from user space. Actual cycle counts come from PMCCNTR_EL0, which the OS must enable first.
RISC-V one instruction Two counters kept deliberately separate: RDCYCLE counts core cycles and RDTIME a constant-rate wall clock, so code cannot silently confuse the two on a part that scales frequency. Both are CSR reads the OS may trap.
PowerISA one instruction MFTB reads the Time Base, a constant-rate counter readable from user mode. Cycle-accurate counts come from the performance monitor SPRs through MFSPR, which are privileged.