xref: /DragonOS/kernel/src/arch/x86_64/process/idle.rs (revision 2eab6dd743e94a86a685f1f3c01e599adf86610a)
15b59005fSLoGin use core::hint::spin_loop;
25b59005fSLoGin 
3*2eab6dd7S曾俊 use log::error;
4*2eab6dd7S曾俊 
5f0c87a89SGnoCiYeH use crate::{
6f0c87a89SGnoCiYeH     arch::CurrentIrqArch,
7f0c87a89SGnoCiYeH     exception::InterruptArch,
8f0c87a89SGnoCiYeH     process::{ProcessFlags, ProcessManager},
9f0c87a89SGnoCiYeH     sched::{SchedMode, __schedule},
10f0c87a89SGnoCiYeH };
115b59005fSLoGin 
125b59005fSLoGin impl ProcessManager {
135b59005fSLoGin     /// 每个核的idle进程
arch_idle_func() -> !145b59005fSLoGin     pub fn arch_idle_func() -> ! {
155b59005fSLoGin         loop {
16f0c87a89SGnoCiYeH             let pcb = ProcessManager::current_pcb();
17f0c87a89SGnoCiYeH             if pcb.flags().contains(ProcessFlags::NEED_SCHEDULE) {
18f0c87a89SGnoCiYeH                 __schedule(SchedMode::SM_NONE);
19f0c87a89SGnoCiYeH             }
205b59005fSLoGin             if CurrentIrqArch::is_irq_enabled() {
215b59005fSLoGin                 unsafe {
225b59005fSLoGin                     x86::halt();
235b59005fSLoGin                 }
245b59005fSLoGin             } else {
25*2eab6dd7S曾俊                 error!("Idle process should not be scheduled with IRQs disabled.");
265b59005fSLoGin                 spin_loop();
275b59005fSLoGin             }
285b59005fSLoGin         }
295b59005fSLoGin     }
305b59005fSLoGin }
31