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