source: rtems/cpukit/include/rtems/score/smpimpl.h @ d8bc0730

5
Last change on this file since d8bc0730 was 5677883, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/18 at 07:09:06

score: _SMP_Inter_processor_interrupt_handler()

Optimize _SMP_Inter_processor_interrupt_handler() for the common case in
which the inter-processor interrupt is only used to trigger a thread
dispatch.

  • Property mode set to 100644
File size: 8.6 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 *
138 * @param[in] cpu_self The current processor control.
139 */
140void _SMP_Start_multitasking_on_secondary_processor(
141  Per_CPU_Control *cpu_self
142) RTEMS_NO_RETURN;
143
144typedef void ( *SMP_Test_message_handler )( Per_CPU_Control *cpu_self );
145
146extern SMP_Test_message_handler _SMP_Test_message_handler;
147
148/**
149 * @brief Sets the handler for test messages.
150 *
151 * This handler can be used to test the inter-processor interrupt
152 * implementation.
153 */
154static inline void _SMP_Set_test_message_handler(
155  SMP_Test_message_handler handler
156)
157{
158  _SMP_Test_message_handler = handler;
159}
160
161/**
162 * @brief Processes all pending multicast actions.
163 */
164void _SMP_Multicast_actions_process( void );
165
166/**
167 * @brief Interrupt handler for inter-processor interrupts.
168 *
169 * @return The received message.
170 */
171static inline long unsigned _SMP_Inter_processor_interrupt_handler(
172  Per_CPU_Control *cpu_self
173)
174{
175  unsigned long message;
176
177  /*
178   * In the common case the inter-processor interrupt is issued to carry out a
179   * thread dispatch.
180   */
181  cpu_self->dispatch_necessary = true;
182
183  message = _Atomic_Exchange_ulong(
184    &cpu_self->message,
185    0,
186    ATOMIC_ORDER_ACQUIRE
187  );
188
189  if ( RTEMS_PREDICT_FALSE( message != 0 ) ) {
190    if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) {
191      _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE );
192      /* does not continue past here */
193    }
194
195    if ( ( message & SMP_MESSAGE_TEST ) != 0 ) {
196      ( *_SMP_Test_message_handler )( cpu_self );
197    }
198
199    if ( ( message & SMP_MESSAGE_MULTICAST_ACTION ) != 0 ) {
200      _SMP_Multicast_actions_process();
201    }
202  }
203
204  return message;
205}
206
207/**
208 *  @brief Returns true, if the processor with the specified index should be
209 *  started.
210 *
211 *  @param[in] cpu_index The processor index.
212 *
213 *  @retval true The processor should be started.
214 *  @retval false Otherwise.
215 */
216bool _SMP_Should_start_processor( uint32_t cpu_index );
217
218/**
219 *  @brief Sends an SMP message to a processor.
220 *
221 *  The target processor may be the sending processor.
222 *
223 *  @param[in] cpu_index The target processor of the message.
224 *  @param[in] message The message.
225 */
226void _SMP_Send_message( uint32_t cpu_index, unsigned long message );
227
228/**
229 *  @brief Sends an SMP message to all other online processors.
230 *
231 *  @param[in] message The message.
232 */
233void _SMP_Send_message_broadcast(
234  unsigned long message
235);
236
237/**
238 *  @brief Sends an SMP message to a set of processors.
239 *
240 *  The sending processor may be part of the set.
241 *
242 *  @param[in] targets The set of processors to send the message.
243 *  @param[in] message The message.
244 */
245void _SMP_Send_message_multicast(
246  const Processor_mask *targets,
247  unsigned long         message
248);
249
250typedef void ( *SMP_Action_handler )( void *arg );
251
252/**
253 *  @brief Initiates an SMP multicast action to a set of processors.
254 *
255 *  The current processor may be part of the set.
256 *
257 *  @param[in] setsize The size of the set of target processors of the message.
258 *  @param[in] cpus The set of target processors of the message.
259 *  @param[in] handler The multicast action handler.
260 *  @param[in] arg The multicast action argument.
261 */
262void _SMP_Multicast_action(
263  const size_t setsize,
264  const cpu_set_t *cpus,
265  SMP_Action_handler handler,
266  void *arg
267);
268
269/**
270 * @brief Executes a handler with argument on the specified processor on behalf
271 * of the boot processor.
272 *
273 * The calling processor must be the boot processor.  In case the specified
274 * processor is not online or not in the
275 * PER_CPU_STATE_READY_TO_START_MULTITASKING state, then no action is
276 * performed.
277 *
278 * @param cpu The processor to execute the action.
279 * @param handler The handler of the action.
280 * @param arg The argument of the action.
281 *
282 * @retval true The handler executed on the specified processor.
283 * @retval false Otherwise.
284 *
285 * @see _SMP_Before_multitasking_action_broadcast().
286 */
287bool _SMP_Before_multitasking_action(
288  Per_CPU_Control    *cpu,
289  SMP_Action_handler  handler,
290  void               *arg
291);
292
293/**
294 * @brief Executes a handler with argument on all online processors except the
295 * boot processor on behalf of the boot processor.
296 *
297 * The calling processor must be the boot processor.
298 *
299 * @param handler The handler of the action.
300 * @param arg The argument of the action.
301 *
302 * @retval true The handler executed on all online processors except the boot
303 * processor.
304 * @retval false Otherwise.
305 *
306 * @see _SMP_Before_multitasking_action().
307 */
308bool _SMP_Before_multitasking_action_broadcast(
309  SMP_Action_handler  handler,
310  void               *arg
311);
312
313#endif /* defined( RTEMS_SMP ) */
314
315/**
316 * @brief Requests a multitasking start on all configured and available
317 * processors.
318 */
319#if defined( RTEMS_SMP )
320  void _SMP_Request_start_multitasking( void );
321#else
322  #define _SMP_Request_start_multitasking() \
323    do { } while ( 0 )
324#endif
325
326/**
327 * @brief Requests a shutdown of all processors.
328 *
329 * This function is a part of the system termination procedure.
330 *
331 * @see _Terminate().
332 */
333#if defined( RTEMS_SMP )
334  void _SMP_Request_shutdown( void );
335#else
336  #define _SMP_Request_shutdown() \
337    do { } while ( 0 )
338#endif
339
340RTEMS_INLINE_ROUTINE const Processor_mask *_SMP_Get_online_processors( void )
341{
342#if defined(RTEMS_SMP)
343  return &_SMP_Online_processors;
344#else
345  return &_Processor_mask_The_one_and_only;
346#endif
347}
348
349/** @} */
350
351#ifdef __cplusplus
352}
353#endif
354
355#endif
356/* end of include file */
Note: See TracBrowser for help on using the repository browser.