From abf847a083888bbed4260ecacf849ea19f23e810 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 31 Jan 2017 17:47:16 -0500 Subject: Start of an experiment to remove the use of gs for cpu local variables. --- sysfile.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sysfile.c') diff --git a/sysfile.c b/sysfile.c index 98e8c43..fae6960 100644 --- a/sysfile.c +++ b/sysfile.c @@ -26,7 +26,7 @@ argfd(int n, int *pfd, struct file **pf) if(argint(n, &fd) < 0) return -1; - if(fd < 0 || fd >= NOFILE || (f=proc->ofile[fd]) == 0) + if(fd < 0 || fd >= NOFILE || (f=myproc()->ofile[fd]) == 0) return -1; if(pfd) *pfd = fd; @@ -43,8 +43,8 @@ fdalloc(struct file *f) int fd; for(fd = 0; fd < NOFILE; fd++){ - if(proc->ofile[fd] == 0){ - proc->ofile[fd] = f; + if(myproc()->ofile[fd] == 0){ + myproc()->ofile[fd] = f; return fd; } } @@ -97,7 +97,7 @@ sys_close(void) if(argfd(0, &fd, &f) < 0) return -1; - proc->ofile[fd] = 0; + myproc()->ofile[fd] = 0; fileclose(f); return 0; } @@ -386,9 +386,9 @@ sys_chdir(void) return -1; } iunlock(ip); - iput(proc->cwd); + iput(myproc()->cwd); end_op(); - proc->cwd = ip; + myproc()->cwd = ip; return 0; } @@ -432,7 +432,7 @@ sys_pipe(void) fd0 = -1; if((fd0 = fdalloc(rf)) < 0 || (fd1 = fdalloc(wf)) < 0){ if(fd0 >= 0) - proc->ofile[fd0] = 0; + myproc()->ofile[fd0] = 0; fileclose(rf); fileclose(wf); return -1; -- cgit v1.2.3 From fbb4c0944422f860484142010bb9f366f3e87bf8 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 31 Jan 2017 20:21:14 -0500 Subject: Read curproc from cpu structure, but be careful because after a schedule event myproc() points to a different thread. myproc(); sched(); myproc(); // this proc maybe different than the one before sched Thus, in a function that operates on one thread better to retrieve the current process once at the start of the function. --- sysfile.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sysfile.c') diff --git a/sysfile.c b/sysfile.c index fae6960..87e508b 100644 --- a/sysfile.c +++ b/sysfile.c @@ -41,10 +41,11 @@ static int fdalloc(struct file *f) { int fd; + struct proc *curproc = myproc(); for(fd = 0; fd < NOFILE; fd++){ - if(myproc()->ofile[fd] == 0){ - myproc()->ofile[fd] = f; + if(curproc->ofile[fd] == 0){ + curproc->ofile[fd] = f; return fd; } } @@ -373,7 +374,8 @@ sys_chdir(void) { char *path; struct inode *ip; - + struct proc *curproc = myproc(); + begin_op(); if(argstr(0, &path) < 0 || (ip = namei(path)) == 0){ end_op(); @@ -386,9 +388,9 @@ sys_chdir(void) return -1; } iunlock(ip); - iput(myproc()->cwd); + iput(curproc->cwd); end_op(); - myproc()->cwd = ip; + curproc->cwd = ip; return 0; } -- cgit v1.2.3