65 |
|
|
66 |
/* The bootstrap processor is always running (at start). */ |
/* The bootstrap processor is always running (at start). */ |
67 |
PROCESSOR_CURRENT()->state = PROCESSOR_STATE_RUNNING; |
PROCESSOR_CURRENT()->state = PROCESSOR_STATE_RUNNING; |
68 |
|
PROCESSOR_CURRENT()->cpu_id = CPU_CURRENT (); |
69 |
master_cpu = CPU_CURRENT (); |
master_cpu = CPU_CURRENT (); |
70 |
} |
} |
71 |
|
|
113 |
|
|
114 |
thread->sched_state |= THREAD_STATE_IDLE; |
thread->sched_state |= THREAD_STATE_IDLE; |
115 |
thread_set_priority (thread, THREAD_POLICY_TIMESHARE, 0); |
thread_set_priority (thread, THREAD_POLICY_TIMESHARE, 0); |
116 |
|
trace_printf ("idle thread prio %d", thread->sched_premul); |
117 |
thread_start (thread, idle_thread_fn, processor); |
thread_start (thread, idle_thread_fn, processor); |
118 |
} |
} |
119 |
} |
} |
153 |
if (processor == PROCESSOR_CURRENT ()) |
if (processor == PROCESSOR_CURRENT ()) |
154 |
return; |
return; |
155 |
|
|
156 |
|
#if 1 |
157 |
|
trace_printf ("cpu %d sending dispatch ipi to cpu %d for thread %p", |
158 |
|
CPU_CURRENT (), processor->cpu_id, thread); |
159 |
|
#endif |
160 |
|
|
161 |
spl = SPLOFF (); |
spl = SPLOFF (); |
162 |
msg = get_free_ipi_msg (); |
msg = get_free_ipi_msg (); |
163 |
|
|
172 |
SPLON (spl); |
SPLON (spl); |
173 |
} |
} |
174 |
|
|
175 |
|
/* Terminate THREAD running on PROCESSOR. */ |
176 |
|
|
177 |
|
void |
178 |
|
processor_send_terminate_ipi (struct processor *processor, |
179 |
|
struct thread *thread) |
180 |
|
{ |
181 |
|
struct ipi_msg *msg; |
182 |
|
SPL_T spl; |
183 |
|
|
184 |
|
if (processor == PROCESSOR_CURRENT ()) |
185 |
|
return; |
186 |
|
|
187 |
|
spl = SPLOFF (); |
188 |
|
msg = get_free_ipi_msg (); |
189 |
|
|
190 |
|
msg->ipi_type = PROCESSOR_IPI_TERMINATE; |
191 |
|
msg->common.terminate.dead_thread = thread; |
192 |
|
|
193 |
|
spin_lock (&processor->lock); |
194 |
|
enqueue_tail (&processor->ipi_msg_list, &msg->link); |
195 |
|
spin_unlock (&processor->lock); |
196 |
|
|
197 |
|
SEND_IPI (processor->cpu_id); |
198 |
|
SPLON (spl); |
199 |
|
} |
200 |
|
|
201 |
/* Interprocess interrupt handler. ??? called with interrupts disabled? */ |
/* Interprocess interrupt handler. ??? called with interrupts disabled? */ |
202 |
|
|
203 |
void |
void |
204 |
processor_ipi_handler (void) |
processor_ipi_handler (void) |
205 |
{ |
{ |
206 |
struct processor *this_processor = PROCESSOR_CURRENT (); |
struct processor *this_processor = PROCESSOR_CURRENT (); |
207 |
|
bool halt_p = false, terminate_p = false; |
208 |
struct ipi_msg *msg; |
struct ipi_msg *msg; |
|
bool halt_p = false; |
|
209 |
|
|
210 |
/* Loop through all available messages in this processors msg queue. */ |
/* Loop through all available messages in this processors msg queue. */ |
211 |
|
|
216 |
/* Get first message from queue. */ |
/* Get first message from queue. */ |
217 |
|
|
218 |
msg = (struct ipi_msg *) dequeue_head (&this_processor->ipi_msg_list); |
msg = (struct ipi_msg *) dequeue_head (&this_processor->ipi_msg_list); |
219 |
|
trace_printf ("cpu #%d got ipi msg %d", |
220 |
|
CPU_CURRENT (), msg->ipi_type); |
221 |
switch (msg->ipi_type) |
switch (msg->ipi_type) |
222 |
{ |
{ |
223 |
case PROCESSOR_IPI_HALT: |
case PROCESSOR_IPI_HALT: |
230 |
spin_lock (&this_processor->lock); |
spin_lock (&this_processor->lock); |
231 |
break; |
break; |
232 |
|
|
233 |
|
case PROCESSOR_IPI_TERMINATE: |
234 |
|
/* Check so that we are still running the thread that we |
235 |
|
should terminate. */ |
236 |
|
|
237 |
|
if (THREAD_CURRENT () != msg->common.terminate.dead_thread) |
238 |
|
panic ("??? have switched beyond thread!"); |
239 |
|
|
240 |
|
terminate_p = true; |
241 |
|
break; |
242 |
|
|
243 |
case PROCESSOR_IPI_FLUSH_TLB: |
case PROCESSOR_IPI_FLUSH_TLB: |
244 |
break; |
break; |
245 |
|
|
259 |
for (;;) |
for (;;) |
260 |
; |
; |
261 |
} |
} |
262 |
|
|
263 |
|
/* If we should terminate the current running thread, we do that after |
264 |
|
we have processed all IPI messages. */ |
265 |
|
|
266 |
|
if (terminate_p) |
267 |
|
thread_zombify_running (THREAD_CURRENT ()); |
268 |
} |
} |