bolts: add time ticks method for arm (#2032)

This commit is contained in:
David CARLIER 2024-04-10 00:01:27 +01:00 committed by GitHub
parent c4f076356f
commit d3b3d5d462
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,12 +1,13 @@
//! Architecture agnostic processor features
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
use core::arch::asm;
#[cfg(not(any(
target_arch = "x86_64",
target_arch = "x86",
target_arch = "aarch64",
target_arch = "arm",
target_arch = "riscv64",
target_arsch = "riscv32"
)))]
@ -50,6 +51,16 @@ pub fn read_time_counter() -> u64 {
v
}
#[cfg(target_arch = "arm")]
#[must_use]
pub fn read_time_counter() -> u64 {
let mut v: u32;
unsafe {
asm!("mrc p15, 0, {v}, c9, c13, 0", v = out(reg) v);
}
u64::from(v)
}
/// Read a timestamp for measurements
///
/// Fetches the full 64 bits of the cycle counter in one instruction.
@ -99,6 +110,7 @@ pub fn read_time_counter() -> u64 {
target_arch = "x86_64",
target_arch = "x86",
target_arch = "aarch64",
target_arch = "arm",
target_arch = "riscv64",
target_arch = "riscv32"
)))]