diff options
author | Robert Morris <[email protected]> | 2019-06-05 11:42:03 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-06-05 11:42:03 -0400 |
commit | f1a727b971a59bab6025b4c4111342c27356ca40 (patch) | |
tree | d22d52c613bfc003e6fb75b5d137aeff9d954201 /proc.c | |
parent | ec3d3a1fceee437c640f9c5c05fc517edfb1899e (diff) | |
download | xv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.tar.gz xv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.tar.bz2 xv6-labs-f1a727b971a59bab6025b4c4111342c27356ca40.zip |
start at support for multiple CPUs
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -32,28 +32,33 @@ procinit(void) initlock(&ptable.lock, "ptable"); } -// Must be called with interrupts disabled. -// XXX riscv +// Must be called with interrupts disabled, +// to prevent race with process being moved +// to a different CPU. int -cpuid() { - return 0; +cpuid() +{ + int id = r_tp(); + return id; } // Return this core's cpu struct. -// XXX riscv +// Interrupts must be disabled. struct cpu* mycpu(void) { - struct cpu *c; - c = &cpus[0]; + int id = cpuid(); + struct cpu *c = &cpus[id]; return c; } -// Disable interrupts so that we are not rescheduled -// while reading proc from the cpu structure -// XXX riscv +// Return the current struct proc *. struct proc* myproc(void) { - return cpus[0].proc; + // XXX push intr off + struct cpu *c = mycpu(); + struct proc *p = c->proc; + // XXX pop intr + return p; } //PAGEBREAK: 32 |