Skip to content

Use wfi to sleep a cpu if no process is found while cycling pool #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/kernel/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ pub fn scheduler() -> ! {
// Avoid deadlock by ensuring thet devices can interrupt.
intr_on();

let mut found : bool = false;
for p in PROCS.pool.iter() {
let mut inner = p.inner.lock();
if inner.state == ProcState::RUNNABLE {
Expand All @@ -682,6 +683,16 @@ pub fn scheduler() -> ! {
// Process is done running for now.
// It should have changed its p->state before coming back.
c.proc.take();
found = true;
}
}
if found == false {
intr_on();
// If pool cycle ran without a process running...
// ...park cpu until interrupt
// This prevents cpu from red-lining for no reason
unsafe {
asm!("wfi");
}
}
}
Expand Down