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

4.104.114.84.95
Last change on this file since a29d2e7 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 11.0 KB
Line 
1/*
2 *  Multiprocessing Communications Interface (MPCI) Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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    case OBJECTS_REMOTE:
332      the_thread = NULL;          /* IMPOSSIBLE */
333      break;
334    case OBJECTS_LOCAL:
335      _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread );
336      the_thread->Wait.return_code = the_packet->return_code;
337      _Thread_Unnest_dispatch();
338    break;
339  }
340
341  return the_thread;
342}
343
344/*PAGE
345 *
346 *  _MPCI_Receive_server
347 *
348 */
349
350Thread _MPCI_Receive_server(
351  uint32_t   ignored
352)
353{
354
355  MP_packet_Prefix         *the_packet;
356  MPCI_Packet_processor     the_function;
357  Thread_Control           *executing;
358
359  executing = _Thread_Executing;
360
361  for ( ; ; ) {
362
363    executing->receive_packet = NULL;
364
365    _Thread_Disable_dispatch();
366    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, TRUE, WATCHDOG_NO_TIMEOUT );
367    _Thread_Enable_dispatch();
368
369    for ( ; ; ) {
370      the_packet = _MPCI_Receive_packet();
371
372      if ( !the_packet )
373        break;
374
375      executing->receive_packet = the_packet;
376
377      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
378        break;
379
380      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
381
382      if ( !the_function )
383        _Internal_error_Occurred(
384          INTERNAL_ERROR_CORE,
385          TRUE,
386          INTERNAL_ERROR_BAD_PACKET
387        );
388
389        (*the_function)( the_packet );
390    }
391  }
392
393  return 0;   /* unreached - only to remove warnings */
394}
395
396/*PAGE
397 *
398 *  _MPCI_Announce
399 *
400 */
401
402void _MPCI_Announce ( void )
403{
404  _Thread_Disable_dispatch();
405  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
406  _Thread_Enable_dispatch();
407}
408
409/*PAGE
410 *
411 *  _MPCI_Internal_packets_Send_process_packet
412 *
413 */
414
415void _MPCI_Internal_packets_Send_process_packet (
416   MPCI_Internal_Remote_operations operation
417)
418{
419  MPCI_Internal_packet *the_packet;
420
421  switch ( operation ) {
422
423    case MPCI_PACKETS_SYSTEM_VERIFY:
424
425      the_packet                    = _MPCI_Internal_packets_Get_packet();
426      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
427      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
428      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
429      the_packet->operation         = operation;
430
431      the_packet->maximum_nodes = _Objects_Maximum_nodes;
432
433      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
434
435      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
436      break;
437  }
438}
439
440/*PAGE
441 *
442 *  _MPCI_Internal_packets_Send_request_packet
443 *
444 *  This subprogram is not needed since there are no request
445 *  packets to be sent by this manager.
446 *
447 */
448
449/*PAGE
450 *
451 *  _MPCI_Internal_packets_Send_response_packet
452 *
453 *  This subprogram is not needed since there are no response
454 *  packets to be sent by this manager.
455 *
456 */
457
458/*PAGE
459 *
460 *
461 *  _MPCI_Internal_packets_Process_packet
462 *
463 */
464
465void _MPCI_Internal_packets_Process_packet (
466  MP_packet_Prefix  *the_packet_prefix
467)
468{
469  MPCI_Internal_packet *the_packet;
470  uint32_t                    maximum_nodes;
471  uint32_t                    maximum_global_objects;
472
473  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
474
475  switch ( the_packet->operation ) {
476
477    case MPCI_PACKETS_SYSTEM_VERIFY:
478
479      maximum_nodes          = the_packet->maximum_nodes;
480      maximum_global_objects = the_packet->maximum_global_objects;
481      if ( maximum_nodes != _Objects_Maximum_nodes ||
482           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
483
484        _MPCI_Return_packet( the_packet_prefix );
485
486        _Internal_error_Occurred(
487          INTERNAL_ERROR_CORE,
488          TRUE,
489          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
490        );
491      }
492
493      _MPCI_Return_packet( the_packet_prefix );
494
495      break;
496  }
497}
498
499/*PAGE
500 *
501 *  _MPCI_Internal_packets_Send_object_was_deleted
502 *
503 *  This subprogram is not needed since there are no objects
504 *  deleted by this manager.
505 *
506 */
507
508/*PAGE
509 *
510 *  _MPCI_Internal_packets_Send_extract_proxy
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_Get_packet
520 *
521 */
522
523MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
524{
525  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
526}
527
528/* end of file */
Note: See TracBrowser for help on using the repository browser.