The run queues hold only runnable procs

上级 af1ff963
...@@ -39,6 +39,7 @@ idleloop(void) ...@@ -39,6 +39,7 @@ idleloop(void)
if (p) { if (p) {
acquire(&p->lock); acquire(&p->lock);
if (p->state != RUNNABLE) { if (p->state != RUNNABLE) {
panic("Huh?");
release(&p->lock); release(&p->lock);
} else { } else {
if (idle[mycpu()->id]) if (idle[mycpu()->id])
...@@ -68,8 +69,8 @@ idleloop(void) ...@@ -68,8 +69,8 @@ idleloop(void)
// Process is done running for now. // Process is done running for now.
// It should have changed its p->state before coming back. // It should have changed its p->state before coming back.
mycpu()->proc = idlep; mycpu()->proc = idlep;
if (p->state != RUNNABLE) if (p->state == RUNNABLE)
delrun(p); addrun(p);
release(&p->lock); release(&p->lock);
} }
} else { } else {
......
...@@ -74,6 +74,7 @@ steal(void) ...@@ -74,6 +74,7 @@ steal(void)
if (p->state == RUNNABLE && !p->cpu_pin && if (p->state == RUNNABLE && !p->cpu_pin &&
p->curcycles != 0 && p->curcycles > VICTIMAGE) p->curcycles != 0 && p->curcycles > VICTIMAGE)
{ {
STAILQ_REMOVE(&q->q, p, proc, runqlink);
steal = p; steal = p;
break; break;
} }
...@@ -85,7 +86,7 @@ steal(void) ...@@ -85,7 +86,7 @@ steal(void)
if (steal->state == RUNNABLE && !steal->cpu_pin && if (steal->state == RUNNABLE && !steal->cpu_pin &&
steal->curcycles != 0 && steal->curcycles > VICTIMAGE) steal->curcycles != 0 && steal->curcycles > VICTIMAGE)
{ {
delrun(steal); //delrun(steal);
steal->curcycles = 0; steal->curcycles = 0;
steal->cpuid = mycpu()->id; steal->cpuid = mycpu()->id;
addrun(steal); addrun(steal);
...@@ -93,6 +94,8 @@ steal(void) ...@@ -93,6 +94,8 @@ steal(void)
r = 1; r = 1;
break; break;
} }
if (steal->state == RUNNABLE)
addrun(steal);
release(&steal->lock); release(&steal->lock);
} }
} }
...@@ -112,10 +115,8 @@ schednext(void) ...@@ -112,10 +115,8 @@ schednext(void)
q = &runq[cpunum()]; q = &runq[cpunum()];
acquire(&q->lock); acquire(&q->lock);
p = STAILQ_LAST(&q->q, proc, runqlink); p = STAILQ_LAST(&q->q, proc, runqlink);
if (p) { if (p)
STAILQ_REMOVE(&q->q, p, proc, runqlink); STAILQ_REMOVE(&q->q, p, proc, runqlink);
STAILQ_INSERT_HEAD(&q->q, p, runqlink);
}
release(&q->lock); release(&q->lock);
popcli(); popcli();
return p; return p;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论