source: rtems/cpukit/score/src/mpci.c @ 0e87deaa

4.104.114.9
Last change on this file since 0e87deaa was 0e87deaa, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 26, 2007 at 8:19:02 PM

2007-10-26 Joel Sherrill <joel.sherrill@…>

  • itron/src/can_wup.c, itron/src/chg_pri.c, itron/src/del_mbf.c, itron/src/del_mbx.c, itron/src/del_sem.c, itron/src/del_tsk.c, itron/src/frsm_tsk.c, itron/src/ref_mbf.c, itron/src/ref_mbx.c, itron/src/ref_sem.c, itron/src/ref_tsk.c, itron/src/rel_wai.c, itron/src/rsm_tsk.c, itron/src/sig_sem.c, itron/src/snd_mbx.c, itron/src/sta_tsk.c, itron/src/sus_tsk.c, itron/src/ter_tsk.c, itron/src/trcv_mbf.c, itron/src/trcv_mbx.c, itron/src/tsnd_mbf.c, itron/src/twai_sem.c, posix/src/cancel.c, posix/src/conddestroy.c, posix/src/condinit.c, posix/src/condsignalsupp.c, posix/src/condwaitsupp.c, posix/src/keydelete.c, posix/src/keygetspecific.c, posix/src/keysetspecific.c, posix/src/mqueueclose.c, posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c, posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c, posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c, posix/src/mutexunlock.c, posix/src/pbarrierdestroy.c, posix/src/pbarrierwait.c, posix/src/prwlockdestroy.c, posix/src/prwlockrdlock.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/prwlocktryrdlock.c, posix/src/prwlocktrywrlock.c, posix/src/prwlockunlock.c, posix/src/prwlockwrlock.c, posix/src/pspindestroy.c, posix/src/pspinlock.c, posix/src/pspintrylock.c, posix/src/pspinunlock.c, posix/src/pthreaddetach.c, posix/src/pthreadequal.c, posix/src/pthreadgetschedparam.c, posix/src/pthreadjoin.c, posix/src/pthreadkill.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/semaphorewaitsupp.c, posix/src/semclose.c, posix/src/semdestroy.c, posix/src/semgetvalue.c, posix/src/sempost.c, posix/src/types.c, rtems/src/barrierdelete.c, rtems/src/barrierrelease.c, rtems/src/barrierwait.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmeminternal2external.c, rtems/src/eventsend.c, rtems/src/eventtimeout.c, rtems/src/msgqbroadcast.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqreceive.c, rtems/src/msgqsend.c, rtems/src/msgqurgent.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partreturnbuffer.c, rtems/src/ratemoncancel.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/signalsend.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskissuspended.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskvariableadd.c, rtems/src/taskvariabledelete.c, rtems/src/taskvariableget.c, rtems/src/timercancel.c, rtems/src/timerdelete.c, rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c, sapi/src/extensiondelete.c, score/include/rtems/score/object.h, score/src/corerwlocktimeout.c, score/src/mpci.c, score/src/objectgetnameasstring.c, score/src/threaddelayended.c, score/src/threadqtimeout.c: When multiprocessing is disabled, do not even allow the constant OBJECTS_REMOTE to appear in the source. Even at -O2, the presence of a case OBJECTS_REMOTE in each id->pointer _Objects_Get switch results in the generation of binary code which can NOT be reached.
  • Property mode set to 100644
File size: 11.0 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#include <rtems/score/cpu.h>
21#include <rtems/score/interr.h>
22#if defined(RTEMS_MULTIPROCESSING)
23#include <rtems/score/mpci.h>
24#include <rtems/score/mppkt.h>
25#endif
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
35/*PAGE
36 *
37 *  _MPCI_Handler_initialization
38 *
39 *  This subprogram performs the initialization necessary for this handler.
40 */
41
42void _MPCI_Handler_initialization(
43  MPCI_Control            *users_mpci_table,
44  uint32_t                 timeout_status
45)
46{
47  CORE_semaphore_Attributes    attributes;
48
49  if ( _System_state_Is_multiprocessing && !users_mpci_table )
50    _Internal_error_Occurred(
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/*PAGE
91 *
92 *  _MPCI_Create_server
93 *
94 *  This subprogram creates the MPCI receive server.
95 */
96
97char *_MPCI_Internal_name = "MPCI";
98
99void _MPCI_Create_server( void )
100{
101
102  if ( !_System_state_Is_multiprocessing )
103    return;
104
105  /*
106   *  Initialize the MPCI Receive Server
107   */
108
109  _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
110
111  _Thread_Initialize(
112    &_Thread_Internal_information,
113    _MPCI_Receive_server_tcb,
114    NULL,        /* allocate the stack */
115    MPCI_RECEIVE_SERVER_STACK_SIZE,
116    CPU_ALL_TASKS_ARE_FP,
117    PRIORITY_MINIMUM,
118    FALSE,       /* no preempt */
119    THREAD_CPU_BUDGET_ALGORITHM_NONE,
120    NULL,        /* no budget algorithm callout */
121    0,           /* all interrupts enabled */
122    _MPCI_Internal_name
123  );
124
125  _Thread_Start(
126    _MPCI_Receive_server_tcb,
127    THREAD_START_NUMERIC,
128    (void *) _MPCI_Receive_server,
129    NULL,
130    0
131  );
132}
133
134/*PAGE
135 *
136 *  _MPCI_Initialization
137 *
138 *  This subprogram initializes the MPCI driver by
139 *  invoking the user provided MPCI initialization callout.
140 */
141
142void _MPCI_Initialization ( void )
143{
144  (*_MPCI_table->initialization)();
145}
146
147/*PAGE
148 *
149 *  _MPCI_Register_packet_processor
150 *
151 *  This routine registers the MPCI packet processor for the
152 *  designated object class.
153 */
154
155void _MPCI_Register_packet_processor(
156  MP_packet_Classes      the_class,
157  MPCI_Packet_processor  the_packet_processor
158
159)
160{
161  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
162}
163
164/*PAGE
165 *
166 *  _MPCI_Get_packet
167 *
168 *  This subprogram obtains a packet by invoking the user provided
169 *  MPCI get packet callout.
170 */
171
172MP_packet_Prefix *_MPCI_Get_packet ( void )
173{
174  MP_packet_Prefix  *the_packet;
175
176  (*_MPCI_table->get_packet)( &the_packet );
177
178  if ( the_packet == NULL )
179    _Internal_error_Occurred(
180      INTERNAL_ERROR_CORE,
181      TRUE,
182      INTERNAL_ERROR_OUT_OF_PACKETS
183    );
184
185  /*
186   *  Put in a default timeout that will be used for
187   *  all packets that do not otherwise have a timeout.
188   */
189
190  the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
191
192  return the_packet;
193}
194
195/*PAGE
196 *
197 *  _MPCI_Return_packet
198 *
199 *  This subprogram returns a packet by invoking the user provided
200 *  MPCI return packet callout.
201 */
202
203void _MPCI_Return_packet (
204  MP_packet_Prefix   *the_packet
205)
206{
207  (*_MPCI_table->return_packet)( the_packet );
208}
209
210/*PAGE
211 *
212 *  _MPCI_Send_process_packet
213 *
214 *  This subprogram sends a process packet by invoking the user provided
215 *  MPCI send callout.
216 */
217
218void _MPCI_Send_process_packet (
219  uint32_t            destination,
220  MP_packet_Prefix   *the_packet
221)
222{
223  the_packet->source_tid = _Thread_Executing->Object.id;
224  the_packet->to_convert =
225     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
226       sizeof(uint32_t  );
227
228  (*_MPCI_table->send_packet)( destination, the_packet );
229}
230
231/*PAGE
232 *
233 *  _MPCI_Send_request_packet
234 *
235 *  This subprogram sends a request packet by invoking the user provided
236 *  MPCI send callout.
237 */
238
239uint32_t   _MPCI_Send_request_packet (
240  uint32_t            destination,
241  MP_packet_Prefix   *the_packet,
242  States_Control      extra_state
243)
244{
245  the_packet->source_tid      = _Thread_Executing->Object.id;
246  the_packet->source_priority = _Thread_Executing->current_priority;
247  the_packet->to_convert =
248     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
249       sizeof(uint32_t  );
250
251  _Thread_Executing->Wait.id = the_packet->id;
252
253  _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads;
254
255  _Thread_Disable_dispatch();
256
257    (*_MPCI_table->send_packet)( destination, the_packet );
258
259    _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads );
260
261    /*
262     *  See if we need a default timeout
263     */
264
265    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
266        the_packet->timeout = _MPCI_table->default_timeout;
267
268    _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout );
269
270    _Thread_Executing->current_state =
271      _States_Set( extra_state, _Thread_Executing->current_state );
272
273  _Thread_Enable_dispatch();
274
275  return _Thread_Executing->Wait.return_code;
276}
277
278/*PAGE
279 *
280 *  _MPCI_Send_response_packet
281 *
282 *  This subprogram sends a response packet by invoking the user provided
283 *  MPCI send callout.
284 */
285
286void _MPCI_Send_response_packet (
287  uint32_t            destination,
288  MP_packet_Prefix   *the_packet
289)
290{
291  the_packet->source_tid = _Thread_Executing->Object.id;
292
293  (*_MPCI_table->send_packet)( destination, the_packet );
294}
295
296/*PAGE
297 *
298 *  _MPCI_Receive_packet
299 *
300 *  This subprogram receives a packet by invoking the user provided
301 *  MPCI receive callout.
302 */
303
304MP_packet_Prefix  *_MPCI_Receive_packet ( void )
305{
306  MP_packet_Prefix  *the_packet;
307
308  (*_MPCI_table->receive_packet)( &the_packet );
309
310  return the_packet;
311}
312
313/*PAGE
314 *
315 *  _MPCI_Process_response
316 *
317 *  This subprogram obtains a packet by invoking the user provided
318 *  MPCI get packet callout.
319 */
320
321Thread_Control *_MPCI_Process_response (
322  MP_packet_Prefix  *the_packet
323)
324{
325  Thread_Control    *the_thread;
326  Objects_Locations  location;
327
328  the_thread = _Thread_Get( the_packet->id, &location );
329  switch ( location ) {
330    case OBJECTS_ERROR:
331#if defined(RTEMS_MULTIPROCESSING)
332    case OBJECTS_REMOTE:
333#endif
334      the_thread = NULL;          /* IMPOSSIBLE */
335      break;
336    case OBJECTS_LOCAL:
337      _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread );
338      the_thread->Wait.return_code = the_packet->return_code;
339      _Thread_Unnest_dispatch();
340    break;
341  }
342
343  return the_thread;
344}
345
346/*PAGE
347 *
348 *  _MPCI_Receive_server
349 *
350 */
351
352Thread _MPCI_Receive_server(
353  uint32_t   ignored
354)
355{
356
357  MP_packet_Prefix         *the_packet;
358  MPCI_Packet_processor     the_function;
359  Thread_Control           *executing;
360
361  executing = _Thread_Executing;
362
363  for ( ; ; ) {
364
365    executing->receive_packet = NULL;
366
367    _Thread_Disable_dispatch();
368    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, TRUE, WATCHDOG_NO_TIMEOUT );
369    _Thread_Enable_dispatch();
370
371    for ( ; ; ) {
372      the_packet = _MPCI_Receive_packet();
373
374      if ( !the_packet )
375        break;
376
377      executing->receive_packet = the_packet;
378
379      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
380        break;
381
382      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
383
384      if ( !the_function )
385        _Internal_error_Occurred(
386          INTERNAL_ERROR_CORE,
387          TRUE,
388          INTERNAL_ERROR_BAD_PACKET
389        );
390
391        (*the_function)( the_packet );
392    }
393  }
394
395  return 0;   /* unreached - only to remove warnings */
396}
397
398/*PAGE
399 *
400 *  _MPCI_Announce
401 *
402 */
403
404void _MPCI_Announce ( void )
405{
406  _Thread_Disable_dispatch();
407  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
408  _Thread_Enable_dispatch();
409}
410
411/*PAGE
412 *
413 *  _MPCI_Internal_packets_Send_process_packet
414 *
415 */
416
417void _MPCI_Internal_packets_Send_process_packet (
418   MPCI_Internal_Remote_operations operation
419)
420{
421  MPCI_Internal_packet *the_packet;
422
423  switch ( operation ) {
424
425    case MPCI_PACKETS_SYSTEM_VERIFY:
426
427      the_packet                    = _MPCI_Internal_packets_Get_packet();
428      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
429      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
430      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
431      the_packet->operation         = operation;
432
433      the_packet->maximum_nodes = _Objects_Maximum_nodes;
434
435      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
436
437      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
438      break;
439  }
440}
441
442/*PAGE
443 *
444 *  _MPCI_Internal_packets_Send_request_packet
445 *
446 *  This subprogram is not needed since there are no request
447 *  packets to be sent by this manager.
448 *
449 */
450
451/*PAGE
452 *
453 *  _MPCI_Internal_packets_Send_response_packet
454 *
455 *  This subprogram is not needed since there are no response
456 *  packets to be sent by this manager.
457 *
458 */
459
460/*PAGE
461 *
462 *
463 *  _MPCI_Internal_packets_Process_packet
464 *
465 */
466
467void _MPCI_Internal_packets_Process_packet (
468  MP_packet_Prefix  *the_packet_prefix
469)
470{
471  MPCI_Internal_packet *the_packet;
472  uint32_t                    maximum_nodes;
473  uint32_t                    maximum_global_objects;
474
475  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
476
477  switch ( the_packet->operation ) {
478
479    case MPCI_PACKETS_SYSTEM_VERIFY:
480
481      maximum_nodes          = the_packet->maximum_nodes;
482      maximum_global_objects = the_packet->maximum_global_objects;
483      if ( maximum_nodes != _Objects_Maximum_nodes ||
484           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
485
486        _MPCI_Return_packet( the_packet_prefix );
487
488        _Internal_error_Occurred(
489          INTERNAL_ERROR_CORE,
490          TRUE,
491          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
492        );
493      }
494
495      _MPCI_Return_packet( the_packet_prefix );
496
497      break;
498  }
499}
500
501/*PAGE
502 *
503 *  _MPCI_Internal_packets_Send_object_was_deleted
504 *
505 *  This subprogram is not needed since there are no objects
506 *  deleted by this manager.
507 *
508 */
509
510/*PAGE
511 *
512 *  _MPCI_Internal_packets_Send_extract_proxy
513 *
514 *  This subprogram is not needed since there are no objects
515 *  deleted by this manager.
516 *
517 */
518
519/*PAGE
520 *
521 *  _MPCI_Internal_packets_Get_packet
522 *
523 */
524
525MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
526{
527  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
528}
529
530/* end of file */
Note: See TracBrowser for help on using the repository browser.