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

Last change on this file since addb600 was addb600, checked in by Sebastian Huber <sebastian.huber@…>, on Jan 26, 2016 at 9:29:28 AM

mpci: Fix warning

Assignment is superfluous due to later call to _Thread_queue_Enqueue().

  • 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  _Thread_Disable_dispatch();
205
206    (*_MPCI_table->send_packet)( destination, the_packet );
207
208    /*
209     *  See if we need a default timeout
210     */
211
212    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
213        the_packet->timeout = _MPCI_table->default_timeout;
214
215    _Thread_queue_Enqueue(
216      &_MPCI_Remote_blocked_threads,
217      executing,
218      STATES_WAITING_FOR_RPC_REPLY | extra_state,
219      the_packet->timeout,
220      timeout_code
221    );
222
223  _Thread_Enable_dispatch();
224
225  return executing->Wait.return_code;
226}
227
228void _MPCI_Send_response_packet (
229  uint32_t            destination,
230  MP_packet_Prefix   *the_packet
231)
232{
233  the_packet->source_tid = _Thread_Executing->Object.id;
234
235  (*_MPCI_table->send_packet)( destination, the_packet );
236}
237
238MP_packet_Prefix  *_MPCI_Receive_packet ( void )
239{
240  MP_packet_Prefix  *the_packet;
241
242  (*_MPCI_table->receive_packet)( &the_packet );
243
244  return the_packet;
245}
246
247Thread_Control *_MPCI_Process_response (
248  MP_packet_Prefix  *the_packet
249)
250{
251  Thread_Control    *the_thread;
252  Objects_Locations  location;
253
254  the_thread = _Thread_Get( the_packet->id, &location );
255  switch ( location ) {
256    case OBJECTS_ERROR:
257#if defined(RTEMS_MULTIPROCESSING)
258    case OBJECTS_REMOTE:
259#endif
260      the_thread = NULL;          /* IMPOSSIBLE */
261      break;
262    case OBJECTS_LOCAL:
263      _Thread_queue_Extract( the_thread );
264      the_thread->Wait.return_code = the_packet->return_code;
265      _Objects_Put_without_thread_dispatch( &the_thread->Object );
266    break;
267  }
268
269  return the_thread;
270}
271
272/*
273 *  _MPCI_Receive_server
274 *
275 */
276
277void _MPCI_Receive_server(
278  Thread_Entry_numeric_type ignored
279)
280{
281
282  MP_packet_Prefix         *the_packet;
283  MPCI_Packet_processor     the_function;
284  Thread_Control           *executing;
285  ISR_lock_Context          lock_context;
286
287  executing = _Thread_Get_executing();
288
289  for ( ; ; ) {
290
291    executing->receive_packet = NULL;
292
293    _ISR_lock_ISR_disable( &lock_context );
294    _CORE_semaphore_Seize(
295      &_MPCI_Semaphore,
296      executing,
297      0,
298      true,
299      WATCHDOG_NO_TIMEOUT,
300      &lock_context
301    );
302
303    for ( ; ; ) {
304      the_packet = _MPCI_Receive_packet();
305
306      if ( !the_packet )
307        break;
308
309      executing->receive_packet = the_packet;
310
311      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
312        break;
313
314      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
315
316      if ( !the_function )
317        _Terminate(
318          INTERNAL_ERROR_CORE,
319          true,
320          INTERNAL_ERROR_BAD_PACKET
321        );
322
323       (*the_function)( the_packet );
324    }
325  }
326}
327
328void _MPCI_Announce ( void )
329{
330  ISR_lock_Context lock_context;
331
332  _ISR_lock_ISR_disable( &lock_context );
333  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0, &lock_context );
334}
335
336void _MPCI_Internal_packets_Send_process_packet (
337   MPCI_Internal_Remote_operations operation
338)
339{
340  MPCI_Internal_packet *the_packet;
341
342  switch ( operation ) {
343
344    case MPCI_PACKETS_SYSTEM_VERIFY:
345
346      the_packet                    = _MPCI_Internal_packets_Get_packet();
347      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
348      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
349      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
350      the_packet->operation         = operation;
351
352      the_packet->maximum_nodes = _Objects_Maximum_nodes;
353
354      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
355
356      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
357      break;
358  }
359}
360
361/*
362 *  _MPCI_Internal_packets_Send_request_packet
363 *
364 *  This subprogram is not needed since there are no request
365 *  packets to be sent by this manager.
366 *
367 */
368
369/*
370 *  _MPCI_Internal_packets_Send_response_packet
371 *
372 *  This subprogram is not needed since there are no response
373 *  packets to be sent by this manager.
374 *
375 */
376
377void _MPCI_Internal_packets_Process_packet (
378  MP_packet_Prefix  *the_packet_prefix
379)
380{
381  MPCI_Internal_packet *the_packet;
382  uint32_t                    maximum_nodes;
383  uint32_t                    maximum_global_objects;
384
385  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
386
387  switch ( the_packet->operation ) {
388
389    case MPCI_PACKETS_SYSTEM_VERIFY:
390
391      maximum_nodes          = the_packet->maximum_nodes;
392      maximum_global_objects = the_packet->maximum_global_objects;
393      if ( maximum_nodes != _Objects_Maximum_nodes ||
394           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
395
396        _MPCI_Return_packet( the_packet_prefix );
397
398        _Terminate(
399          INTERNAL_ERROR_CORE,
400          true,
401          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
402        );
403      }
404
405      _MPCI_Return_packet( the_packet_prefix );
406
407      break;
408  }
409}
410
411/*
412 *  _MPCI_Internal_packets_Send_object_was_deleted
413 *
414 *  This subprogram is not needed since there are no objects
415 *  deleted by this manager.
416 *
417 */
418
419/*
420 *  _MPCI_Internal_packets_Send_extract_proxy
421 *
422 *  This subprogram is not needed since there are no objects
423 *  deleted by this manager.
424 *
425 */
426
427MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
428{
429  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
430}
431
432/* end of file */
Note: See TracBrowser for help on using the repository browser.