Skip to content

Commit

Permalink
feat(sched): PELT
Browse files Browse the repository at this point in the history
  • Loading branch information
zwb0x00 committed May 12, 2024
1 parent 0102d69 commit 4ec11ff
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 24 deletions.
1 change: 1 addition & 0 deletions kernel/src/process/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ fn do_waitpid(
unsafe { ProcessManager::release(pid) };
return Some(Ok(pid.into()));
}
_ => {}
};

return None;
Expand Down
35 changes: 32 additions & 3 deletions kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ use crate::{
VirtAddr,
},
net::socket::SocketInode,
sched::completion::Completion,
sched::{
cpu_rq, fair::FairSchedEntity, prio::MAX_PRIO, DequeueFlag, EnqueueFlag, OnRq, SchedMode,
WakeupFlags, __schedule,
completion::Completion,
cpu_rq,
fair::{CompletelyFairScheduler, FairSchedEntity},
prio::MAX_PRIO,
DequeueFlag, EnqueueFlag, OnRq, SchedMode, SchedPolicy, WakeupFlags, __schedule,
},
smp::{
core::smp_get_processor_id,
Expand Down Expand Up @@ -467,6 +469,20 @@ impl ProcessManager {
.take()
.expect("next_pcb is None");

let guard = prev_pcb.sched_info.inner_lock_read_irqsave();
if unlikely(guard.state() == ProcessState::Dead) {
match prev_pcb.sched_info().policy() {
SchedPolicy::RT => todo!(),
SchedPolicy::FIFO => todo!(),
SchedPolicy::CFS => CompletelyFairScheduler::task_dead(prev_pcb.clone()),
SchedPolicy::IDLE => todo!(),
}

// TODO: put_task_stack
// TODO: put_task_struct_rcu_user
}
drop(guard);

// 由于进程切换前使用了SpinLockGuard::leak(),所以这里需要手动释放锁
fence(Ordering::SeqCst);

Expand Down Expand Up @@ -530,6 +546,7 @@ pub enum ProcessState {
Stopped,
/// 进程已经退出,usize表示进程的退出码
Exited(usize),
Dead,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -977,6 +994,11 @@ impl ProcessControlBlock {
pub fn alarm_timer_irqsave(&self) -> SpinLockGuard<Option<AlarmTimer>> {
return self.alarm_timer.lock_irqsave();
}

#[inline]
pub fn task_util(&self) -> usize {
self.sched_info().sched_entity.avg.util_avg
}
}

impl Drop for ProcessControlBlock {
Expand Down Expand Up @@ -1481,6 +1503,13 @@ impl ProcessSignalInfo {
self.tty = Some(tty);
}

#[allow(dead_code)]
pub fn set_task_cpu(&self, _new_cpu: x86::cpuid::CpuId) {
// TODO

// TODO(pelt): call migrate_task_rq
}

/// 从 pcb 的 siginfo中取出下一个要处理的信号,先处理线程信号,再处理进程信号
///
/// ## 参数
Expand Down
Loading

0 comments on commit 4ec11ff

Please sign in to comment.