xref: /DragonOS/kernel/src/sched/syscall.rs (revision 86ee1395de7c614865236ee15071c3603b794e44)
1 use system_error::SystemError;
2 
3 use crate::arch::cpu::current_cpu_id;
4 use crate::exception::InterruptArch;
5 use crate::process::ProcessManager;
6 use crate::sched::CurrentIrqArch;
7 use crate::sched::Scheduler;
8 use crate::syscall::Syscall;
9 
10 use super::fair::CompletelyFairScheduler;
11 use super::{cpu_rq, schedule, SchedMode};
12 
13 impl Syscall {
14     pub fn do_sched_yield() -> Result<usize, SystemError> {
15         // 禁用中断
16         let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
17 
18         let pcb = ProcessManager::current_pcb();
19         let rq = cpu_rq(pcb.sched_info().on_cpu().unwrap_or(current_cpu_id()).data() as usize);
20         let (rq, guard) = rq.self_lock();
21 
22         // TODO: schedstat_inc(rq->yld_count);
23 
24         CompletelyFairScheduler::yield_task(rq);
25 
26         pcb.preempt_disable();
27 
28         drop(guard);
29         drop(irq_guard);
30 
31         pcb.preempt_enable(); // sched_preempt_enable_no_resched();
32 
33         schedule(SchedMode::SM_NONE);
34 
35         Ok(0)
36     }
37 }
38