提交 b3ad63d6 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

Make exit more scalable

上级 9fee0d5f
...@@ -16,8 +16,6 @@ int nextpid = 1; ...@@ -16,8 +16,6 @@ int nextpid = 1;
extern void forkret(void); extern void forkret(void);
extern void trapret(void); extern void trapret(void);
// static void wakeup1(struct ptable *pt, void *chan);
void void
pinit(void) pinit(void)
{ {
...@@ -31,7 +29,7 @@ pinit(void) ...@@ -31,7 +29,7 @@ pinit(void)
for (i = 0; i < NPROC; i++) { for (i = 0; i < NPROC; i++) {
initlock(&ptables[c].proc[i].lock, ptables[c].proc[i].name); initlock(&ptables[c].proc[i].lock, ptables[c].proc[i].name);
initlock(&ptables[c].proc[i].cv.lock, ptables[c].proc[i].name); initlock(&ptables[c].proc[i].cv.lock, ptables[c].proc[i].name); // XXX cv_init
} }
runqs[c].name[0] = (char) (c + '0'); runqs[c].name[0] = (char) (c + '0');
...@@ -99,7 +97,7 @@ addrun1(struct runq *rq, struct proc *p) ...@@ -99,7 +97,7 @@ addrun1(struct runq *rq, struct proc *p)
return; return;
} }
} }
p->state = RUNNABLE; // race? p->state = RUNNABLE; // XXX race?
SLIST_INSERT_HEAD(&rq->runq, p, run_next); SLIST_INSERT_HEAD(&rq->runq, p, run_next);
} }
...@@ -229,9 +227,8 @@ fork(void) ...@@ -229,9 +227,8 @@ fork(void)
void void
exit(void) exit(void)
{ {
struct proc *p; struct proc *p, *np;
int fd; int fd;
int c;
int wakeupinit; int wakeupinit;
if(proc == initproc) if(proc == initproc)
...@@ -252,16 +249,14 @@ exit(void) ...@@ -252,16 +249,14 @@ exit(void)
// Pass abandoned children to init. // Pass abandoned children to init.
wakeupinit = 0; wakeupinit = 0;
for (c = 0; c < NCPU; c++) { SLIST_FOREACH_SAFE(p, &proc->childq, child_next, np) {
acquire(&ptables[c].lock); // XXX Unscalable acquire(&p->lock);
for(p = ptables[c].proc; p < &ptables[c].proc[NPROC]; p++){ p->parent = initproc;
if(p->parent == proc){ if(p->state == ZOMBIE)
p->parent = initproc;
if(p->state == ZOMBIE)
wakeupinit = 1; wakeupinit = 1;
} SLIST_REMOVE(&proc->childq, p, proc, child_next);
} SLIST_INSERT_HEAD(&initproc->childq, p, child_next); // XXX lock?
release(&ptables[c].lock); release(&p->lock);
} }
// Parent might be sleeping in wait(). // Parent might be sleeping in wait().
...@@ -291,7 +286,7 @@ wait(void) ...@@ -291,7 +286,7 @@ wait(void)
cprintf("wait %d\n", proc->pid); cprintf("wait %d\n", proc->pid);
for(;;){ for(;;){
// Scan through table looking for zombie children. // Scan children for ZOMBIEs
havekids = 0; havekids = 0;
acquire(&proc->lock); acquire(&proc->lock);
SLIST_FOREACH_SAFE(p, &proc->childq, child_next, np) { SLIST_FOREACH_SAFE(p, &proc->childq, child_next, np) {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论