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