summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-05 11:42:03 -0400
committerRobert Morris <[email protected]>2019-06-05 11:42:03 -0400
commitf1a727b971a59bab6025b4c4111342c27356ca40 (patch)
treed22d52c613bfc003e6fb75b5d137aeff9d954201 /proc.c
parentec3d3a1fceee437c640f9c5c05fc517edfb1899e (diff)
downloadxv6-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.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/proc.c b/proc.c
index 768aa6d..766fd93 100644
--- a/proc.c
+++ b/proc.c
@@ -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