Skip to content

Commit

Permalink
Start of an experiment to remove the use of gs for cpu local variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaashoek committed Jan 31, 2017
1 parent 59cdd6c commit abf847a
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 123 deletions.
4 changes: 2 additions & 2 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ panic(char *s)

cli();
cons.locking = 0;
cprintf("cpu with apicid %d: panic: ", cpu->apicid);
cprintf("cpu %d: panic: ", cpuid());
cprintf(s);
cprintf("\n");
getcallerpcs(&s, pcs);
Expand Down Expand Up @@ -242,7 +242,7 @@ consoleread(struct inode *ip, char *dst, int n)
acquire(&cons.lock);
while(n > 0){
while(input.r == input.w){
if(proc->killed){
if(myproc()->killed){
release(&cons.lock);
ilock(ip);
return -1;
Expand Down
4 changes: 3 additions & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void kbdintr(void);

// lapic.c
void cmostime(struct rtcdate *r);
int cpunum(void);
int lapiccpunum(void);
extern volatile uint* lapic;
void lapiceoi(void);
void lapicinit(void);
Expand Down Expand Up @@ -103,6 +103,7 @@ int pipewrite(struct pipe*, char*, int);

//PAGEBREAK: 16
// proc.c
int cpuid(void);
void exit(void);
int fork(void);
int growproc(int);
Expand All @@ -111,6 +112,7 @@ void pinit(void);
void procdump(void);
void scheduler(void) __attribute__((noreturn));
void sched(void);
void setproc(struct proc*);
void sleep(void*, struct spinlock*);
void userinit(void);
int wait(void);
Expand Down
15 changes: 8 additions & 7 deletions exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ exec(char *path, char **argv)

if((ip = namei(path)) == 0){
end_op();
cprintf("exec: fail\n");
return -1;
}
ilock(ip);
Expand Down Expand Up @@ -89,15 +90,15 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++)
if(*s == '/')
last = s+1;
safestrcpy(proc->name, last, sizeof(proc->name));
safestrcpy(myproc()->name, last, sizeof(myproc()->name));

// Commit to the user image.
oldpgdir = proc->pgdir;
proc->pgdir = pgdir;
proc->sz = sz;
proc->tf->eip = elf.entry; // main
proc->tf->esp = sp;
switchuvm(proc);
oldpgdir = myproc()->pgdir;
myproc()->pgdir = pgdir;
myproc()->sz = sz;
myproc()->tf->eip = elf.entry; // main
myproc()->tf->esp = sp;
switchuvm(myproc());
freevm(oldpgdir);
return 0;

Expand Down
4 changes: 2 additions & 2 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ iinit(int dev)
for(i = 0; i < NINODE; i++) {
initsleeplock(&icache.inode[i].lock, "inode");
}

readsb(dev, &sb);
cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d\
inodestart %d bmap start %d\n", sb.size, sb.nblocks,
Expand Down Expand Up @@ -615,7 +615,7 @@ namex(char *path, int nameiparent, char *name)
if(*path == '/')
ip = iget(ROOTDEV, ROOTINO);
else
ip = idup(proc->cwd);
ip = idup(myproc()->cwd);

while((path = skipelem(path, name)) != 0){
ilock(ip);
Expand Down
3 changes: 2 additions & 1 deletion ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ ideintr(void)

// First queued buffer is the active request.
acquire(&idelock);

if((b = idequeue) == 0){
release(&idelock);
// cprintf("spurious IDE interrupt\n");
return;
}
idequeue = b->qnext;
Expand Down Expand Up @@ -164,5 +164,6 @@ iderw(struct buf *b)
sleep(b, &idelock);
}


release(&idelock);
}
6 changes: 3 additions & 3 deletions lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ lapicinit(void)
}

int
cpunum(void)
lapiccpunum(void)
{
int apicid, i;

// Cannot call cpu when interrupts are enabled:
// Cannot call cpunum when interrupts are enabled:
// result not guaranteed to last long enough to be used!
// Would prefer to panic but even printing is chancy here:
// almost everything, including cprintf and panic, calls cpu,
// often indirectly through acquire and release.
if(readeflags()&FL_IF){
static int n;
if(n++ == 0)
cprintf("cpu called from %x with interrupts enabled\n",
cprintf("cpunum called from %x with interrupts enabled\n",
__builtin_return_address(0));
}

Expand Down
9 changes: 4 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ main(void)
mpinit(); // detect other processors
lapicinit(); // interrupt controller
seginit(); // segment descriptors
cprintf("\ncpu%d: starting xv6\n\n", cpunum());
picinit(); // another interrupt controller
ioapicinit(); // another interrupt controller
consoleinit(); // console hardware
Expand All @@ -31,7 +30,7 @@ main(void)
tvinit(); // trap vectors
binit(); // buffer cache
fileinit(); // file table
ideinit(); // disk
ideinit(); // disk
if(!ismp)
timerinit(); // uniprocessor timer
startothers(); // start other processors
Expand All @@ -54,9 +53,9 @@ mpenter(void)
static void
mpmain(void)
{
cprintf("cpu%d: starting\n", cpunum());
cprintf("cpu%d: starting %d\n", cpuid(), lapiccpunum());
idtinit(); // load idt register
xchg(&cpu->started, 1); // tell startothers() we're up
xchg(&(mycpu()->started), 1); // tell startothers() we're up
scheduler(); // start running processes
}

Expand All @@ -78,7 +77,7 @@ startothers(void)
memmove(code, _binary_entryother_start, (uint)_binary_entryother_size);

for(c = cpus; c < cpus+ncpu; c++){
if(c == cpus+cpunum()) // We've started already.
if(c == mycpu()) // We've started already.
continue;

// Tell entryother.S what stack to use, where to enter, and what
Expand Down
4 changes: 2 additions & 2 deletions pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pipewrite(struct pipe *p, char *addr, int n)
acquire(&p->lock);
for(i = 0; i < n; i++){
while(p->nwrite == p->nread + PIPESIZE){ //DOC: pipewrite-full
if(p->readopen == 0 || proc->killed){
if(p->readopen == 0 || myproc()->killed){
release(&p->lock);
return -1;
}
Expand All @@ -104,7 +104,7 @@ piperead(struct pipe *p, char *addr, int n)

acquire(&p->lock);
while(p->nread == p->nwrite && p->writeopen){ //DOC: pipe-empty
if(proc->killed){
if(myproc()->killed){
release(&p->lock);
return -1;
}
Expand Down
Loading

0 comments on commit abf847a

Please sign in to comment.