xref: /DragonOS/kernel/src/arch/x86_64/cpu.rs (revision 45b8371173b070028457f7ee64be33f68b4f9ada)
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