From 9d34838b4f7c859b753a32124002d7d845140b0a Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Mon, 8 Jul 2019 11:11:00 -0400 Subject: [PATCH] holding p->lock all the way through state=RUNNABLE means we don't need EMBRYO --- kernel/proc.c | 17 ++++++----------- kernel/proc.h | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/kernel/proc.c b/kernel/proc.c index ade12d9..a947f7f 100644 --- a/kernel/proc.c +++ b/kernel/proc.c @@ -75,8 +75,7 @@ allocpid() { //PAGEBREAK: 32 // Look in the process table for an UNUSED proc. -// If found, change state to EMBRYO, initialize -// state required to run in the kernel, +// If found, initialize state required to run in the kernel, // and return with p->lock held. // Otherwise return 0. static struct proc* @@ -95,18 +94,17 @@ allocproc(void) return 0; found: - p->state = EMBRYO; p->pid = allocpid(); // Allocate a page for the kernel stack. if((p->kstack = kalloc()) == 0){ - p->state = UNUSED; return 0; } // Allocate a trapframe page. if((p->tf = (struct trapframe *)kalloc()) == 0){ - p->state = UNUSED; + kfree(p->kstack); + p->kstack = 0; return 0; } @@ -208,7 +206,7 @@ userinit(void) uvminit(p->pagetable, initcode, sizeof(initcode)); p->sz = PGSIZE; - // prepare for the very first kernel->user. + // prepare for the very first "return" from kernel to user. p->tf->epc = 0; p->tf->sp = PGSIZE; @@ -336,11 +334,10 @@ exit(void) } } - struct inode *cwd = p->cwd; - begin_op(); - iput(cwd); + iput(p->cwd); end_op(); + p->cwd = 0; acquire(&p->parent->lock); @@ -348,7 +345,6 @@ exit(void) reparent(p, p->parent); - p->cwd = 0; p->state = ZOMBIE; // Parent might be sleeping in wait(). @@ -627,7 +623,6 @@ procdump(void) { static char *states[] = { [UNUSED] "unused", - [EMBRYO] "embryo", [SLEEPING] "sleep ", [RUNNABLE] "runble", [RUNNING] "run ", diff --git a/kernel/proc.h b/kernel/proc.h index 0fa61ff..687fdd1 100644 --- a/kernel/proc.h +++ b/kernel/proc.h @@ -78,7 +78,7 @@ struct trapframe { /* 280 */ uint64 t6; }; -enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; +enum procstate { UNUSED, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; // Per-process state struct proc {