Eliminate code for gs trick to track per-cpu state. We rely on lapiccpunum()

to find a per-cpu id with which we locate a cpu's cpu struct.
This commit is contained in:
Frans Kaashoek 2017-02-01 18:04:13 -05:00
parent fbb4c09444
commit ed396c068b
8 changed files with 33 additions and 67 deletions

34
proc.c
View file

@ -26,12 +26,29 @@ pinit(void)
initlock(&ptable.lock, "ptable");
}
// XXX get rid off?
// Must be called with interrupts disabled
int
cpuid() {
return mycpu()-cpus;
}
// Must be called with interrupts disabled
struct cpu*
mycpu(void)
{
// Would prefer to panic but even printing is chancy here: almost everything,
// including cprintf and panic, calls mycpu(), often indirectly through
// acquire and release.
if(readeflags()&FL_IF){
static int n;
if(n++ == 0)
cprintf("mycpu called from %x with interrupts enabled\n",
__builtin_return_address(0));
}
return &cpus[lapiccpunum()];
}
// Disable interrupts so that we are not rescheduled
// while reading proc from the cpu structure
struct proc*
@ -304,7 +321,8 @@ scheduler(void)
{
struct proc *p;
struct cpu *c = mycpu();
c->proc = 0;
for(;;){
// Enable interrupts on this processor.
sti();
@ -321,15 +339,13 @@ scheduler(void)
c->proc = p;
switchuvm(p);
p->state = RUNNING;
p->cpu = c;
// cprintf("%d: switch to %d\n", c-cpus, p->pid);
swtch(&(p->cpu->scheduler), p->context);
swtch(&(c->scheduler), p->context);
switchkvm();
// Process is done running for now.
// It should have changed its p->state before coming back.
c->proc = 0;
p->cpu = 0;
}
release(&ptable.lock);
@ -358,9 +374,7 @@ sched(void)
if(readeflags()&FL_IF)
panic("sched interruptible");
intena = mycpu()->intena;
// cprintf("%d: before swtch %d %x\n", p->cpu-cpus, p->pid, * (int *) 0x1d);
swtch(&p->context, p->cpu->scheduler);
// cprintf("%d/%d: after swtch %d %x\n", cpuid(), p->cpu-cpus, p->pid, * (int *) 0x1d);
swtch(&p->context, mycpu()->scheduler);
mycpu()->intena = intena;
}
@ -422,8 +436,6 @@ sleep(void *chan, struct spinlock *lk)
p->chan = chan;
p->state = SLEEPING;
// cprintf("sleep %d\n", p->pid);
sched();
// Tidy up.