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

4.115
Last change on this file since bf54252 was bf54252, checked in by Alexandre Devienne <deviennealexandre@…>, on 11/28/12 at 20:14:50

Score misc: Clean up Doxygen #4 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/7985215

  • 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-2008.
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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#if defined(RTEMS_MULTIPROCESSING)
23#include <rtems/score/mpci.h>
24#include <rtems/score/mppkt.h>
25#endif
26#include <rtems/config.h>
27#include <rtems/score/cpu.h>
28#include <rtems/score/interr.h>
29#include <rtems/score/states.h>
30#include <rtems/score/thread.h>
31#include <rtems/score/threadq.h>
32#include <rtems/score/tqdata.h>
33#include <rtems/score/watchdog.h>
34#include <rtems/score/sysstate.h>
35
36#include <rtems/score/coresem.h>
37#include <rtems/config.h>
38
39RTEMS_STATIC_ASSERT(
40  sizeof(MPCI_Internal_packet) <= MP_PACKET_MINIMUM_PACKET_SIZE,
41  MPCI_Internal_packet
42);
43
44/**
45 *  This is the core semaphore which the MPCI Receive Server blocks on.
46 */
47CORE_semaphore_Control _MPCI_Semaphore;
48
49void _MPCI_Handler_initialization(
50  uint32_t   timeout_status
51)
52{
53  CORE_semaphore_Attributes   attributes;
54  MPCI_Control               *users_mpci_table;
55
56  users_mpci_table = _Configuration_MP_table->User_mpci_table;
57
58  if ( _System_state_Is_multiprocessing && !users_mpci_table )
59    _Internal_error_Occurred(
60      INTERNAL_ERROR_CORE,
61      true,
62      INTERNAL_ERROR_NO_MPCI
63    );
64
65  _MPCI_table = users_mpci_table;
66
67  if ( !_System_state_Is_multiprocessing )
68    return;
69
70  /*
71   *  Register the MP Process Packet routine.
72   */
73
74  _MPCI_Register_packet_processor(
75    MP_PACKET_MPCI_INTERNAL,
76    _MPCI_Internal_packets_Process_packet
77  );
78
79  /*
80   *  Create the counting semaphore used by the MPCI Receive Server.
81   */
82
83  attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
84
85  _CORE_semaphore_Initialize(
86    &_MPCI_Semaphore,
87    &attributes,              /* the_semaphore_attributes */
88    0                         /* initial_value */
89  );
90
91  _Thread_queue_Initialize(
92    &_MPCI_Remote_blocked_threads,
93    THREAD_QUEUE_DISCIPLINE_FIFO,
94    STATES_WAITING_FOR_RPC_REPLY,
95    timeout_status
96  );
97}
98
99void _MPCI_Create_server( void )
100{
101  Objects_Name name;
102
103
104  if ( !_System_state_Is_multiprocessing )
105    return;
106
107  /*
108   *  Initialize the MPCI Receive Server
109   */
110
111  _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
112
113  name.name_u32 = _Objects_Build_name( 'M', 'P', 'C', 'I' );
114  _Thread_Initialize(
115    &_Thread_Internal_information,
116    _MPCI_Receive_server_tcb,
117    NULL,        /* allocate the stack */
118    _Stack_Minimum() +
119      CPU_MPCI_RECEIVE_SERVER_EXTRA_STACK +
120      _Configuration_MP_table->extra_mpci_receive_server_stack,
121    CPU_ALL_TASKS_ARE_FP,
122    PRIORITY_MINIMUM,
123    false,       /* no preempt */
124    THREAD_CPU_BUDGET_ALGORITHM_NONE,
125    NULL,        /* no budget algorithm callout */
126    0,           /* all interrupts enabled */
127    name
128  );
129
130  _Thread_Start(
131    _MPCI_Receive_server_tcb,
132    THREAD_START_NUMERIC,
133    (void *) _MPCI_Receive_server,
134    NULL,
135    0
136  );
137}
138
139void _MPCI_Initialization ( void )
140{
141  (*_MPCI_table->initialization)();
142}
143
144void _MPCI_Register_packet_processor(
145  MP_packet_Classes      the_class,
146  MPCI_Packet_processor  the_packet_processor
147
148)
149{
150  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
151}
152
153MP_packet_Prefix *_MPCI_Get_packet ( void )
154{
155  MP_packet_Prefix  *the_packet;
156
157  (*_MPCI_table->get_packet)( &the_packet );
158
159  if ( the_packet == NULL )
160    _Internal_error_Occurred(
161      INTERNAL_ERROR_CORE,
162      true,
163      INTERNAL_ERROR_OUT_OF_PACKETS
164    );
165
166  /*
167   *  Put in a default timeout that will be used for
168   *  all packets that do not otherwise have a timeout.
169   */
170
171  the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
172
173  return the_packet;
174}
175
176void _MPCI_Return_packet (
177  MP_packet_Prefix   *the_packet
178)
179{
180  (*_MPCI_table->return_packet)( the_packet );
181}
182
183void _MPCI_Send_process_packet (
184  uint32_t            destination,
185  MP_packet_Prefix   *the_packet
186)
187{
188  the_packet->source_tid = _Thread_Executing->Object.id;
189  the_packet->to_convert =
190     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
191
192  (*_MPCI_table->send_packet)( destination, the_packet );
193}
194
195uint32_t   _MPCI_Send_request_packet (
196  uint32_t            destination,
197  MP_packet_Prefix   *the_packet,
198  States_Control      extra_state
199)
200{
201  the_packet->source_tid      = _Thread_Executing->Object.id;
202  the_packet->source_priority = _Thread_Executing->current_priority;
203  the_packet->to_convert =
204     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
205
206  _Thread_Executing->Wait.id = the_packet->id;
207
208  _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads;
209
210  _Thread_Disable_dispatch();
211
212    (*_MPCI_table->send_packet)( destination, the_packet );
213
214    _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads );
215
216    /*
217     *  See if we need a default timeout
218     */
219
220    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
221        the_packet->timeout = _MPCI_table->default_timeout;
222
223    _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout );
224
225    _Thread_Executing->current_state =
226      _States_Set( extra_state, _Thread_Executing->current_state );
227
228  _Thread_Enable_dispatch();
229
230  return _Thread_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      _Thread_Unnest_dispatch();
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_Executing;
292
293  for ( ; ; ) {
294
295    executing->receive_packet = NULL;
296
297    _Thread_Disable_dispatch();
298    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, true, WATCHDOG_NO_TIMEOUT );
299    _Thread_Enable_dispatch();
300
301    for ( ; ; ) {
302      the_packet = _MPCI_Receive_packet();
303
304      if ( !the_packet )
305        break;
306
307      executing->receive_packet = the_packet;
308
309      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
310        break;
311
312      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
313
314      if ( !the_function )
315        _Internal_error_Occurred(
316          INTERNAL_ERROR_CORE,
317          true,
318          INTERNAL_ERROR_BAD_PACKET
319        );
320
321        (*the_function)( the_packet );
322    }
323  }
324
325  return 0;   /* unreached - only to remove warnings */
326}
327
328void _MPCI_Announce ( void )
329{
330  _Thread_Disable_dispatch();
331  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
332  _Thread_Enable_dispatch();
333}
334
335void _MPCI_Internal_packets_Send_process_packet (
336   MPCI_Internal_Remote_operations operation
337)
338{
339  MPCI_Internal_packet *the_packet;
340
341  switch ( operation ) {
342
343    case MPCI_PACKETS_SYSTEM_VERIFY:
344
345      the_packet                    = _MPCI_Internal_packets_Get_packet();
346      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
347      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
348      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
349      the_packet->operation         = operation;
350
351      the_packet->maximum_nodes = _Objects_Maximum_nodes;
352
353      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
354
355      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
356      break;
357  }
358}
359
360/*
361 *  _MPCI_Internal_packets_Send_request_packet
362 *
363 *  This subprogram is not needed since there are no request
364 *  packets to be sent by this manager.
365 *
366 */
367
368/*
369 *  _MPCI_Internal_packets_Send_response_packet
370 *
371 *  This subprogram is not needed since there are no response
372 *  packets to be sent by this manager.
373 *
374 */
375
376void _MPCI_Internal_packets_Process_packet (
377  MP_packet_Prefix  *the_packet_prefix
378)
379{
380  MPCI_Internal_packet *the_packet;
381  uint32_t                    maximum_nodes;
382  uint32_t                    maximum_global_objects;
383
384  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
385
386  switch ( the_packet->operation ) {
387
388    case MPCI_PACKETS_SYSTEM_VERIFY:
389
390      maximum_nodes          = the_packet->maximum_nodes;
391      maximum_global_objects = the_packet->maximum_global_objects;
392      if ( maximum_nodes != _Objects_Maximum_nodes ||
393           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
394
395        _MPCI_Return_packet( the_packet_prefix );
396
397        _Internal_error_Occurred(
398          INTERNAL_ERROR_CORE,
399          true,
400          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
401        );
402      }
403
404      _MPCI_Return_packet( the_packet_prefix );
405
406      break;
407  }
408}
409
410/*
411 *  _MPCI_Internal_packets_Send_object_was_deleted
412 *
413 *  This subprogram is not needed since there are no objects
414 *  deleted by this manager.
415 *
416 */
417
418/*
419 *  _MPCI_Internal_packets_Send_extract_proxy
420 *
421 *  This subprogram is not needed since there are no objects
422 *  deleted by this manager.
423 *
424 */
425
426MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
427{
428  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
429}
430
431/* end of file */
Note: See TracBrowser for help on using the repository browser.