diff options
| -rw-r--r-- | console.c | 2 | ||||
| -rw-r--r-- | fs.c | 11 | ||||
| -rw-r--r-- | kalloc.c | 14 | ||||
| -rw-r--r-- | pipe.c | 4 | ||||
| -rw-r--r-- | proc.c | 14 | ||||
| -rw-r--r-- | proc.h | 10 | ||||
| -rw-r--r-- | syscall.c | 5 | ||||
| -rw-r--r-- | sysfile.c | 7 | ||||
| -rw-r--r-- | sysproc.c | 5 | ||||
| -rw-r--r-- | trap.c | 1 | 
10 files changed, 32 insertions, 41 deletions
@@ -397,7 +397,7 @@ console_read(int minor, char *dst, int n)    acquire(&kbd_lock);    while(n > 0){      while(kbd_r == kbd_w){ -      if(curproc[cpu()]->killed){ +      if(cp->killed){          release(&kbd_lock);          return -1;        } @@ -557,7 +557,6 @@ namei(char *path, int mode, uint *ret_off,        char **ret_last, struct inode **ret_ip)  {    struct inode *dp; -  struct proc *cp = curproc[cpu()];    char *name;    int namelen;    uint off, dev, inum; @@ -648,15 +647,15 @@ wdir(struct inode *dp, char *name, uint ino)      panic("wdir write");  } -// Create the path cp and return its locked inode structure. +// Create the path and return its locked inode structure.  // If cp already exists, return 0.  struct inode* -mknod(char *cp, short type, short major, short minor) +mknod(char *path, short type, short major, short minor)  {    struct inode *ip, *dp;    char *last; -  if((dp = namei(cp, NAMEI_CREATE, 0, &last, 0)) == 0) +  if((dp = namei(path, NAMEI_CREATE, 0, &last, 0)) == 0)      return 0;    ip = mknod1(dp, last, type, major, minor); @@ -691,13 +690,13 @@ mknod1(struct inode *dp, char *name, short type, short major, short minor)  // Unlink the inode named cp.  int -unlink(char *cp) +unlink(char *path)  {    struct inode *ip, *dp;    struct dirent de;    uint off, inum, dev; -  dp = namei(cp, NAMEI_DELETE, &off, 0, 0); +  dp = namei(path, NAMEI_DELETE, &off, 0, 0);    if(dp == 0)      return -1; @@ -40,24 +40,22 @@ kinit(void)    kfree(start, mem * PAGE);  } -// Free the len bytes of memory pointed at by cp, +// Free the len bytes of memory pointed at by v,  // which normally should have been returned by a -// call to kalloc(cp).  (The exception is when +// call to kalloc(len).  (The exception is when  // initializing the allocator; see kinit above.)  void -kfree(char *cp, int len) +kfree(char *v, int len)  {    struct run **rr; -  struct run *p = (struct run*) cp; -  struct run *pend = (struct run*) (cp + len); -  int i; +  struct run *p = (struct run*)v; +  struct run *pend = (struct run*)(v + len);    if(len % PAGE)      panic("kfree");    // Fill with junk to catch dangling refs. -  for(i = 0; i < len; i++) -    cp[i] = 1; +  memset(v, 1, len);    acquire(&kalloc_lock); @@ -87,7 +87,7 @@ pipe_write(struct pipe *p, char *addr, int n)    for(i = 0; i < n; i++){      while(((p->writep + 1) % PIPESIZE) == p->readp){ -      if(p->readopen == 0 || curproc[cpu()]->killed){ +      if(p->readopen == 0 || cp->killed){          release(&p->lock);          return -1;        } @@ -111,7 +111,7 @@ pipe_read(struct pipe *p, char *addr, int n)    acquire(&p->lock);    while(p->readp == p->writep){ -    if(p->writeopen == 0 || curproc[cpu()]->killed){ +    if(p->writeopen == 0 || cp->killed){        release(&p->lock);        return 0;      } @@ -59,7 +59,6 @@ setupsegs(struct proc *p)  int  growproc(int n)  { -  struct proc *cp = curproc[cpu()];    char *newmem, *oldmem;    newmem = kalloc(cp->sz + n); @@ -183,14 +182,14 @@ scheduler(void)        // before jumping back to us.        setupsegs(p); -      curproc[cpu()] = p; +      cp = p;        p->state = RUNNING;        if(setjmp(&cpus[cpu()].jmpbuf) == 0)          longjmp(&p->jmpbuf);        // Process is done running for now.        // It should have changed its p->state before coming back. -      curproc[cpu()] = 0; +      cp = 0;        setupsegs(0);      } @@ -204,7 +203,6 @@ scheduler(void)  void  sched(void)  { -  struct proc *cp = curproc[cpu()];    if(cp->state == RUNNING)      panic("sched running"); @@ -213,7 +211,7 @@ sched(void)    if(cpus[cpu()].nlock != 1)      panic("sched locks"); -  if(setjmp(&p->jmpbuf) == 0) +  if(setjmp(&cp->jmpbuf) == 0)      longjmp(&cpus[cpu()].jmpbuf);  } @@ -221,7 +219,6 @@ sched(void)  void  yield(void)  { -  struct proc *cp = curproc[cpu()];    acquire(&proc_table_lock);    cp->state = RUNNABLE; @@ -238,7 +235,7 @@ forkret(void)    release(&proc_table_lock);    // Jump into assembly, never to return. -  forkret1(curproc[cpu()]->tf); +  forkret1(cp->tf);  }  // Atomically release lock and sleep on chan. @@ -246,7 +243,6 @@ forkret(void)  void  sleep(void *chan, struct spinlock *lk)  { -  struct proc *cp = curproc[cpu()];    if(cp == 0)      panic("sleep"); @@ -332,7 +328,6 @@ void  proc_exit(void)  {    struct proc *p; -  struct proc *cp = curproc[cpu()];    int fd;    if(cp->pid == 1) @@ -376,7 +371,6 @@ int  proc_wait(void)  {    struct proc *p; -  struct proc *cp = curproc[cpu()];    int i, havekids, pid;    acquire(&proc_table_lock); @@ -50,7 +50,17 @@ struct proc {  //   expandable heap  extern struct proc proc[]; + +// If xv6 was only for uniprocessors, this could be +//   struct proc *cp; +// Instead we have an array curproc, one per +// processor, and #define cp to the right element +// in the array.  In general such preprocessor  +// subterfuge is to be avoided, but cp is used  +// so often that having the shorthand is worth the ugliness.  extern struct proc *curproc[NCPU];  // Current (running) process per CPU +#define cp (curproc[cpu()])  // Current process on this CPU +  #define MPSTACK 512 @@ -53,7 +53,6 @@ fetchstr(struct proc *p, uint addr, char **pp)  int  argint(int argno, int *ip)  { -  struct proc *cp = curproc[cpu()];    return fetchint(cp, cp->tf->esp + 4 + 4*argno, ip);  } @@ -65,7 +64,6 @@ int  argptr(int argno, char **pp, int size)  {    int i; -  struct proc *cp = curproc[cpu()];    if(argint(argno, &i) < 0)      return -1; @@ -85,7 +83,7 @@ argstr(int argno, char **pp)    int addr;    if(argint(argno, &addr) < 0)      return -1; -  return fetchstr(curproc[cpu()], addr, pp); +  return fetchstr(cp, addr, pp);  }  extern int sys_chdir(void); @@ -133,7 +131,6 @@ static int (*syscalls[])(void) = {  void  syscall(void)  { -  struct proc *cp = curproc[cpu()];    int num = cp->tf->eax;    if(num >= 0 && num < NELEM(syscalls) && syscalls[num]) @@ -22,7 +22,6 @@ argfd(int argno, int *pfd, struct file **pf)  {    int fd;    struct file *f; -  struct proc *cp = curproc[cpu()];    if(argint(argno, &fd) < 0)      return -1; @@ -41,7 +40,6 @@ static int  fdalloc(struct file *f)  {    int fd; -  struct proc *cp = curproc[cpu()];    for(fd = 0; fd < NOFILE; fd++){      if(cp->ofile[fd] == 0){ @@ -58,7 +56,6 @@ sys_pipe(void)    int *fd;    struct file *rf = 0, *wf = 0;    int fd0, fd1; -  struct proc *cp = curproc[cpu()];    if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)      return -1; @@ -109,7 +106,7 @@ sys_close(void)    if(argfd(0, &fd, &f) < 0)      return -1; -  curproc[cpu()]->ofile[fd] = 0; +  cp->ofile[fd] = 0;    fileclose(f);    return 0;  } @@ -242,7 +239,6 @@ sys_mkdir(void)  int  sys_chdir(void)  { -  struct proc *cp = curproc[cpu()];    struct inode *ip;    char *path; @@ -316,7 +312,6 @@ sys_link(void)  int  sys_exec(void)  { -  struct proc *cp = curproc[cpu()];    uint sz=0, ap, sp, p1, p2;    int i, nargs, argbytes, len;    struct inode *ip; @@ -20,7 +20,7 @@ sys_fork(void)  {    struct proc *np; -  if((np = copyproc(curproc[cpu()])) == 0) +  if((np = copyproc(cp)) == 0)      return -1;    np->state = RUNNABLE;    return np->pid; @@ -52,7 +52,7 @@ sys_kill(void)  int  sys_getpid(void)  { -  return curproc[cpu()]->pid; +  return cp->pid;  }  int @@ -60,7 +60,6 @@ sys_sbrk(void)  {    int addr;    int n; -  struct proc *cp = curproc[cpu()];    if(argint(0, &n) < 0)      return -1; @@ -31,7 +31,6 @@ void  trap(struct trapframe *tf)  {    int v = tf->trapno; -  struct proc *cp = curproc[cpu()];    if(v == T_SYSCALL){      if(cp->killed)  | 
