1 use crate::time::{clocksource::HZ, TimeArch}; 2 3 use super::driver::tsc::TSCManager; 4 5 /// 这个是系统jiffies时钟源的固有频率(不是调频之后的) 6 pub const CLOCK_TICK_RATE: u32 = HZ as u32 * 1000000; 7 8 pub fn time_init() { 9 // do nothing 10 } 11 12 pub struct X86_64TimeArch; 13 14 impl TimeArch for X86_64TimeArch { 15 #[inline(always)] 16 fn get_cycles() -> usize { 17 unsafe { x86::time::rdtsc() as usize } 18 } 19 20 fn cal_expire_cycles(ns: usize) -> usize { 21 Self::get_cycles() + ns * TSCManager::cpu_khz() as usize / 1000000 22 } 23 24 /// 将CPU的时钟周期数转换为纳秒 25 #[inline(always)] 26 fn cycles2ns(cycles: usize) -> usize { 27 cycles * 1000000 / TSCManager::cpu_khz() as usize 28 } 29 } 30