tscnsuses a global static variable to cache the clock counter and system clock reference difference.tscnsis thread-safe.tscnsglobally uses the atomicAtomicUsizetype and aligns it to the CPU cache line, ensuring performance during multi-threaded access.- CPU cache line alignment relies on
[crossbeam_utils::CachePadded], andCachePaddedis suitable for most platforms.
- x86_64
- On x86_64, the value of the
Counterregister is obtained via therdtscinstruction, 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_el0register 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
regregister 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