Change addrun to set p->state = RUNNABLE

上级 87b199ef
......@@ -21,7 +21,6 @@ wakeup(struct proc *p)
LIST_REMOVE(p, cv_waiters);
p->oncv = 0;
addrun(p);
p->state = RUNNABLE;
}
void
......
......@@ -315,7 +315,6 @@ initgc(void)
gcp->cpuid = c;
gcp->cpu_pin = 1;
acquire(&gcp->lock);
gcp->state = RUNNABLE;
addrun(gcp);
release(&gcp->lock);
}
......
......@@ -247,7 +247,6 @@ void sched(void);
void userinit(void);
int wait(void);
void yield(void);
void migrate(struct proc *);
struct proc* threadalloc(void (*fn)(void*), void *arg);
// prof.c
......
......@@ -106,7 +106,6 @@ start_timer(struct timer_thread *t, void (*func)(void),
acquire(&p->lock);
safestrcpy(p->name, name, sizeof(p->name));
p->state = RUNNABLE;
addrun(p);
release(&p->lock);
}
......@@ -262,7 +261,6 @@ initnet(void)
acquire(&t->lock);
safestrcpy(t->name, "initnet", sizeof(t->name));
t->state = RUNNABLE;
addrun(t);
release(&t->lock);
}
......
......@@ -61,39 +61,38 @@ yield(void)
release(&myproc()->lock);
}
void
static int
migrate(struct proc *p)
{
// p should not be running, or be on a runqueue, or be myproc()
int c;
if (p == myproc())
panic("migrate: myproc");
for (c = 0; c < NCPU; c++) {
if (c == mycpu()->id)
continue;
if (idle[c]) { // OK if there is a race
acquire(&p->lock);
if (p->state != RUNNABLE || p->cpu_pin) {
release(&p->lock);
continue;
}
if (sched_debug)
cprintf("cpu%d: migrate %d to %d\n", mycpu()->id, p->pid, c);
if (p->state == RUNNING)
panic("migrate: pid %u name %s is running",
p->pid, p->name);
if (p->cpu_pin)
panic("migrate: pid %u name %s is pinned",
p->pid, p->name);
delrun(p);
p->curcycles = 0;
p->cpuid = c;
addrun(p);
idle[c] = 0;
if (p == myproc()) {
myproc()->state = RUNNABLE;
sched();
}
release(&p->lock);
return;
return 0;
}
}
return -1;
}
// A fork child's very first scheduling by scheduler()
......@@ -268,7 +267,6 @@ inituser(void)
p->cwd = NULL; // forkret will fix in the process's context
acquire(&p->lock);
addrun(p);
p->state = RUNNABLE;
release(&p->lock);
}
......@@ -327,7 +325,7 @@ scheduler(void)
if (p) {
acquire(&p->lock);
if (p->state != RUNNABLE) {
release(&p->lock);
release(&p->lock);
} else {
if (idle[mycpu()->id])
idle[mycpu()->id] = 0;
......@@ -593,12 +591,12 @@ fork(int flags)
SLIST_INSERT_HEAD(&myproc()->childq, np, child_next);
release(&myproc()->lock);
acquire(&np->lock);
addrun(np);
np->state = RUNNABLE;
release(&np->lock);
migrate(np);
if (migrate(np)) {
acquire(&np->lock);
np->cpuid = mycpu()->id;
addrun(np);
release(&np->lock);
}
// cprintf("%d: fork done (pid %d)\n", myproc()->pid, pid);
return pid;
......
......@@ -29,6 +29,8 @@ addrun(struct proc *p)
// Always called with p->lock held
struct runq *q;
p->state = RUNNABLE;
q = &runq[p->cpuid];
acquire(&q->lock);
STAILQ_INSERT_HEAD(&q->q, p, runqlink);
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论