tscns
uses a global static variable to cache the clock counter and system clock reference difference.tscns
is thread-safe.tscns
globally uses the atomicAtomicUsize
type and aligns it to the CPU cache line, ensuring performance during multi-threaded access.- CPU cache line alignment relies on
[crossbeam_utils::CachePadded]
, andCachePadded
is suitable for most platforms.
- x86_64
- On x86_64, the value of the
Counter
register is obtained via therdtsc
instruction, and the clock source frequency is calculated through a random sampling rate. The frequency is aligned with the system clock source.
- On x86_64, the value of the
- arm64
- On arm64, the value of the
cntvct_el0
register is obtained via the inline assembly instructionmrs
, and the clock source frequency is calculated through a random sampling rate. The frequency is aligned with the system clock source.
- On arm64, the value of the
- mips64
- On mips64, the value of the
reg
register is obtained via the inline assembly instructionrdtime
, and the clock source frequency is calculated through a random sampling rate. The frequency is aligned with the system clock source.
- On mips64, the value of the