RTEMS  5.0.0
smpimpl.h
Go to the documentation of this file.
1 
9 /*
10  * COPYRIGHT (c) 1989-2011.
11  * On-Line Applications Research Corporation (OAR).
12  *
13  * The license and distribution terms for this file may be
14  * found in the file LICENSE in this distribution or at
15  * http://www.rtems.org/license/LICENSE.
16  */
17 
18 #ifndef _RTEMS_SCORE_SMPIMPL_H
19 #define _RTEMS_SCORE_SMPIMPL_H
20 
21 #include <rtems/score/smp.h>
22 #include <rtems/score/percpu.h>
24 #include <rtems/fatal.h>
25 #include <rtems/rtems/cache.h>
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
44 #define SMP_MESSAGE_SHUTDOWN 0x1UL
45 
51 #define SMP_MESSAGE_TEST 0x2UL
52 
58 #define SMP_MESSAGE_MULTICAST_ACTION 0x4UL
59 
68 #define SMP_MESSAGE_CLOCK_TICK 0x8UL
69 
73 typedef enum {
74  SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER,
75  SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT,
76  SMP_FATAL_MULTITASKING_START_ON_INVALID_PROCESSOR,
77  SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR,
78  SMP_FATAL_SHUTDOWN,
79  SMP_FATAL_SHUTDOWN_RESPONSE,
80  SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED,
81  SMP_FATAL_SCHEDULER_PIN_OR_UNPIN_NOT_SUPPORTED
83 
84 static inline void _SMP_Fatal( SMP_Fatal_code code )
85 {
87 }
88 
94 #if defined( RTEMS_SMP )
95  void _SMP_Handler_initialize( void );
96 #else
97  #define _SMP_Handler_initialize() \
98  do { } while ( 0 )
99 #endif
100 
101 #if defined( RTEMS_SMP )
102 
111 extern Processor_mask _SMP_Online_processors;
112 
139 void _SMP_Start_multitasking_on_secondary_processor(
140  Per_CPU_Control *cpu_self
142 
143 typedef void ( *SMP_Test_message_handler )( Per_CPU_Control *cpu_self );
144 
145 extern SMP_Test_message_handler _SMP_Test_message_handler;
146 
153 static inline void _SMP_Set_test_message_handler(
154  SMP_Test_message_handler handler
155 )
156 {
157  _SMP_Test_message_handler = handler;
158 }
159 
163 void _SMP_Multicast_actions_process( void );
164 
170 static inline long unsigned _SMP_Inter_processor_interrupt_handler(
171  Per_CPU_Control *cpu_self
172 )
173 {
174  unsigned long message;
175 
176  /*
177  * In the common case the inter-processor interrupt is issued to carry out a
178  * thread dispatch.
179  */
180  cpu_self->dispatch_necessary = true;
181 
182  message = _Atomic_Exchange_ulong(
183  &cpu_self->message,
184  0,
185  ATOMIC_ORDER_ACQUIRE
186  );
187 
188  if ( RTEMS_PREDICT_FALSE( message != 0 ) ) {
189  if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) {
190  _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE );
191  /* does not continue past here */
192  }
193 
194  if ( ( message & SMP_MESSAGE_TEST ) != 0 ) {
195  ( *_SMP_Test_message_handler )( cpu_self );
196  }
197 
198  if ( ( message & SMP_MESSAGE_MULTICAST_ACTION ) != 0 ) {
199  _SMP_Multicast_actions_process();
200  }
201  }
202 
203  return message;
204 }
205 
215 bool _SMP_Should_start_processor( uint32_t cpu_index );
216 
225 void _SMP_Send_message( uint32_t cpu_index, unsigned long message );
226 
232 void _SMP_Send_message_broadcast(
233  unsigned long message
234 );
235 
244 void _SMP_Send_message_multicast(
245  const Processor_mask *targets,
246  unsigned long message
247 );
248 
249 typedef void ( *SMP_Action_handler )( void *arg );
250 
261 void _SMP_Multicast_action(
262  const size_t setsize,
263  const cpu_set_t *cpus,
264  SMP_Action_handler handler,
265  void *arg
266 );
267 
286 bool _SMP_Before_multitasking_action(
287  Per_CPU_Control *cpu,
288  SMP_Action_handler handler,
289  void *arg
290 );
291 
307 bool _SMP_Before_multitasking_action_broadcast(
308  SMP_Action_handler handler,
309  void *arg
310 );
311 
312 #endif /* defined( RTEMS_SMP ) */
313 
318 #if defined( RTEMS_SMP )
319  void _SMP_Request_start_multitasking( void );
320 #else
321  #define _SMP_Request_start_multitasking() \
322  do { } while ( 0 )
323 #endif
324 
332 #if defined( RTEMS_SMP )
333  void _SMP_Request_shutdown( void );
334 #else
335  #define _SMP_Request_shutdown() \
336  do { } while ( 0 )
337 #endif
338 
339 RTEMS_INLINE_ROUTINE const Processor_mask *_SMP_Get_online_processors( void )
340 {
341 #if defined(RTEMS_SMP)
342  return &_SMP_Online_processors;
343 #else
344  return &_Processor_mask_The_one_and_only;
345 #endif
346 }
347 
350 #ifdef __cplusplus
351 }
352 #endif
353 
354 #endif
355 /* end of include file */
SuperCore SMP Support API.
Definition: media-server.c:33
Fatal source of SMP domain.
Definition: interr.h:121
#define RTEMS_PREDICT_FALSE(_exp)
Returns the value of the specified integral expression and tells the compiler that the predicted valu...
Definition: basedefs.h:359
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
#define SMP_MESSAGE_SHUTDOWN
SMP message to request a processor shutdown.
Definition: smpimpl.h:44
#define _SMP_Handler_initialize()
Initialize SMP Handler.
Definition: smpimpl.h:97
void _Terminate(Internal_errors_Source the_source, Internal_errors_t the_error) RTEMS_NO_RETURN
Initiates system termination.
Definition: interr.c:30
Per CPU Core Structure.
Definition: percpu.h:290
#define SMP_MESSAGE_MULTICAST_ACTION
SMP message to request a multicast action.
Definition: smpimpl.h:58
#define _SMP_Request_shutdown()
Requests a shutdown of all processors.
Definition: smpimpl.h:335
#define RTEMS_NO_RETURN
Definition: basedefs.h:101
volatile bool dispatch_necessary
This is set to true when this processor needs to run the thread dispatcher.
Definition: percpu.h:343
Definition: inftrees.h:24
SMP_Fatal_code
SMP fatal codes.
Definition: smpimpl.h:73
#define SMP_MESSAGE_TEST
SMP message to request a test handler invocation.
Definition: smpimpl.h:51
Processor Mask API.
Fatal API.
#define _SMP_Request_start_multitasking()
Requests a multitasking start on all configured and available processors.
Definition: smpimpl.h:321