feat(sched): add sched_yield (#766)

* 实现sched_yield系统调用
This commit is contained in:
zwb0x00 2024-04-26 15:33:29 +08:00 committed by GitHub
parent 471d65cf15
commit 173c4567cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 0 deletions

View File

@ -5,6 +5,7 @@ pub mod fair;
pub mod idle;
pub mod pelt;
pub mod prio;
pub mod syscall;
use core::{
intrinsics::{likely, unlikely},

View File

@ -0,0 +1,37 @@
use system_error::SystemError;
use crate::arch::cpu::current_cpu_id;
use crate::exception::InterruptArch;
use crate::process::ProcessManager;
use crate::sched::CurrentIrqArch;
use crate::sched::Scheduler;
use crate::syscall::Syscall;
use super::fair::CompletelyFairScheduler;
use super::{cpu_rq, schedule, SchedMode};
impl Syscall {
pub fn do_sched_yield() -> Result<usize, SystemError> {
// 禁用中断
let irq_guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
let pcb = ProcessManager::current_pcb();
let rq = cpu_rq(pcb.sched_info().on_cpu().unwrap_or(current_cpu_id()).data() as usize);
let (rq, guard) = rq.self_lock();
// TODO: schedstat_inc(rq->yld_count);
CompletelyFairScheduler::yield_task(rq);
pcb.preempt_disable();
drop(guard);
drop(irq_guard);
pcb.preempt_enable(); // sched_preempt_enable_no_resched();
schedule(SchedMode::SM_NONE);
Ok(0)
}
}

View File

@ -1007,6 +1007,8 @@ impl Syscall {
Self::fchmodat(dirfd, pathname, mode)
}
SYS_SCHED_YIELD => Self::do_sched_yield(),
SYS_SCHED_GETAFFINITY => {
let pid = args[0] as i32;
let size = args[1];