source: rtems/cpukit/score/src/mpci.c @ a5b6cdd

4.104.114.95
Last change on this file since a5b6cdd was a5b6cdd, checked in by Joel Sherrill <joel.sherrill@…>, on 09/08/08 at 15:19:34

2008-09-08 Joel Sherrill <joel.sherrill@…>

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