File tree 4 files changed +17
-17
lines changed
4 files changed +17
-17
lines changed Original file line number Diff line number Diff line change @@ -112,7 +112,7 @@ panic(char *s)
112
112
cli ();
113
113
cons .locking = 0 ;
114
114
// use lapiccpunum so that we can call panic from mycpu()
115
- cprintf ("cpu %d: panic: " , lapiccpunum ());
115
+ cprintf ("lapicid %d: panic: " , lapicid ());
116
116
cprintf (s );
117
117
cprintf ("\n" );
118
118
getcallerpcs (& s , pcs );
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ void kbdintr(void);
74
74
75
75
// lapic.c
76
76
void cmostime (struct rtcdate * r );
77
- int lapiccpunum (void );
77
+ int lapicid (void );
78
78
extern volatile uint * lapic ;
79
79
void lapiceoi (void );
80
80
void lapicinit (void );
Original file line number Diff line number Diff line change 9
9
#include "traps.h"
10
10
#include "mmu.h"
11
11
#include "x86.h"
12
- #include "proc.h" // ncpu
13
12
14
13
// Local APIC registers, divided by 4 for use as uint[] indices.
15
14
#define ID (0x0020/4) // ID
@@ -98,22 +97,12 @@ lapicinit(void)
98
97
lapicw (TPR , 0 );
99
98
}
100
99
101
- // Should be called with interrupts disabled: the calling thread shouldn't be
102
- // rescheduled between reading lapic[ID] and checking against cpu array.
103
100
int
104
- lapiccpunum (void )
101
+ lapicid (void )
105
102
{
106
- int apicid , i ;
107
-
108
103
if (!lapic )
109
104
return 0 ;
110
-
111
- apicid = lapic [ID ] >> 24 ;
112
- for (i = 0 ; i < ncpu ; ++ i ) {
113
- if (cpus [i ].apicid == apicid )
114
- return i ;
115
- }
116
- panic ("unknown apicid\n" );
105
+ return lapic [ID ] >> 24 ;
117
106
}
118
107
119
108
// Acknowledge interrupt.
Original file line number Diff line number Diff line change @@ -32,13 +32,24 @@ cpuid() {
32
32
return mycpu ()- cpus ;
33
33
}
34
34
35
- // Must be called with interrupts disabled
35
+ // Must be called with interrupts disabled to avoid the caller being rescheduled
36
+ // between reading lapicid and running through the loop.
36
37
struct cpu *
37
38
mycpu (void )
38
39
{
40
+ int apicid , i ;
41
+
39
42
if (readeflags ()& FL_IF )
40
43
panic ("mycpu called with interrupts enabled\n" );
41
- return & cpus [lapiccpunum ()];
44
+
45
+ apicid = lapicid ();
46
+ // APIC IDs are not guaranteed to be contiguous. Maybe we should have
47
+ // a reverse map, or reserve a register to store &cpus[i].
48
+ for (i = 0 ; i < ncpu ; ++ i ) {
49
+ if (cpus [i ].apicid == apicid )
50
+ return & cpus [i ];
51
+ }
52
+ panic ("unknown apicid\n" );
42
53
}
43
54
44
55
// Disable interrupts so that we are not rescheduled
You can’t perform that action at this time.
0 commit comments