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

4.115
Last change on this file since cfa5aab was cfa5aab, checked in by Sebastian Huber <sebastian.huber@…>, on 05/02/15 at 12:02:20

score: Delete _CORE_semaphore_Seize()

Rename _CORE_semaphore_Seize_isr_disable() to _CORE_semaphore_Seize().

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