summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2017-02-01 20:36:41 -0500
committerFrans Kaashoek <[email protected]>2017-02-01 20:36:41 -0500
commitc9fa90f7e514f27fa1ac071cd9795f3830ab6a1b (patch)
tree2bfaf92fbd2a649247af758c8e8967f7df3c45ac /proc.c
parent2e2d14c235b570a6beb222fc1bfa53de85a98de3 (diff)
downloadxv6-labs-c9fa90f7e514f27fa1ac071cd9795f3830ab6a1b.tar.gz
xv6-labs-c9fa90f7e514f27fa1ac071cd9795f3830ab6a1b.tar.bz2
xv6-labs-c9fa90f7e514f27fa1ac071cd9795f3830ab6a1b.zip
A tiny bit of clean up (e.g., move code searching cpu array from lapic.c into
mycpu() in proc.c.
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/proc.c b/proc.c
index ca343cb..aac7523 100644
--- a/proc.c
+++ b/proc.c
@@ -32,13 +32,24 @@ cpuid() {
return mycpu()-cpus;
}
-// Must be called with interrupts disabled
+// Must be called with interrupts disabled to avoid the caller being rescheduled
+// between reading lapicid and running through the loop.
struct cpu*
mycpu(void)
{
+ int apicid, i;
+
if(readeflags()&FL_IF)
panic("mycpu called with interrupts enabled\n");
- return &cpus[lapiccpunum()];
+
+ apicid = lapicid();
+ // APIC IDs are not guaranteed to be contiguous. Maybe we should have
+ // a reverse map, or reserve a register to store &cpus[i].
+ for (i = 0; i < ncpu; ++i) {
+ if (cpus[i].apicid == apicid)
+ return &cpus[i];
+ }
+ panic("unknown apicid\n");
}
// Disable interrupts so that we are not rescheduled