source: rtems/cpukit/score/src/mpci.c @ 25f5730f

4.11
Last change on this file since 25f5730f was 1ed8762e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 21, 2014 at 6:08:38 PM

mpci.c: Now compiles again

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