source: rtems/cpukit/score/include/rtems/score/smpimpl.h @ 3dfe55ee

Last change on this file since 3dfe55ee was 3dfe55ee, checked in by Sebastian Huber <sebastian.huber@…>, on Jul 3, 2017 at 9:46:12 AM

score: Use <sys/bitset.h> for Processor_mask

Implement the Processor_mask via <sys/bitset.h>. Provide
_Processor_mask_To_uint32_t() to enable its use in device specific
routines, e.g. interrupt affinity register in an interrupt controller.

Update #3059.

  • Property mode set to 100644
File size: 8.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSMPImpl
5 *
6 * @brief SuperCore SMP Implementation
7 */
8
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>
23#include <rtems/score/processormask.h>
24#include <rtems/fatal.h>
25#include <rtems/rtems/cache.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @defgroup ScoreSMP SMP Support
33 *
34 * @ingroup Score
35 *
36 * This defines the interface of the SuperCore SMP support.
37 *
38 * @{
39 */
40
41/**
42 * @brief SMP message to request a processor shutdown.
43 *
44 * @see _SMP_Send_message().
45 */
46#define SMP_MESSAGE_SHUTDOWN 0x1UL
47
48/**
49 * @brief SMP message to request a test handler invocation.
50 *
51 * @see _SMP_Send_message().
52 */
53#define SMP_MESSAGE_TEST 0x2UL
54
55/**
56 * @brief SMP message to request a multicast action.
57 *
58 * @see _SMP_Send_message().
59 */
60#define SMP_MESSAGE_MULTICAST_ACTION 0x4UL
61
62/**
63 * @brief SMP message to request a clock tick.
64 *
65 * This message is provided for systems without a proper interrupt affinity
66 * support and may be used by the clock driver.
67 *
68 * @see _SMP_Send_message().
69 */
70#define SMP_MESSAGE_CLOCK_TICK 0x8UL
71
72/**
73 * @brief SMP fatal codes.
74 */
75typedef enum {
76  SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER,
77  SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT,
78  SMP_FATAL_MULTITASKING_START_ON_INVALID_PROCESSOR,
79  SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR,
80  SMP_FATAL_SHUTDOWN,
81  SMP_FATAL_SHUTDOWN_RESPONSE,
82  SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED
83} SMP_Fatal_code;
84
85static inline void _SMP_Fatal( SMP_Fatal_code code )
86{
87  _Terminate( RTEMS_FATAL_SOURCE_SMP, code );
88}
89
90/**
91 *  @brief Initialize SMP Handler
92 *
93 *  This method initialize the SMP Handler.
94 */
95#if defined( RTEMS_SMP )
96  void _SMP_Handler_initialize( void );
97#else
98  #define _SMP_Handler_initialize() \
99    do { } while ( 0 )
100#endif
101
102#if defined( RTEMS_SMP )
103
104/**
105 * @brief Set of online processors.
106 *
107 * A processor is online if was started during system initialization.  In this
108 * case its corresponding bit in the mask is set.
109 *
110 * @see _SMP_Handler_initialize().
111 */
112extern Processor_mask _SMP_Online_processors;
113
114/**
115 * @brief Performs high-level initialization of a secondary processor and runs
116 * the application threads.
117 *
118 * The low-level initialization code must call this function to hand over the
119 * control of this processor to RTEMS.  Interrupts must be disabled.  It must
120 * be possible to send inter-processor interrupts to this processor.  Since
121 * interrupts are disabled the inter-processor interrupt delivery is postponed
122 * until interrupts are enabled the first time.  Interrupts are enabled during
123 * the execution begin of threads in case they have interrupt level zero (this
124 * is the default).
125 *
126 * The pre-requisites for the call to this function are
127 * - disabled interrupts,
128 * - delivery of inter-processor interrupts is possible,
129 * - a valid stack pointer and enough stack space,
130 * - a valid code memory, and
131 * - a valid BSS section.
132 *
133 * This function must not be called by the main processor.  The main processor
134 * uses _Thread_Start_multitasking() instead.
135 *
136 * This function does not return to the caller.
137 */
138void _SMP_Start_multitasking_on_secondary_processor( void )
139  RTEMS_NO_RETURN;
140
141typedef void ( *SMP_Test_message_handler )( Per_CPU_Control *cpu_self );
142
143extern SMP_Test_message_handler _SMP_Test_message_handler;
144
145/**
146 * @brief Sets the handler for test messages.
147 *
148 * This handler can be used to test the inter-processor interrupt
149 * implementation.
150 */
151static inline void _SMP_Set_test_message_handler(
152  SMP_Test_message_handler handler
153)
154{
155  _SMP_Test_message_handler = handler;
156}
157
158/**
159 * @brief Processes all pending multicast actions.
160 */
161void _SMP_Multicast_actions_process( void );
162
163/**
164 * @brief Interrupt handler for inter-processor interrupts.
165 *
166 * @return The received message.
167 */
168static inline long unsigned _SMP_Inter_processor_interrupt_handler( void )
169{
170  Per_CPU_Control *cpu_self;
171  unsigned long    message;
172
173  cpu_self = _Per_CPU_Get();
174
175  /*
176   * In the common case the inter-processor interrupt is issued to carry out a
177   * thread dispatch.
178   */
179  cpu_self->dispatch_necessary = true;
180
181  message = _Atomic_Exchange_ulong(
182    &cpu_self->message,
183    0,
184    ATOMIC_ORDER_ACQUIRE
185  );
186
187  if ( message != 0 ) {
188    if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) {
189      _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE );
190      /* does not continue past here */
191    }
192
193    if ( ( message & SMP_MESSAGE_TEST ) != 0 ) {
194      ( *_SMP_Test_message_handler )( cpu_self );
195    }
196
197    if ( ( message & SMP_MESSAGE_MULTICAST_ACTION ) != 0 ) {
198      _SMP_Multicast_actions_process();
199    }
200  }
201
202  return message;
203}
204
205/**
206 *  @brief Returns true, if the processor with the specified index should be
207 *  started.
208 *
209 *  @param[in] cpu_index The processor index.
210 *
211 *  @retval true The processor should be started.
212 *  @retval false Otherwise.
213 */
214bool _SMP_Should_start_processor( uint32_t cpu_index );
215
216/**
217 *  @brief Sends an SMP message to a processor.
218 *
219 *  The target processor may be the sending processor.
220 *
221 *  @param[in] cpu_index The target processor of the message.
222 *  @param[in] message The message.
223 */
224void _SMP_Send_message( uint32_t cpu_index, unsigned long message );
225
226/**
227 *  @brief Sends an SMP message to all other online processors.
228 *
229 *  @param[in] message The message.
230 */
231void _SMP_Send_message_broadcast(
232  unsigned long message
233);
234
235/**
236 *  @brief Sends an SMP message to a set of processors.
237 *
238 *  The sending processor may be part of the set.
239 *
240 *  @param[in] targets The set of processors to send the message.
241 *  @param[in] message The message.
242 */
243void _SMP_Send_message_multicast(
244  const Processor_mask *targets,
245  unsigned long         message
246);
247
248typedef void ( *SMP_Action_handler )( void *arg );
249
250/**
251 *  @brief Initiates an SMP multicast action to a set of processors.
252 *
253 *  The current processor may be part of the set.
254 *
255 *  @param[in] setsize The size of the set of target processors of the message.
256 *  @param[in] cpus The set of target processors of the message.
257 *  @param[in] handler The multicast action handler.
258 *  @param[in] arg The multicast action argument.
259 */
260void _SMP_Multicast_action(
261  const size_t setsize,
262  const cpu_set_t *cpus,
263  SMP_Action_handler handler,
264  void *arg
265);
266
267/**
268 * @brief Executes a handler with argument on the specified processor on behalf
269 * of the boot processor.
270 *
271 * The calling processor must be the boot processor.  In case the specified
272 * processor is not online or not in the
273 * PER_CPU_STATE_READY_TO_START_MULTITASKING state, then no action is
274 * performed.
275 *
276 * @param cpu The processor to execute the action.
277 * @param handler The handler of the action.
278 * @param arg The argument of the action.
279 *
280 * @retval true The handler executed on the specified processor.
281 * @retval false Otherwise.
282 *
283 * @see _SMP_Before_multitasking_action_broadcast().
284 */
285bool _SMP_Before_multitasking_action(
286  Per_CPU_Control    *cpu,
287  SMP_Action_handler  handler,
288  void               *arg
289);
290
291/**
292 * @brief Executes a handler with argument on all online processors except the
293 * boot processor on behalf of the boot processor.
294 *
295 * The calling processor must be the boot processor.
296 *
297 * @param handler The handler of the action.
298 * @param arg The argument of the action.
299 *
300 * @retval true The handler executed on all online processors except the boot
301 * processor.
302 * @retval false Otherwise.
303 *
304 * @see _SMP_Before_multitasking_action().
305 */
306bool _SMP_Before_multitasking_action_broadcast(
307  SMP_Action_handler  handler,
308  void               *arg
309);
310
311#endif /* defined( RTEMS_SMP ) */
312
313/**
314 * @brief Requests a multitasking start on all configured and available
315 * processors.
316 */
317#if defined( RTEMS_SMP )
318  void _SMP_Request_start_multitasking( void );
319#else
320  #define _SMP_Request_start_multitasking() \
321    do { } while ( 0 )
322#endif
323
324/**
325 * @brief Requests a shutdown of all processors.
326 *
327 * This function is a part of the system termination procedure.
328 *
329 * @see _Terminate().
330 */
331#if defined( RTEMS_SMP )
332  void _SMP_Request_shutdown( void );
333#else
334  #define _SMP_Request_shutdown() \
335    do { } while ( 0 )
336#endif
337
338/** @} */
339
340#ifdef __cplusplus
341}
342#endif
343
344#endif
345/* end of include file */
Note: See TracBrowser for help on using the repository browser.