source: rtems/cpukit/score/src/smp.c @ 58444f7

4.115
Last change on this file since 58444f7 was 58444f7, checked in by Sebastian Huber <sebastian.huber@…>, on 05/06/14 at 13:16:39

score: Delete _SMP_Test_message_default_handler

A default handler is not necessary. The test message sender must ensure
that a handler is installed.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief SMP Support
5 *  @ingroup Score
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
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/smpimpl.h>
22#include <rtems/score/assert.h>
23#include <rtems/score/schedulerimpl.h>
24#include <rtems/score/threaddispatch.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/config.h>
27
28static void _SMP_Start_processors( uint32_t cpu_count )
29{
30  uint32_t cpu_index_self = _SMP_Get_current_processor();
31  uint32_t cpu_index;
32
33
34  for ( cpu_index = 0 ; cpu_index < cpu_count; ++cpu_index ) {
35    const Scheduler_Assignment *assignment =
36      _Scheduler_Get_assignment( cpu_index );
37    Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
38    bool started;
39
40    if ( cpu_index != cpu_index_self ) {
41      if ( _Scheduler_Should_start_processor( assignment ) ) {
42        started = _CPU_SMP_Start_processor( cpu_index );
43
44        if ( !started && _Scheduler_Is_mandatory_processor( assignment ) ) {
45          _SMP_Fatal( SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED );
46        }
47      } else {
48        started = false;
49      }
50    } else {
51      started = true;
52
53      if ( !_Scheduler_Should_start_processor( assignment ) ) {
54        _SMP_Fatal( SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER );
55      }
56    }
57
58    cpu->started = started;
59
60    if ( started ) {
61      ++assignment->scheduler->context->processor_count;
62    }
63  }
64}
65
66void _SMP_Handler_initialize( void )
67{
68  uint32_t cpu_max = rtems_configuration_get_maximum_processors();
69  uint32_t cpu_count;
70  uint32_t cpu_index;
71
72  for ( cpu_index = 0 ; cpu_index < cpu_max; ++cpu_index ) {
73    Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
74
75    _SMP_ticket_lock_Initialize( &cpu->Lock, "per-CPU" );
76  }
77
78  /*
79   * Discover and initialize the secondary cores in an SMP system.
80   */
81
82  cpu_count = _CPU_SMP_Initialize();
83  cpu_count = cpu_count < cpu_max ? cpu_count : cpu_max;
84  _SMP_Processor_count = cpu_count;
85
86  for ( cpu_index = cpu_count ; cpu_index < cpu_max; ++cpu_index ) {
87    const Scheduler_Assignment *assignment =
88      _Scheduler_Get_assignment( cpu_index );
89
90    if ( _Scheduler_Is_mandatory_processor( assignment ) ) {
91      _SMP_Fatal( SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT );
92    }
93  }
94
95  _SMP_Start_processors( cpu_count );
96
97  _CPU_SMP_Finalize_initialization( cpu_count );
98}
99
100void _SMP_Request_start_multitasking( void )
101{
102  Per_CPU_Control *self_cpu = _Per_CPU_Get();
103  uint32_t cpu_count = _SMP_Get_processor_count();
104  uint32_t cpu_index;
105
106  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_READY_TO_START_MULTITASKING );
107
108  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
109    Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
110
111    _Per_CPU_State_change( cpu, PER_CPU_STATE_REQUEST_START_MULTITASKING );
112  }
113}
114
115void _SMP_Start_multitasking_on_secondary_processor( void )
116{
117  Per_CPU_Control *self_cpu = _Per_CPU_Get();
118
119  if ( !_Per_CPU_Is_processor_started( self_cpu ) ) {
120    _SMP_Fatal( SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR );
121  }
122
123  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_READY_TO_START_MULTITASKING );
124
125  _Thread_Start_multitasking();
126}
127
128void _SMP_Request_shutdown( void )
129{
130  Per_CPU_Control *self_cpu = _Per_CPU_Get();
131
132  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_SHUTDOWN );
133
134  /*
135   * We have to drop the Giant lock here in order to give other processors the
136   * opportunity to receive the inter-processor interrupts issued previously.
137   * In case the executing thread still holds SMP locks, then other processors
138   * already waiting for this SMP lock will spin forever.
139   */
140  _Giant_Drop( self_cpu );
141}
142
143void _SMP_Send_message( uint32_t cpu_index, unsigned long message )
144{
145  Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index );
146
147  _Atomic_Fetch_or_ulong( &cpu->message, message, ATOMIC_ORDER_RELAXED );
148
149  _CPU_SMP_Send_interrupt( cpu_index );
150}
151
152void _SMP_Broadcast_message( uint32_t message )
153{
154  uint32_t cpu_count = _SMP_Get_processor_count();
155  uint32_t cpu_index_self = _SMP_Get_current_processor();
156  uint32_t cpu_index;
157
158  _Assert( _Debug_Is_thread_dispatching_allowed() );
159
160  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
161    if ( cpu_index != cpu_index_self ) {
162      _SMP_Send_message( cpu_index, message );
163    }
164  }
165}
166
167SMP_Test_message_handler _SMP_Test_message_handler;
Note: See TracBrowser for help on using the repository browser.