Debian Codegraph @

debian/rust-vendor/codspeed-divan-compat-walltime/src/time/timestamp/tsc/aarch64.rs

raw
1 use std::arch::asm;
2
3 use crate::time::TscUnavailable;
4
5 /// Reads the [`cntfrq_el0`](https://developer.arm.com/documentation/ddi0595/2021-12/AArch64-Registers/CNTFRQ-EL0--Counter-timer-Frequency-register?lang=en)
6 /// register.
7 ///
8 /// This value is set on system initialization and thus does not change between
9 /// reads.
10 #[inline]
11 pub(crate) fn frequency() -> Result<u64, TscUnavailable> {
12 unsafe {
13 let frequency: u64;
14 asm!(
15 "mrs {}, cntfrq_el0",
16 out(reg) frequency,
17 options(nomem, nostack, preserves_flags, pure),
18 );
19 Ok(frequency)
20 }
21 }
22
23 /// Reads the [`cntvct_el0`](https://developer.arm.com/documentation/ddi0595/2021-12/AArch64-Registers/CNTVCT-EL0--Counter-timer-Virtual-Count-register?lang=en)
24 /// register.
25 #[inline(always)]
26 pub(crate) fn timestamp() -> u64 {
27 unsafe {
28 let timestamp: u64;
29 asm!(
30 "mrs {}, cntvct_el0",
31 out(reg) timestamp,
32 // Leave off `nomem` because this should be a compiler fence.
33 options(nostack, preserves_flags),
34 );
35 timestamp
36 }
37 }