source: rtems/cpukit/score/src/mpci.c @ 885c342e

5
Last change on this file since 885c342e was 885c342e, checked in by Sebastian Huber <sebastian.huber@…>, on 01/26/16 at 09:23:22

mpci: Update due to API changes

Update due to API changes introduced by
ccd54344d904b657123e4e4ba795a32212382be2.

Update #2514.

  • Property mode set to 100644
File size: 9.7 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  );
87}
88
89void _MPCI_Create_server( void )
90{
91  Thread_Entry_information entry = {
92    .adaptor = _Thread_Entry_adaptor_numeric,
93    .Kinds = {
94      .Numeric = {
95        .entry = _MPCI_Receive_server
96      }
97    }
98  };
99  Objects_Name name;
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  name.name_u32 = _Objects_Build_name( 'M', 'P', 'C', 'I' );
112  _Thread_Initialize(
113    &_Thread_Internal_information,
114    _MPCI_Receive_server_tcb,
115    _Scheduler_Get_by_CPU_index( _SMP_Get_current_processor() ),
116    NULL,        /* allocate the stack */
117    _Stack_Minimum() +
118      CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK +
119      _Configuration_MP_table->extra_mpci_receive_server_stack,
120    CPU_ALL_TASKS_ARE_FP,
121    PRIORITY_PSEUDO_ISR,
122    false,       /* no preempt */
123    THREAD_CPU_BUDGET_ALGORITHM_NONE,
124    NULL,        /* no budget algorithm callout */
125    0,           /* all interrupts enabled */
126    name
127  );
128
129  _Thread_Start( _MPCI_Receive_server_tcb, &entry );
130}
131
132void _MPCI_Initialization ( void )
133{
134  (*_MPCI_table->initialization)();
135}
136
137void _MPCI_Register_packet_processor(
138  MP_packet_Classes      the_class,
139  MPCI_Packet_processor  the_packet_processor
140
141)
142{
143  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
144}
145
146MP_packet_Prefix *_MPCI_Get_packet ( void )
147{
148  MP_packet_Prefix  *the_packet;
149
150  (*_MPCI_table->get_packet)( &the_packet );
151
152  if ( the_packet == NULL )
153    _Terminate(
154      INTERNAL_ERROR_CORE,
155      true,
156      INTERNAL_ERROR_OUT_OF_PACKETS
157    );
158
159  /*
160   *  Put in a default timeout that will be used for
161   *  all packets that do not otherwise have a timeout.
162   */
163
164  the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
165
166  return the_packet;
167}
168
169void _MPCI_Return_packet (
170  MP_packet_Prefix   *the_packet
171)
172{
173  (*_MPCI_table->return_packet)( the_packet );
174}
175
176void _MPCI_Send_process_packet (
177  uint32_t            destination,
178  MP_packet_Prefix   *the_packet
179)
180{
181  the_packet->source_tid = _Thread_Executing->Object.id;
182  the_packet->to_convert =
183     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
184
185  (*_MPCI_table->send_packet)( destination, the_packet );
186}
187
188uint32_t   _MPCI_Send_request_packet (
189  uint32_t            destination,
190  MP_packet_Prefix   *the_packet,
191  States_Control      extra_state,
192  uint32_t            timeout_code
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    /*
211     *  See if we need a default timeout
212     */
213
214    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
215        the_packet->timeout = _MPCI_table->default_timeout;
216
217    _Thread_queue_Enqueue(
218      &_MPCI_Remote_blocked_threads,
219      executing,
220      STATES_WAITING_FOR_RPC_REPLY | extra_state,
221      the_packet->timeout,
222      timeout_code
223    );
224
225  _Thread_Enable_dispatch();
226
227  return executing->Wait.return_code;
228}
229
230void _MPCI_Send_response_packet (
231  uint32_t            destination,
232  MP_packet_Prefix   *the_packet
233)
234{
235  the_packet->source_tid = _Thread_Executing->Object.id;
236
237  (*_MPCI_table->send_packet)( destination, the_packet );
238}
239
240MP_packet_Prefix  *_MPCI_Receive_packet ( void )
241{
242  MP_packet_Prefix  *the_packet;
243
244  (*_MPCI_table->receive_packet)( &the_packet );
245
246  return the_packet;
247}
248
249Thread_Control *_MPCI_Process_response (
250  MP_packet_Prefix  *the_packet
251)
252{
253  Thread_Control    *the_thread;
254  Objects_Locations  location;
255
256  the_thread = _Thread_Get( the_packet->id, &location );
257  switch ( location ) {
258    case OBJECTS_ERROR:
259#if defined(RTEMS_MULTIPROCESSING)
260    case OBJECTS_REMOTE:
261#endif
262      the_thread = NULL;          /* IMPOSSIBLE */
263      break;
264    case OBJECTS_LOCAL:
265      _Thread_queue_Extract( the_thread );
266      the_thread->Wait.return_code = the_packet->return_code;
267      _Objects_Put_without_thread_dispatch( &the_thread->Object );
268    break;
269  }
270
271  return the_thread;
272}
273
274/*
275 *  _MPCI_Receive_server
276 *
277 */
278
279void _MPCI_Receive_server(
280  Thread_Entry_numeric_type ignored
281)
282{
283
284  MP_packet_Prefix         *the_packet;
285  MPCI_Packet_processor     the_function;
286  Thread_Control           *executing;
287  ISR_lock_Context          lock_context;
288
289  executing = _Thread_Get_executing();
290
291  for ( ; ; ) {
292
293    executing->receive_packet = NULL;
294
295    _ISR_lock_ISR_disable( &lock_context );
296    _CORE_semaphore_Seize(
297      &_MPCI_Semaphore,
298      executing,
299      0,
300      true,
301      WATCHDOG_NO_TIMEOUT,
302      &lock_context
303    );
304
305    for ( ; ; ) {
306      the_packet = _MPCI_Receive_packet();
307
308      if ( !the_packet )
309        break;
310
311      executing->receive_packet = the_packet;
312
313      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
314        break;
315
316      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
317
318      if ( !the_function )
319        _Terminate(
320          INTERNAL_ERROR_CORE,
321          true,
322          INTERNAL_ERROR_BAD_PACKET
323        );
324
325       (*the_function)( the_packet );
326    }
327  }
328}
329
330void _MPCI_Announce ( void )
331{
332  ISR_lock_Context lock_context;
333
334  _ISR_lock_ISR_disable( &lock_context );
335  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0, &lock_context );
336}
337
338void _MPCI_Internal_packets_Send_process_packet (
339   MPCI_Internal_Remote_operations operation
340)
341{
342  MPCI_Internal_packet *the_packet;
343
344  switch ( operation ) {
345
346    case MPCI_PACKETS_SYSTEM_VERIFY:
347
348      the_packet                    = _MPCI_Internal_packets_Get_packet();
349      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
350      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
351      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
352      the_packet->operation         = operation;
353
354      the_packet->maximum_nodes = _Objects_Maximum_nodes;
355
356      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
357
358      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
359      break;
360  }
361}
362
363/*
364 *  _MPCI_Internal_packets_Send_request_packet
365 *
366 *  This subprogram is not needed since there are no request
367 *  packets to be sent by this manager.
368 *
369 */
370
371/*
372 *  _MPCI_Internal_packets_Send_response_packet
373 *
374 *  This subprogram is not needed since there are no response
375 *  packets to be sent by this manager.
376 *
377 */
378
379void _MPCI_Internal_packets_Process_packet (
380  MP_packet_Prefix  *the_packet_prefix
381)
382{
383  MPCI_Internal_packet *the_packet;
384  uint32_t                    maximum_nodes;
385  uint32_t                    maximum_global_objects;
386
387  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
388
389  switch ( the_packet->operation ) {
390
391    case MPCI_PACKETS_SYSTEM_VERIFY:
392
393      maximum_nodes          = the_packet->maximum_nodes;
394      maximum_global_objects = the_packet->maximum_global_objects;
395      if ( maximum_nodes != _Objects_Maximum_nodes ||
396           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
397
398        _MPCI_Return_packet( the_packet_prefix );
399
400        _Terminate(
401          INTERNAL_ERROR_CORE,
402          true,
403          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
404        );
405      }
406
407      _MPCI_Return_packet( the_packet_prefix );
408
409      break;
410  }
411}
412
413/*
414 *  _MPCI_Internal_packets_Send_object_was_deleted
415 *
416 *  This subprogram is not needed since there are no objects
417 *  deleted by this manager.
418 *
419 */
420
421/*
422 *  _MPCI_Internal_packets_Send_extract_proxy
423 *
424 *  This subprogram is not needed since there are no objects
425 *  deleted by this manager.
426 *
427 */
428
429MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
430{
431  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
432}
433
434/* end of file */
Note: See TracBrowser for help on using the repository browser.