use crate::arch::{__rdtscp, _rdtsc};
pub unsafe fn rdtsc() -> u64 {
_rdtsc() as u64
}
pub unsafe fn rdtscp() -> u64 {
let mut _aux = 0;
__rdtscp(&mut _aux)
}
#[cfg(all(test, feature = "utest"))]
mod test {
use super::*;
#[test]
fn check_rdtsc() {
let cpuid = crate::cpuid::CpuId::new();
let has_tsc = cpuid
.get_feature_info()
.map_or(false, |finfo| finfo.has_tsc());
if has_tsc {
unsafe {
assert!(rdtsc() > 0, "rdtsc returned 0, unlikely!");
}
}
}
#[test]
fn check_rdtscp() {
let cpuid = crate::cpuid::CpuId::new();
let has_rdtscp = cpuid
.get_extended_function_info()
.map_or(false, |einfo| einfo.has_rdtscp());
if has_rdtscp {
unsafe {
assert!(rdtscp() > 0, "rdtscp returned 0, unlikely!");
}
}
}
}