1 //! 这个文件实现的是调度过程中涉及到的时钟 2 //! 3 use crate::{arch::CurrentTimeArch, time::TimeArch}; 4 5 pub struct SchedClock; 6 7 impl SchedClock { 8 #[inline] sched_clock_cpu(_cpu: usize) -> u649 pub fn sched_clock_cpu(_cpu: usize) -> u64 { 10 #[cfg(target_arch = "x86_64")] 11 { 12 if crate::arch::driver::tsc::TSCManager::cpu_khz() == 0 { 13 // TSC not calibrated yet 14 return 0; 15 } 16 return CurrentTimeArch::cycles2ns(CurrentTimeArch::get_cycles()) as u64; 17 } 18 19 #[cfg(target_arch = "riscv64")] 20 { 21 return CurrentTimeArch::cycles2ns(CurrentTimeArch::get_cycles()) as u64; 22 } 23 } 24 } 25 26 bitflags! { 27 pub struct ClockUpdataFlag: u8 { 28 /// 请求在下一次调用 __schedule() 时跳过时钟更新 29 const RQCF_REQ_SKIP = 0x01; 30 /// 表示跳过时钟更新正在生效,update_rq_clock() 的调用将被忽略。 31 const RQCF_ACT_SKIP = 0x02; 32 /// 调试标志,指示自上次固定 rq::lock 以来是否已调用过 33 const RQCF_UPDATE = 0x04; 34 } 35 } 36