A tiny bit of clean up (e.g., move code searching cpu array from lapic.c into

mycpu() in proc.c.
This commit is contained in:
Frans Kaashoek 2017-02-01 20:36:41 -05:00
parent 2e2d14c235
commit c9fa90f7e5
4 changed files with 17 additions and 17 deletions

15
proc.c
View file

@ -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