commit 1c0d873592bb6d44ab2d9e8042fdd4feabbc5e47
parent 2c00491ad7eaab5b0b2eecb0c5f84ccc7be71688
Author: Brian Swetland <swetland@frotz.net>
Date: Sat, 28 Dec 2013 06:19:17 -0800
scheduler: halt and wait for irq if nothing was scheduleable
h/t tankenmate@hackernews who did this a bit more verbosely
https://news.ycombinator.com/item?id=6974384
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/proc.c b/kernel/proc.c
@@ -257,12 +257,17 @@ wait(void)
void
scheduler(void)
{
- struct proc *p;
+ struct proc *p = 0;
for(;;){
// Enable interrupts on this processor.
sti();
+ // no runnable processes? (did we hit the end of the table last time?)
+ // if so, wait for irq before trying again.
+ if (p == &ptable.proc[NPROC])
+ hlt();
+
// Loop over process table looking for process to run.
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){