summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2017-02-01 18:04:13 -0500
committerFrans Kaashoek <[email protected]>2017-02-01 18:04:13 -0500
commited396c068b881877330f7d40bfce02db9b1199b3 (patch)
tree69103a78128b46d6bae179b0440cca0a9c7f0b0c /proc.c
parentfbb4c0944422f860484142010bb9f366f3e87bf8 (diff)
downloadxv6-labs-ed396c068b881877330f7d40bfce02db9b1199b3.tar.gz
xv6-labs-ed396c068b881877330f7d40bfce02db9b1199b3.tar.bz2
xv6-labs-ed396c068b881877330f7d40bfce02db9b1199b3.zip
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.
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/proc.c b/proc.c
index 4e8f461..6445725 100644
--- a/proc.c
+++ b/proc.c
@@ -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.