1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Multiprocessing Communications Interface (MPCI) Handler |
---|
5 | * @ingroup ScoreMPCI |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2008. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/mpciimpl.h> |
---|
22 | #include <rtems/score/coresemimpl.h> |
---|
23 | #include <rtems/score/interr.h> |
---|
24 | #include <rtems/score/stackimpl.h> |
---|
25 | #include <rtems/score/sysstate.h> |
---|
26 | #include <rtems/score/threadimpl.h> |
---|
27 | #include <rtems/score/threadqimpl.h> |
---|
28 | #include <rtems/config.h> |
---|
29 | |
---|
30 | RTEMS_STATIC_ASSERT( |
---|
31 | sizeof(MPCI_Internal_packet) <= MP_PACKET_MINIMUM_PACKET_SIZE, |
---|
32 | MPCI_Internal_packet |
---|
33 | ); |
---|
34 | |
---|
35 | /** |
---|
36 | * This is the core semaphore which the MPCI Receive Server blocks on. |
---|
37 | */ |
---|
38 | CORE_semaphore_Control _MPCI_Semaphore; |
---|
39 | |
---|
40 | void _MPCI_Handler_initialization( |
---|
41 | uint32_t timeout_status |
---|
42 | ) |
---|
43 | { |
---|
44 | CORE_semaphore_Attributes attributes; |
---|
45 | MPCI_Control *users_mpci_table; |
---|
46 | |
---|
47 | users_mpci_table = _Configuration_MP_table->User_mpci_table; |
---|
48 | |
---|
49 | if ( _System_state_Is_multiprocessing && !users_mpci_table ) |
---|
50 | _Terminate( |
---|
51 | INTERNAL_ERROR_CORE, |
---|
52 | true, |
---|
53 | INTERNAL_ERROR_NO_MPCI |
---|
54 | ); |
---|
55 | |
---|
56 | _MPCI_table = users_mpci_table; |
---|
57 | |
---|
58 | if ( !_System_state_Is_multiprocessing ) |
---|
59 | return; |
---|
60 | |
---|
61 | /* |
---|
62 | * Register the MP Process Packet routine. |
---|
63 | */ |
---|
64 | |
---|
65 | _MPCI_Register_packet_processor( |
---|
66 | MP_PACKET_MPCI_INTERNAL, |
---|
67 | _MPCI_Internal_packets_Process_packet |
---|
68 | ); |
---|
69 | |
---|
70 | /* |
---|
71 | * Create the counting semaphore used by the MPCI Receive Server. |
---|
72 | */ |
---|
73 | |
---|
74 | attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO; |
---|
75 | |
---|
76 | _CORE_semaphore_Initialize( |
---|
77 | &_MPCI_Semaphore, |
---|
78 | &attributes, /* the_semaphore_attributes */ |
---|
79 | 0 /* initial_value */ |
---|
80 | ); |
---|
81 | |
---|
82 | _Thread_queue_Initialize( |
---|
83 | &_MPCI_Remote_blocked_threads, |
---|
84 | THREAD_QUEUE_DISCIPLINE_FIFO, |
---|
85 | STATES_WAITING_FOR_RPC_REPLY, |
---|
86 | timeout_status |
---|
87 | ); |
---|
88 | } |
---|
89 | |
---|
90 | void _MPCI_Create_server( void ) |
---|
91 | { |
---|
92 | Objects_Name name; |
---|
93 | |
---|
94 | |
---|
95 | if ( !_System_state_Is_multiprocessing ) |
---|
96 | return; |
---|
97 | |
---|
98 | /* |
---|
99 | * Initialize the MPCI Receive Server |
---|
100 | */ |
---|
101 | |
---|
102 | _MPCI_Receive_server_tcb = _Thread_Internal_allocate(); |
---|
103 | |
---|
104 | name.name_u32 = _Objects_Build_name( 'M', 'P', 'C', 'I' ); |
---|
105 | _Thread_Initialize( |
---|
106 | &_Thread_Internal_information, |
---|
107 | _MPCI_Receive_server_tcb, |
---|
108 | NULL, /* allocate the stack */ |
---|
109 | _Stack_Minimum() + |
---|
110 | CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK + |
---|
111 | _Configuration_MP_table->extra_mpci_receive_server_stack, |
---|
112 | CPU_ALL_TASKS_ARE_FP, |
---|
113 | PRIORITY_MINIMUM, |
---|
114 | false, /* no preempt */ |
---|
115 | THREAD_CPU_BUDGET_ALGORITHM_NONE, |
---|
116 | NULL, /* no budget algorithm callout */ |
---|
117 | 0, /* all interrupts enabled */ |
---|
118 | name |
---|
119 | ); |
---|
120 | |
---|
121 | _Thread_Start( |
---|
122 | _MPCI_Receive_server_tcb, |
---|
123 | THREAD_START_NUMERIC, |
---|
124 | (void *) _MPCI_Receive_server, |
---|
125 | NULL, |
---|
126 | 0, |
---|
127 | NULL |
---|
128 | ); |
---|
129 | } |
---|
130 | |
---|
131 | void _MPCI_Initialization ( void ) |
---|
132 | { |
---|
133 | (*_MPCI_table->initialization)(); |
---|
134 | } |
---|
135 | |
---|
136 | void _MPCI_Register_packet_processor( |
---|
137 | MP_packet_Classes the_class, |
---|
138 | MPCI_Packet_processor the_packet_processor |
---|
139 | |
---|
140 | ) |
---|
141 | { |
---|
142 | _MPCI_Packet_processors[ the_class ] = the_packet_processor; |
---|
143 | } |
---|
144 | |
---|
145 | MP_packet_Prefix *_MPCI_Get_packet ( void ) |
---|
146 | { |
---|
147 | MP_packet_Prefix *the_packet; |
---|
148 | |
---|
149 | (*_MPCI_table->get_packet)( &the_packet ); |
---|
150 | |
---|
151 | if ( the_packet == NULL ) |
---|
152 | _Terminate( |
---|
153 | INTERNAL_ERROR_CORE, |
---|
154 | true, |
---|
155 | INTERNAL_ERROR_OUT_OF_PACKETS |
---|
156 | ); |
---|
157 | |
---|
158 | /* |
---|
159 | * Put in a default timeout that will be used for |
---|
160 | * all packets that do not otherwise have a timeout. |
---|
161 | */ |
---|
162 | |
---|
163 | the_packet->timeout = MPCI_DEFAULT_TIMEOUT; |
---|
164 | |
---|
165 | return the_packet; |
---|
166 | } |
---|
167 | |
---|
168 | void _MPCI_Return_packet ( |
---|
169 | MP_packet_Prefix *the_packet |
---|
170 | ) |
---|
171 | { |
---|
172 | (*_MPCI_table->return_packet)( the_packet ); |
---|
173 | } |
---|
174 | |
---|
175 | void _MPCI_Send_process_packet ( |
---|
176 | uint32_t destination, |
---|
177 | MP_packet_Prefix *the_packet |
---|
178 | ) |
---|
179 | { |
---|
180 | the_packet->source_tid = _Thread_Executing->Object.id; |
---|
181 | the_packet->to_convert = |
---|
182 | ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t); |
---|
183 | |
---|
184 | (*_MPCI_table->send_packet)( destination, the_packet ); |
---|
185 | } |
---|
186 | |
---|
187 | uint32_t _MPCI_Send_request_packet ( |
---|
188 | uint32_t destination, |
---|
189 | MP_packet_Prefix *the_packet, |
---|
190 | States_Control extra_state |
---|
191 | ) |
---|
192 | { |
---|
193 | Thread_Control *executing = _Thread_Executing; |
---|
194 | |
---|
195 | the_packet->source_tid = executing->Object.id; |
---|
196 | the_packet->source_priority = executing->current_priority; |
---|
197 | the_packet->to_convert = |
---|
198 | ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t); |
---|
199 | |
---|
200 | executing->Wait.id = the_packet->id; |
---|
201 | |
---|
202 | executing->Wait.queue = &_MPCI_Remote_blocked_threads; |
---|
203 | |
---|
204 | _Thread_Disable_dispatch(); |
---|
205 | |
---|
206 | (*_MPCI_table->send_packet)( destination, the_packet ); |
---|
207 | |
---|
208 | _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads ); |
---|
209 | |
---|
210 | /* |
---|
211 | * See if we need a default timeout |
---|
212 | */ |
---|
213 | |
---|
214 | if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT) |
---|
215 | the_packet->timeout = _MPCI_table->default_timeout; |
---|
216 | |
---|
217 | _Thread_queue_Enqueue( |
---|
218 | &_MPCI_Remote_blocked_threads, |
---|
219 | executing, |
---|
220 | the_packet->timeout |
---|
221 | ); |
---|
222 | |
---|
223 | executing->current_state = |
---|
224 | _States_Set( extra_state, executing->current_state ); |
---|
225 | |
---|
226 | _Thread_Enable_dispatch(); |
---|
227 | |
---|
228 | return executing->Wait.return_code; |
---|
229 | } |
---|
230 | |
---|
231 | void _MPCI_Send_response_packet ( |
---|
232 | uint32_t destination, |
---|
233 | MP_packet_Prefix *the_packet |
---|
234 | ) |
---|
235 | { |
---|
236 | the_packet->source_tid = _Thread_Executing->Object.id; |
---|
237 | |
---|
238 | (*_MPCI_table->send_packet)( destination, the_packet ); |
---|
239 | } |
---|
240 | |
---|
241 | MP_packet_Prefix *_MPCI_Receive_packet ( void ) |
---|
242 | { |
---|
243 | MP_packet_Prefix *the_packet; |
---|
244 | |
---|
245 | (*_MPCI_table->receive_packet)( &the_packet ); |
---|
246 | |
---|
247 | return the_packet; |
---|
248 | } |
---|
249 | |
---|
250 | Thread_Control *_MPCI_Process_response ( |
---|
251 | MP_packet_Prefix *the_packet |
---|
252 | ) |
---|
253 | { |
---|
254 | Thread_Control *the_thread; |
---|
255 | Objects_Locations location; |
---|
256 | |
---|
257 | the_thread = _Thread_Get( the_packet->id, &location ); |
---|
258 | switch ( location ) { |
---|
259 | case OBJECTS_ERROR: |
---|
260 | #if defined(RTEMS_MULTIPROCESSING) |
---|
261 | case OBJECTS_REMOTE: |
---|
262 | #endif |
---|
263 | the_thread = NULL; /* IMPOSSIBLE */ |
---|
264 | break; |
---|
265 | case OBJECTS_LOCAL: |
---|
266 | _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread ); |
---|
267 | the_thread->Wait.return_code = the_packet->return_code; |
---|
268 | _Objects_Put_without_thread_dispatch( &the_thread->Object ); |
---|
269 | break; |
---|
270 | } |
---|
271 | |
---|
272 | return the_thread; |
---|
273 | } |
---|
274 | |
---|
275 | /* |
---|
276 | * _MPCI_Receive_server |
---|
277 | * |
---|
278 | */ |
---|
279 | |
---|
280 | Thread _MPCI_Receive_server( |
---|
281 | uint32_t ignored |
---|
282 | ) |
---|
283 | { |
---|
284 | |
---|
285 | MP_packet_Prefix *the_packet; |
---|
286 | MPCI_Packet_processor the_function; |
---|
287 | Thread_Control *executing; |
---|
288 | |
---|
289 | executing = _Thread_Get_executing(); |
---|
290 | |
---|
291 | for ( ; ; ) { |
---|
292 | |
---|
293 | executing->receive_packet = NULL; |
---|
294 | |
---|
295 | _Thread_Disable_dispatch(); |
---|
296 | _CORE_semaphore_Seize( |
---|
297 | &_MPCI_Semaphore, |
---|
298 | executing, |
---|
299 | 0, |
---|
300 | true, |
---|
301 | WATCHDOG_NO_TIMEOUT |
---|
302 | ); |
---|
303 | _Thread_Enable_dispatch(); |
---|
304 | |
---|
305 | for ( ; ; ) { |
---|
306 | the_packet = _MPCI_Receive_packet(); |
---|
307 | |
---|
308 | if ( !the_packet ) |
---|
309 | break; |
---|
310 | |
---|
311 | executing->receive_packet = the_packet; |
---|
312 | |
---|
313 | if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) ) |
---|
314 | break; |
---|
315 | |
---|
316 | the_function = _MPCI_Packet_processors[ the_packet->the_class ]; |
---|
317 | |
---|
318 | if ( !the_function ) |
---|
319 | _Terminate( |
---|
320 | INTERNAL_ERROR_CORE, |
---|
321 | true, |
---|
322 | INTERNAL_ERROR_BAD_PACKET |
---|
323 | ); |
---|
324 | |
---|
325 | (*the_function)( the_packet ); |
---|
326 | } |
---|
327 | } |
---|
328 | |
---|
329 | return 0; /* unreached - only to remove warnings */ |
---|
330 | } |
---|
331 | |
---|
332 | void _MPCI_Announce ( void ) |
---|
333 | { |
---|
334 | _Thread_Disable_dispatch(); |
---|
335 | (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 ); |
---|
336 | _Thread_Enable_dispatch(); |
---|
337 | } |
---|
338 | |
---|
339 | void _MPCI_Internal_packets_Send_process_packet ( |
---|
340 | MPCI_Internal_Remote_operations operation |
---|
341 | ) |
---|
342 | { |
---|
343 | MPCI_Internal_packet *the_packet; |
---|
344 | |
---|
345 | switch ( operation ) { |
---|
346 | |
---|
347 | case MPCI_PACKETS_SYSTEM_VERIFY: |
---|
348 | |
---|
349 | the_packet = _MPCI_Internal_packets_Get_packet(); |
---|
350 | the_packet->Prefix.the_class = MP_PACKET_MPCI_INTERNAL; |
---|
351 | the_packet->Prefix.length = sizeof ( MPCI_Internal_packet ); |
---|
352 | the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet ); |
---|
353 | the_packet->operation = operation; |
---|
354 | |
---|
355 | the_packet->maximum_nodes = _Objects_Maximum_nodes; |
---|
356 | |
---|
357 | the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects; |
---|
358 | |
---|
359 | _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix ); |
---|
360 | break; |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | /* |
---|
365 | * _MPCI_Internal_packets_Send_request_packet |
---|
366 | * |
---|
367 | * This subprogram is not needed since there are no request |
---|
368 | * packets to be sent by this manager. |
---|
369 | * |
---|
370 | */ |
---|
371 | |
---|
372 | /* |
---|
373 | * _MPCI_Internal_packets_Send_response_packet |
---|
374 | * |
---|
375 | * This subprogram is not needed since there are no response |
---|
376 | * packets to be sent by this manager. |
---|
377 | * |
---|
378 | */ |
---|
379 | |
---|
380 | void _MPCI_Internal_packets_Process_packet ( |
---|
381 | MP_packet_Prefix *the_packet_prefix |
---|
382 | ) |
---|
383 | { |
---|
384 | MPCI_Internal_packet *the_packet; |
---|
385 | uint32_t maximum_nodes; |
---|
386 | uint32_t maximum_global_objects; |
---|
387 | |
---|
388 | the_packet = (MPCI_Internal_packet *) the_packet_prefix; |
---|
389 | |
---|
390 | switch ( the_packet->operation ) { |
---|
391 | |
---|
392 | case MPCI_PACKETS_SYSTEM_VERIFY: |
---|
393 | |
---|
394 | maximum_nodes = the_packet->maximum_nodes; |
---|
395 | maximum_global_objects = the_packet->maximum_global_objects; |
---|
396 | if ( maximum_nodes != _Objects_Maximum_nodes || |
---|
397 | maximum_global_objects != _Objects_MP_Maximum_global_objects ) { |
---|
398 | |
---|
399 | _MPCI_Return_packet( the_packet_prefix ); |
---|
400 | |
---|
401 | _Terminate( |
---|
402 | INTERNAL_ERROR_CORE, |
---|
403 | true, |
---|
404 | INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION |
---|
405 | ); |
---|
406 | } |
---|
407 | |
---|
408 | _MPCI_Return_packet( the_packet_prefix ); |
---|
409 | |
---|
410 | break; |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | /* |
---|
415 | * _MPCI_Internal_packets_Send_object_was_deleted |
---|
416 | * |
---|
417 | * This subprogram is not needed since there are no objects |
---|
418 | * deleted by this manager. |
---|
419 | * |
---|
420 | */ |
---|
421 | |
---|
422 | /* |
---|
423 | * _MPCI_Internal_packets_Send_extract_proxy |
---|
424 | * |
---|
425 | * This subprogram is not needed since there are no objects |
---|
426 | * deleted by this manager. |
---|
427 | * |
---|
428 | */ |
---|
429 | |
---|
430 | MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void ) |
---|
431 | { |
---|
432 | return ( (MPCI_Internal_packet *) _MPCI_Get_packet() ); |
---|
433 | } |
---|
434 | |
---|
435 | /* end of file */ |
---|