xref: /DragonOS/kernel/src/arch/x86_64/cpu.rs (revision f6ba114bb0420e848ef7fc844c96c0d7a0552d93)
1 use core::arch::asm;
2 
3 /// @brief 获取当前cpu的apic id
4 #[inline]
5 pub fn current_cpu_id() -> u8 {
6     let cpuid_res: u32;
7     unsafe {
8         asm!(
9              "mov eax, 1",
10              "cpuid",
11              "mov r15, rbx",
12              lateout("r15") cpuid_res
13         );
14     }
15     return ((cpuid_res >> 24) & 0xff) as u8;
16 }
17 
18 /// @brief 通过pause指令,让cpu休息一会儿。降低空转功耗
19 pub fn cpu_relax() {
20     unsafe {
21         asm!("pause");
22     }
23 }
24