1 use core::arch::asm; 2 3 use x86::cpuid::{cpuid, CpuIdResult}; 4 5 /// @brief 获取当前cpu的apic id 6 #[inline] current_cpu_id() -> u327pub fn current_cpu_id() -> u32 { 8 let cpuid_res: CpuIdResult = cpuid!(0x1); 9 let cpu_id = (cpuid_res.ebx >> 24) & 0xff; 10 return cpu_id; 11 } 12 13 /// @brief 通过pause指令,让cpu休息一会儿。降低空转功耗 cpu_relax()14pub fn cpu_relax() { 15 unsafe { 16 asm!("pause"); 17 } 18 } 19 20 /// 重置cpu cpu_reset() -> !21pub fn cpu_reset() -> ! { 22 // 重启计算机 23 unsafe { x86::io::outb(0x64, 0xfe) }; 24 loop {} 25 } 26