source: rtems/cpukit/score/src/mpci.c @ 976162a6

4.104.114.95
Last change on this file since 976162a6 was 976162a6, checked in by Joel Sherrill <joel.sherrill@…>, on 12/03/07 at 22:23:13

2007-12-03 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/malloc.c, libmisc/monitor/mon-command.c, posix/preinstall.am, posix/include/rtems/posix/cond.h, posix/include/rtems/posix/mqueue.h, posix/include/rtems/posix/mutex.h, posix/include/rtems/posix/pthread.h, posix/include/rtems/posix/semaphore.h, posix/src/conddestroy.c, posix/src/mutexdestroy.c, posix/src/mutexinit.c, posix/src/mutexsetprioceiling.c, posix/src/mutexunlock.c, sapi/include/confdefs.h, sapi/include/rtems/config.h, sapi/include/rtems/init.h, sapi/include/rtems/sptables.h, sapi/src/exinit.c, score/include/rtems/system.h, score/include/rtems/score/mpci.h, score/src/mpci.c, score/src/thread.c, score/src/threadcreateidle.c, score/src/threadstackallocate.c, score/src/threadstackfree.c, score/src/wkspace.c: Moved most of the remaining CPU Table fields to the Configuration Table. This included pretasking_hook, predriver_hook, postdriver_hook, idle_task, do_zero_of_workspace, extra_mpci_receive_server_stack, stack_allocate_hook, and stack_free_hook. As a side-effect of this effort some multiprocessing code was made conditional and some style clean up occurred.
  • Property mode set to 100644
File size: 11.2 KB
Line 
1/*
2 *  Multiprocessing Communications Interface (MPCI) Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2007.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#if defined(RTEMS_MULTIPROCESSING)
21#include <rtems/score/mpci.h>
22#include <rtems/score/mppkt.h>
23#endif
24#include <rtems/score/cpu.h>
25#include <rtems/score/interr.h>
26#include <rtems/score/states.h>
27#include <rtems/score/thread.h>
28#include <rtems/score/threadq.h>
29#include <rtems/score/tqdata.h>
30#include <rtems/score/watchdog.h>
31#include <rtems/score/sysstate.h>
32
33#include <rtems/score/coresem.h>
34#include <rtems/config.h>
35
36/*PAGE
37 *
38 *  _MPCI_Handler_initialization
39 *
40 *  This subprogram performs the initialization necessary for this handler.
41 */
42
43void _MPCI_Handler_initialization(
44  MPCI_Control            *users_mpci_table,
45  uint32_t                 timeout_status
46)
47{
48  CORE_semaphore_Attributes    attributes;
49
50  if ( _System_state_Is_multiprocessing && !users_mpci_table )
51    _Internal_error_Occurred(
52      INTERNAL_ERROR_CORE,
53      TRUE,
54      INTERNAL_ERROR_NO_MPCI
55    );
56
57  _MPCI_table = users_mpci_table;
58
59  if ( !_System_state_Is_multiprocessing )
60    return;
61
62  /*
63   *  Register the MP Process Packet routine.
64   */
65
66  _MPCI_Register_packet_processor(
67    MP_PACKET_MPCI_INTERNAL,
68    _MPCI_Internal_packets_Process_packet
69  );
70
71  /*
72   *  Create the counting semaphore used by the MPCI Receive Server.
73   */
74
75  attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
76
77  _CORE_semaphore_Initialize(
78    &_MPCI_Semaphore,
79    &attributes,              /* the_semaphore_attributes */
80    0                         /* initial_value */
81  );
82
83  _Thread_queue_Initialize(
84    &_MPCI_Remote_blocked_threads,
85    THREAD_QUEUE_DISCIPLINE_FIFO,
86    STATES_WAITING_FOR_RPC_REPLY,
87    timeout_status
88  );
89}
90
91/*PAGE
92 *
93 *  _MPCI_Create_server
94 *
95 *  This subprogram creates the MPCI receive server.
96 */
97
98char *_MPCI_Internal_name = "MPCI";
99
100void _MPCI_Create_server( void )
101{
102
103  if ( !_System_state_Is_multiprocessing )
104    return;
105
106  /*
107   *  Initialize the MPCI Receive Server
108   */
109
110  _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
111
112  _Thread_Initialize(
113    &_Thread_Internal_information,
114    _MPCI_Receive_server_tcb,
115    NULL,        /* allocate the stack */
116    STACK_MINIMUM_SIZE +
117      CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK +
118      _Configuration_MP_table->extra_mpci_receive_server_stack,
119    CPU_ALL_TASKS_ARE_FP,
120    PRIORITY_MINIMUM,
121    FALSE,       /* no preempt */
122    THREAD_CPU_BUDGET_ALGORITHM_NONE,
123    NULL,        /* no budget algorithm callout */
124    0,           /* all interrupts enabled */
125    _MPCI_Internal_name
126  );
127
128  _Thread_Start(
129    _MPCI_Receive_server_tcb,
130    THREAD_START_NUMERIC,
131    (void *) _MPCI_Receive_server,
132    NULL,
133    0
134  );
135}
136
137/*PAGE
138 *
139 *  _MPCI_Initialization
140 *
141 *  This subprogram initializes the MPCI driver by
142 *  invoking the user provided MPCI initialization callout.
143 */
144
145void _MPCI_Initialization ( void )
146{
147  (*_MPCI_table->initialization)();
148}
149
150/*PAGE
151 *
152 *  _MPCI_Register_packet_processor
153 *
154 *  This routine registers the MPCI packet processor for the
155 *  designated object class.
156 */
157
158void _MPCI_Register_packet_processor(
159  MP_packet_Classes      the_class,
160  MPCI_Packet_processor  the_packet_processor
161
162)
163{
164  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
165}
166
167/*PAGE
168 *
169 *  _MPCI_Get_packet
170 *
171 *  This subprogram obtains a packet by invoking the user provided
172 *  MPCI get packet callout.
173 */
174
175MP_packet_Prefix *_MPCI_Get_packet ( void )
176{
177  MP_packet_Prefix  *the_packet;
178
179  (*_MPCI_table->get_packet)( &the_packet );
180
181  if ( the_packet == NULL )
182    _Internal_error_Occurred(
183      INTERNAL_ERROR_CORE,
184      TRUE,
185      INTERNAL_ERROR_OUT_OF_PACKETS
186    );
187
188  /*
189   *  Put in a default timeout that will be used for
190   *  all packets that do not otherwise have a timeout.
191   */
192
193  the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
194
195  return the_packet;
196}
197
198/*PAGE
199 *
200 *  _MPCI_Return_packet
201 *
202 *  This subprogram returns a packet by invoking the user provided
203 *  MPCI return packet callout.
204 */
205
206void _MPCI_Return_packet (
207  MP_packet_Prefix   *the_packet
208)
209{
210  (*_MPCI_table->return_packet)( the_packet );
211}
212
213/*PAGE
214 *
215 *  _MPCI_Send_process_packet
216 *
217 *  This subprogram sends a process packet by invoking the user provided
218 *  MPCI send callout.
219 */
220
221void _MPCI_Send_process_packet (
222  uint32_t            destination,
223  MP_packet_Prefix   *the_packet
224)
225{
226  the_packet->source_tid = _Thread_Executing->Object.id;
227  the_packet->to_convert =
228     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
229       sizeof(uint32_t  );
230
231  (*_MPCI_table->send_packet)( destination, the_packet );
232}
233
234/*PAGE
235 *
236 *  _MPCI_Send_request_packet
237 *
238 *  This subprogram sends a request packet by invoking the user provided
239 *  MPCI send callout.
240 */
241
242uint32_t   _MPCI_Send_request_packet (
243  uint32_t            destination,
244  MP_packet_Prefix   *the_packet,
245  States_Control      extra_state
246)
247{
248  the_packet->source_tid      = _Thread_Executing->Object.id;
249  the_packet->source_priority = _Thread_Executing->current_priority;
250  the_packet->to_convert =
251     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
252       sizeof(uint32_t  );
253
254  _Thread_Executing->Wait.id = the_packet->id;
255
256  _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads;
257
258  _Thread_Disable_dispatch();
259
260    (*_MPCI_table->send_packet)( destination, the_packet );
261
262    _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads );
263
264    /*
265     *  See if we need a default timeout
266     */
267
268    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
269        the_packet->timeout = _MPCI_table->default_timeout;
270
271    _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout );
272
273    _Thread_Executing->current_state =
274      _States_Set( extra_state, _Thread_Executing->current_state );
275
276  _Thread_Enable_dispatch();
277
278  return _Thread_Executing->Wait.return_code;
279}
280
281/*PAGE
282 *
283 *  _MPCI_Send_response_packet
284 *
285 *  This subprogram sends a response packet by invoking the user provided
286 *  MPCI send callout.
287 */
288
289void _MPCI_Send_response_packet (
290  uint32_t            destination,
291  MP_packet_Prefix   *the_packet
292)
293{
294  the_packet->source_tid = _Thread_Executing->Object.id;
295
296  (*_MPCI_table->send_packet)( destination, the_packet );
297}
298
299/*PAGE
300 *
301 *  _MPCI_Receive_packet
302 *
303 *  This subprogram receives a packet by invoking the user provided
304 *  MPCI receive callout.
305 */
306
307MP_packet_Prefix  *_MPCI_Receive_packet ( void )
308{
309  MP_packet_Prefix  *the_packet;
310
311  (*_MPCI_table->receive_packet)( &the_packet );
312
313  return the_packet;
314}
315
316/*PAGE
317 *
318 *  _MPCI_Process_response
319 *
320 *  This subprogram obtains a packet by invoking the user provided
321 *  MPCI get packet callout.
322 */
323
324Thread_Control *_MPCI_Process_response (
325  MP_packet_Prefix  *the_packet
326)
327{
328  Thread_Control    *the_thread;
329  Objects_Locations  location;
330
331  the_thread = _Thread_Get( the_packet->id, &location );
332  switch ( location ) {
333    case OBJECTS_ERROR:
334#if defined(RTEMS_MULTIPROCESSING)
335    case OBJECTS_REMOTE:
336#endif
337      the_thread = NULL;          /* IMPOSSIBLE */
338      break;
339    case OBJECTS_LOCAL:
340      _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread );
341      the_thread->Wait.return_code = the_packet->return_code;
342      _Thread_Unnest_dispatch();
343    break;
344  }
345
346  return the_thread;
347}
348
349/*PAGE
350 *
351 *  _MPCI_Receive_server
352 *
353 */
354
355Thread _MPCI_Receive_server(
356  uint32_t   ignored
357)
358{
359
360  MP_packet_Prefix         *the_packet;
361  MPCI_Packet_processor     the_function;
362  Thread_Control           *executing;
363
364  executing = _Thread_Executing;
365
366  for ( ; ; ) {
367
368    executing->receive_packet = NULL;
369
370    _Thread_Disable_dispatch();
371    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, TRUE, WATCHDOG_NO_TIMEOUT );
372    _Thread_Enable_dispatch();
373
374    for ( ; ; ) {
375      the_packet = _MPCI_Receive_packet();
376
377      if ( !the_packet )
378        break;
379
380      executing->receive_packet = the_packet;
381
382      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
383        break;
384
385      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
386
387      if ( !the_function )
388        _Internal_error_Occurred(
389          INTERNAL_ERROR_CORE,
390          TRUE,
391          INTERNAL_ERROR_BAD_PACKET
392        );
393
394        (*the_function)( the_packet );
395    }
396  }
397
398  return 0;   /* unreached - only to remove warnings */
399}
400
401/*PAGE
402 *
403 *  _MPCI_Announce
404 *
405 */
406
407void _MPCI_Announce ( void )
408{
409  _Thread_Disable_dispatch();
410  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
411  _Thread_Enable_dispatch();
412}
413
414/*PAGE
415 *
416 *  _MPCI_Internal_packets_Send_process_packet
417 *
418 */
419
420void _MPCI_Internal_packets_Send_process_packet (
421   MPCI_Internal_Remote_operations operation
422)
423{
424  MPCI_Internal_packet *the_packet;
425
426  switch ( operation ) {
427
428    case MPCI_PACKETS_SYSTEM_VERIFY:
429
430      the_packet                    = _MPCI_Internal_packets_Get_packet();
431      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
432      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
433      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
434      the_packet->operation         = operation;
435
436      the_packet->maximum_nodes = _Objects_Maximum_nodes;
437
438      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
439
440      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
441      break;
442  }
443}
444
445/*PAGE
446 *
447 *  _MPCI_Internal_packets_Send_request_packet
448 *
449 *  This subprogram is not needed since there are no request
450 *  packets to be sent by this manager.
451 *
452 */
453
454/*PAGE
455 *
456 *  _MPCI_Internal_packets_Send_response_packet
457 *
458 *  This subprogram is not needed since there are no response
459 *  packets to be sent by this manager.
460 *
461 */
462
463/*PAGE
464 *
465 *
466 *  _MPCI_Internal_packets_Process_packet
467 *
468 */
469
470void _MPCI_Internal_packets_Process_packet (
471  MP_packet_Prefix  *the_packet_prefix
472)
473{
474  MPCI_Internal_packet *the_packet;
475  uint32_t                    maximum_nodes;
476  uint32_t                    maximum_global_objects;
477
478  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
479
480  switch ( the_packet->operation ) {
481
482    case MPCI_PACKETS_SYSTEM_VERIFY:
483
484      maximum_nodes          = the_packet->maximum_nodes;
485      maximum_global_objects = the_packet->maximum_global_objects;
486      if ( maximum_nodes != _Objects_Maximum_nodes ||
487           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
488
489        _MPCI_Return_packet( the_packet_prefix );
490
491        _Internal_error_Occurred(
492          INTERNAL_ERROR_CORE,
493          TRUE,
494          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
495        );
496      }
497
498      _MPCI_Return_packet( the_packet_prefix );
499
500      break;
501  }
502}
503
504/*PAGE
505 *
506 *  _MPCI_Internal_packets_Send_object_was_deleted
507 *
508 *  This subprogram is not needed since there are no objects
509 *  deleted by this manager.
510 *
511 */
512
513/*PAGE
514 *
515 *  _MPCI_Internal_packets_Send_extract_proxy
516 *
517 *  This subprogram is not needed since there are no objects
518 *  deleted by this manager.
519 *
520 */
521
522/*PAGE
523 *
524 *  _MPCI_Internal_packets_Get_packet
525 *
526 */
527
528MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
529{
530  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
531}
532
533/* end of file */
Note: See TracBrowser for help on using the repository browser.