source: rtems/cpukit/score/src/mpci.c @ 8ca372e

Last change on this file since 8ca372e was 8ca372e, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 26, 2016 at 9:11:48 AM

Use linker set for MPCI initialization

Update #2408.

  • Property mode set to 100644
File size: 11.5 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/objectmp.h>
25#include <rtems/score/stackimpl.h>
26#include <rtems/score/sysstate.h>
27#include <rtems/score/schedulerimpl.h>
28#include <rtems/score/threadimpl.h>
29#include <rtems/score/threadqimpl.h>
30#include <rtems/config.h>
31#include <rtems/sysinit.h>
32
33RTEMS_STATIC_ASSERT(
34  sizeof(MPCI_Internal_packet) <= MP_PACKET_MINIMUM_PACKET_SIZE,
35  MPCI_Internal_packet
36);
37
38rtems_multiprocessing_table *_Configuration_MP_table;
39
40const rtems_multiprocessing_table
41 _Initialization_Default_multiprocessing_table = {
42  1,                        /* local node number */
43  1,                        /* maximum number nodes in system */
44  0,                        /* maximum number global objects */
45  0,                        /* maximum number proxies */
46  STACK_MINIMUM_SIZE,       /* MPCI receive server stack size */
47  NULL                      /* pointer to MPCI address table */
48};
49
50/**
51 *  This is the core semaphore which the MPCI Receive Server blocks on.
52 */
53CORE_semaphore_Control _MPCI_Semaphore;
54
55static void _MPCI_Handler_early_initialization( void )
56{
57  /*
58   *  Initialize the system state based on whether this is an MP system.
59   *  In an MP configuration, internally we view single processor
60   *  systems as a very restricted multiprocessor system.
61   */
62  _Configuration_MP_table = rtems_configuration_get_user_multiprocessing_table();
63
64  if ( _Configuration_MP_table == NULL ) {
65    _Configuration_MP_table = RTEMS_DECONST(
66      rtems_multiprocessing_table *,
67      &_Initialization_Default_multiprocessing_table
68    );
69  } else {
70    _System_state_Is_multiprocessing = true;
71  }
72
73  _Objects_MP_Handler_early_initialization();
74}
75
76static void _MPCI_Handler_initialization( void )
77{
78  CORE_semaphore_Attributes   attributes;
79  MPCI_Control               *users_mpci_table;
80
81  _Objects_MP_Handler_initialization();
82
83  users_mpci_table = _Configuration_MP_table->User_mpci_table;
84
85  if ( _System_state_Is_multiprocessing && !users_mpci_table )
86    _Terminate(
87      INTERNAL_ERROR_CORE,
88      true,
89      INTERNAL_ERROR_NO_MPCI
90    );
91
92  _MPCI_table = users_mpci_table;
93
94  if ( !_System_state_Is_multiprocessing )
95    return;
96
97  /*
98   *  Register the MP Process Packet routine.
99   */
100
101  _MPCI_Register_packet_processor(
102    MP_PACKET_MPCI_INTERNAL,
103    _MPCI_Internal_packets_Process_packet
104  );
105
106  /*
107   *  Create the counting semaphore used by the MPCI Receive Server.
108   */
109
110  attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
111
112  _CORE_semaphore_Initialize(
113    &_MPCI_Semaphore,
114    &attributes,              /* the_semaphore_attributes */
115    0                         /* initial_value */
116  );
117
118  _Thread_queue_Initialize(
119    &_MPCI_Remote_blocked_threads,
120    THREAD_QUEUE_DISCIPLINE_FIFO
121  );
122}
123
124static void _MPCI_Create_server( void )
125{
126  Thread_Entry_information entry = {
127    .adaptor = _Thread_Entry_adaptor_numeric,
128    .Kinds = {
129      .Numeric = {
130        .entry = _MPCI_Receive_server
131      }
132    }
133  };
134  Objects_Name name;
135
136
137  if ( !_System_state_Is_multiprocessing )
138    return;
139
140  /*
141   *  Initialize the MPCI Receive Server
142   */
143
144  _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
145
146  name.name_u32 = _Objects_Build_name( 'M', 'P', 'C', 'I' );
147  _Thread_Initialize(
148    &_Thread_Internal_information,
149    _MPCI_Receive_server_tcb,
150    _Scheduler_Get_by_CPU_index( _SMP_Get_current_processor() ),
151    NULL,        /* allocate the stack */
152    _Stack_Minimum() +
153      CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK +
154      _Configuration_MP_table->extra_mpci_receive_server_stack,
155    CPU_ALL_TASKS_ARE_FP,
156    PRIORITY_PSEUDO_ISR,
157    false,       /* no preempt */
158    THREAD_CPU_BUDGET_ALGORITHM_NONE,
159    NULL,        /* no budget algorithm callout */
160    0,           /* all interrupts enabled */
161    name
162  );
163
164  _Thread_Start( _MPCI_Receive_server_tcb, &entry );
165}
166
167static void _MPCI_Initialization( void )
168{
169  (*_MPCI_table->initialization)();
170}
171
172void _MPCI_Register_packet_processor(
173  MP_packet_Classes      the_class,
174  MPCI_Packet_processor  the_packet_processor
175
176)
177{
178  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
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    _Terminate(
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
204void _MPCI_Return_packet (
205  MP_packet_Prefix   *the_packet
206)
207{
208  (*_MPCI_table->return_packet)( the_packet );
209}
210
211void _MPCI_Send_process_packet (
212  uint32_t            destination,
213  MP_packet_Prefix   *the_packet
214)
215{
216  the_packet->source_tid = _Thread_Executing->Object.id;
217  the_packet->to_convert =
218     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
219
220  (*_MPCI_table->send_packet)( destination, the_packet );
221}
222
223uint32_t   _MPCI_Send_request_packet (
224  uint32_t            destination,
225  MP_packet_Prefix   *the_packet,
226  States_Control      extra_state,
227  uint32_t            timeout_code
228)
229{
230  Thread_Control *executing = _Thread_Executing;
231
232  the_packet->source_tid      = executing->Object.id;
233  the_packet->source_priority = executing->current_priority;
234  the_packet->to_convert =
235     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
236
237  executing->Wait.id = the_packet->id;
238
239  _Thread_Disable_dispatch();
240
241    (*_MPCI_table->send_packet)( destination, the_packet );
242
243    /*
244     *  See if we need a default timeout
245     */
246
247    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
248        the_packet->timeout = _MPCI_table->default_timeout;
249
250    _Thread_queue_Enqueue(
251      &_MPCI_Remote_blocked_threads,
252      executing,
253      STATES_WAITING_FOR_RPC_REPLY | extra_state,
254      the_packet->timeout,
255      timeout_code
256    );
257
258  _Thread_Enable_dispatch();
259
260  return executing->Wait.return_code;
261}
262
263void _MPCI_Send_response_packet (
264  uint32_t            destination,
265  MP_packet_Prefix   *the_packet
266)
267{
268  the_packet->source_tid = _Thread_Executing->Object.id;
269
270  (*_MPCI_table->send_packet)( destination, the_packet );
271}
272
273MP_packet_Prefix  *_MPCI_Receive_packet ( void )
274{
275  MP_packet_Prefix  *the_packet;
276
277  (*_MPCI_table->receive_packet)( &the_packet );
278
279  return the_packet;
280}
281
282Thread_Control *_MPCI_Process_response (
283  MP_packet_Prefix  *the_packet
284)
285{
286  Thread_Control    *the_thread;
287  Objects_Locations  location;
288
289  the_thread = _Thread_Get( the_packet->id, &location );
290  switch ( location ) {
291    case OBJECTS_ERROR:
292#if defined(RTEMS_MULTIPROCESSING)
293    case OBJECTS_REMOTE:
294#endif
295      the_thread = NULL;          /* IMPOSSIBLE */
296      break;
297    case OBJECTS_LOCAL:
298      _Thread_queue_Extract( the_thread );
299      the_thread->Wait.return_code = the_packet->return_code;
300      _Objects_Put_without_thread_dispatch( &the_thread->Object );
301    break;
302  }
303
304  return the_thread;
305}
306
307/*
308 *  _MPCI_Receive_server
309 *
310 */
311
312void _MPCI_Receive_server(
313  Thread_Entry_numeric_type ignored
314)
315{
316
317  MP_packet_Prefix         *the_packet;
318  MPCI_Packet_processor     the_function;
319  Thread_Control           *executing;
320  ISR_lock_Context          lock_context;
321
322  executing = _Thread_Get_executing();
323
324  for ( ; ; ) {
325
326    executing->receive_packet = NULL;
327
328    _ISR_lock_ISR_disable( &lock_context );
329    _CORE_semaphore_Seize(
330      &_MPCI_Semaphore,
331      executing,
332      0,
333      true,
334      WATCHDOG_NO_TIMEOUT,
335      &lock_context
336    );
337
338    for ( ; ; ) {
339      the_packet = _MPCI_Receive_packet();
340
341      if ( !the_packet )
342        break;
343
344      executing->receive_packet = the_packet;
345
346      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
347        break;
348
349      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
350
351      if ( !the_function )
352        _Terminate(
353          INTERNAL_ERROR_CORE,
354          true,
355          INTERNAL_ERROR_BAD_PACKET
356        );
357
358       (*the_function)( the_packet );
359    }
360  }
361}
362
363void _MPCI_Announce ( void )
364{
365  ISR_lock_Context lock_context;
366
367  _ISR_lock_ISR_disable( &lock_context );
368  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0, &lock_context );
369}
370
371void _MPCI_Internal_packets_Send_process_packet (
372   MPCI_Internal_Remote_operations operation
373)
374{
375  MPCI_Internal_packet *the_packet;
376
377  switch ( operation ) {
378
379    case MPCI_PACKETS_SYSTEM_VERIFY:
380
381      the_packet                    = _MPCI_Internal_packets_Get_packet();
382      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
383      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
384      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
385      the_packet->operation         = operation;
386
387      the_packet->maximum_nodes = _Objects_Maximum_nodes;
388
389      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
390
391      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
392      break;
393  }
394}
395
396/*
397 *  _MPCI_Internal_packets_Send_request_packet
398 *
399 *  This subprogram is not needed since there are no request
400 *  packets to be sent by this manager.
401 *
402 */
403
404/*
405 *  _MPCI_Internal_packets_Send_response_packet
406 *
407 *  This subprogram is not needed since there are no response
408 *  packets to be sent by this manager.
409 *
410 */
411
412void _MPCI_Internal_packets_Process_packet (
413  MP_packet_Prefix  *the_packet_prefix
414)
415{
416  MPCI_Internal_packet *the_packet;
417  uint32_t                    maximum_nodes;
418  uint32_t                    maximum_global_objects;
419
420  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
421
422  switch ( the_packet->operation ) {
423
424    case MPCI_PACKETS_SYSTEM_VERIFY:
425
426      maximum_nodes          = the_packet->maximum_nodes;
427      maximum_global_objects = the_packet->maximum_global_objects;
428      if ( maximum_nodes != _Objects_Maximum_nodes ||
429           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
430
431        _MPCI_Return_packet( the_packet_prefix );
432
433        _Terminate(
434          INTERNAL_ERROR_CORE,
435          true,
436          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
437        );
438      }
439
440      _MPCI_Return_packet( the_packet_prefix );
441
442      break;
443  }
444}
445
446/*
447 *  _MPCI_Internal_packets_Send_object_was_deleted
448 *
449 *  This subprogram is not needed since there are no objects
450 *  deleted by this manager.
451 *
452 */
453
454/*
455 *  _MPCI_Internal_packets_Send_extract_proxy
456 *
457 *  This subprogram is not needed since there are no objects
458 *  deleted by this manager.
459 *
460 */
461
462MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
463{
464  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
465}
466
467static void _MPCI_Finalize( void )
468{
469  if ( _System_state_Is_multiprocessing ) {
470    _MPCI_Initialization();
471    _MPCI_Internal_packets_Send_process_packet( MPCI_PACKETS_SYSTEM_VERIFY );
472  }
473}
474
475RTEMS_SYSINIT_ITEM(
476  _MPCI_Handler_early_initialization,
477  RTEMS_SYSINIT_MP_EARLY,
478  RTEMS_SYSINIT_ORDER_MIDDLE
479);
480
481RTEMS_SYSINIT_ITEM(
482  _MPCI_Handler_initialization,
483  RTEMS_SYSINIT_MP,
484  RTEMS_SYSINIT_ORDER_MIDDLE
485);
486
487RTEMS_SYSINIT_ITEM(
488  _MPCI_Create_server,
489  RTEMS_SYSINIT_MP_SERVER,
490  RTEMS_SYSINIT_ORDER_MIDDLE
491);
492
493RTEMS_SYSINIT_ITEM(
494  _MPCI_Finalize,
495  RTEMS_SYSINIT_MP_FINALIZE,
496  RTEMS_SYSINIT_ORDER_MIDDLE
497);
498
499/* end of file */
Note: See TracBrowser for help on using the repository browser.