try to use cp only for curproc[cpu()]

This commit is contained in:
rsc 2007-08-09 17:32:40 +00:00
parent 22330658ff
commit 9583b476bf
4 changed files with 37 additions and 36 deletions

18
proc.c
View file

@ -204,9 +204,9 @@ scheduler(void)
void void
sched(void) sched(void)
{ {
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(p->state == RUNNING) if(cp->state == RUNNING)
panic("sched running"); panic("sched running");
if(!holding(&proc_table_lock)) if(!holding(&proc_table_lock))
panic("sched proc_table_lock"); panic("sched proc_table_lock");
@ -221,10 +221,10 @@ sched(void)
void void
yield(void) yield(void)
{ {
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
acquire(&proc_table_lock); acquire(&proc_table_lock);
p->state = RUNNABLE; cp->state = RUNNABLE;
sched(); sched();
release(&proc_table_lock); release(&proc_table_lock);
} }
@ -246,9 +246,9 @@ forkret(void)
void void
sleep(void *chan, struct spinlock *lk) sleep(void *chan, struct spinlock *lk)
{ {
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(p == 0) if(cp == 0)
panic("sleep"); panic("sleep");
if(lk == 0) if(lk == 0)
@ -266,12 +266,12 @@ sleep(void *chan, struct spinlock *lk)
} }
// Go to sleep. // Go to sleep.
p->chan = chan; cp->chan = chan;
p->state = SLEEPING; cp->state = SLEEPING;
sched(); sched();
// Tidy up. // Tidy up.
p->chan = 0; cp->chan = 0;
// Reacquire original lock. // Reacquire original lock.
if(lk != &proc_table_lock){ if(lk != &proc_table_lock){

View file

@ -37,15 +37,15 @@ fetchint(struct proc *p, uint addr, int *ip)
int int
fetchstr(struct proc *p, uint addr, char **pp) fetchstr(struct proc *p, uint addr, char **pp)
{ {
char *cp, *ep; char *s, *ep;
if(addr >= p->sz) if(addr >= p->sz)
return -1; return -1;
*pp = p->mem + addr; *pp = p->mem + addr;
ep = p->mem + p->sz; ep = p->mem + p->sz;
for(cp = *pp; cp < ep; cp++) for(s = *pp; s < ep; s++)
if(*cp == 0) if(*s == 0)
return cp - *pp; return s - *pp;
return -1; return -1;
} }
@ -53,9 +53,9 @@ fetchstr(struct proc *p, uint addr, char **pp)
int int
argint(int argno, int *ip) argint(int argno, int *ip)
{ {
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
return fetchint(p, p->tf->esp + 4 + 4*argno, ip); return fetchint(cp, cp->tf->esp + 4 + 4*argno, ip);
} }
// Fetch the nth word-sized system call argument as a pointer // Fetch the nth word-sized system call argument as a pointer
@ -65,13 +65,13 @@ int
argptr(int argno, char **pp, int size) argptr(int argno, char **pp, int size)
{ {
int i; int i;
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(argint(argno, &i) < 0) if(argint(argno, &i) < 0)
return -1; return -1;
if((uint)i >= p->sz || (uint)i+size >= p->sz) if((uint)i >= cp->sz || (uint)i+size >= cp->sz)
return -1; return -1;
*pp = p->mem + i; *pp = cp->mem + i;
return 0; return 0;
} }

View file

@ -22,11 +22,11 @@ argfd(int argno, int *pfd, struct file **pf)
{ {
int fd; int fd;
struct file *f; struct file *f;
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(argint(argno, &fd) < 0) if(argint(argno, &fd) < 0)
return -1; return -1;
if(fd < 0 || fd >= NOFILE || (f=p->ofile[fd]) == 0) if(fd < 0 || fd >= NOFILE || (f=cp->ofile[fd]) == 0)
return -1; return -1;
if(pfd) if(pfd)
*pfd = fd; *pfd = fd;
@ -41,10 +41,11 @@ static int
fdalloc(struct file *f) fdalloc(struct file *f)
{ {
int fd; int fd;
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
for(fd = 0; fd < NOFILE; fd++){ for(fd = 0; fd < NOFILE; fd++){
if(p->ofile[fd] == 0){ if(cp->ofile[fd] == 0){
p->ofile[fd] = f; cp->ofile[fd] = f;
return fd; return fd;
} }
} }
@ -57,7 +58,7 @@ sys_pipe(void)
int *fd; int *fd;
struct file *rf = 0, *wf = 0; struct file *rf = 0, *wf = 0;
int fd0, fd1; int fd0, fd1;
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0) if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)
return -1; return -1;
@ -66,7 +67,7 @@ sys_pipe(void)
fd0 = -1; fd0 = -1;
if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){ if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){
if(fd0 >= 0) if(fd0 >= 0)
p->ofile[fd0] = 0; cp->ofile[fd0] = 0;
fileclose(rf); fileclose(rf);
fileclose(wf); fileclose(wf);
return -1; return -1;
@ -241,7 +242,7 @@ sys_mkdir(void)
int int
sys_chdir(void) sys_chdir(void)
{ {
struct proc *p = curproc[cpu()]; struct proc *cp = curproc[cpu()];
struct inode *ip; struct inode *ip;
char *path; char *path;
@ -261,9 +262,9 @@ sys_chdir(void)
return -1; return -1;
} }
idecref(p->cwd); idecref(cp->cwd);
p->cwd = ip; cp->cwd = ip;
iunlock(p->cwd); iunlock(cp->cwd);
return 0; return 0;
} }

View file

@ -46,17 +46,17 @@ free(void *ap)
static Header* static Header*
morecore(uint nu) morecore(uint nu)
{ {
char *cp; char *p;
Header *up; Header *hp;
if(nu < PAGE) if(nu < PAGE)
nu = PAGE; nu = PAGE;
cp = sbrk(nu * sizeof(Header)); p = sbrk(nu * sizeof(Header));
if(cp == (char*) -1) if(p == (char*) -1)
return 0; return 0;
up = (Header*) cp; hp = (Header*)p;
up->s.size = nu; hp->s.size = nu;
free((void*)(up + 1)); free((void*)(hp + 1));
return freep; return freep;
} }