source: rtems/cpukit/score/src/smp.c @ 2cfbf23a

4.115
Last change on this file since 2cfbf23a was 2cfbf23a, checked in by Sebastian Huber <sebastian.huber@…>, on 08/20/13 at 13:07:33

smp: Delete RTEMS_BSP_SMP_SIGNAL_TO_SELF

  • Property mode set to 100644
File size: 3.7 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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/bspsmp.h>
22#include <rtems/score/threaddispatch.h>
23#include <rtems/score/threadimpl.h>
24#include <rtems/score/smp.h>
25#include <rtems/score/sysstate.h>
26
27#if defined(RTEMS_DEBUG)
28  #include <rtems/bspIo.h>
29#endif
30
31void rtems_smp_secondary_cpu_initialize( void )
32{
33  Per_CPU_Control *self_cpu = _Per_CPU_Get();
34  Thread_Control  *heir;
35
36  #if defined(RTEMS_DEBUG)
37    printk( "Made it to %d -- ", _Per_CPU_Get_index( self_cpu ) );
38  #endif
39
40  _Per_CPU_Change_state( self_cpu, PER_CPU_STATE_READY_TO_BEGIN_MULTITASKING );
41
42  _Per_CPU_Wait_for_state( self_cpu, PER_CPU_STATE_BEGIN_MULTITASKING );
43
44  _Thread_Start_multitasking( NULL );
45}
46
47void rtems_smp_process_interrupt( void )
48{
49  Per_CPU_Control *self_cpu = _Per_CPU_Get();
50
51
52  if ( self_cpu->message != 0 ) {
53    uint32_t  message;
54    ISR_Level level;
55
56    _Per_CPU_ISR_disable_and_acquire( self_cpu, level );
57    message = self_cpu->message;
58    self_cpu->message = 0;
59    _Per_CPU_Release_and_ISR_enable( self_cpu, level );
60
61    #if defined(RTEMS_DEBUG)
62      {
63        void *sp = __builtin_frame_address(0);
64        if ( !(message & RTEMS_BSP_SMP_SHUTDOWN) ) {
65          printk(
66            "ISR on CPU %d -- (0x%02x) (0x%p)\n",
67            _Per_CPU_Get_index( self_cpu ),
68            message,
69            sp
70          );
71          if ( message & RTEMS_BSP_SMP_SHUTDOWN )
72            printk( "shutdown\n" );
73        }
74        printk( "Dispatch level %d\n", _Thread_Dispatch_get_disable_level() );
75      }
76    #endif
77
78    if ( ( message & RTEMS_BSP_SMP_SHUTDOWN ) != 0 ) {
79      _ISR_Disable( level );
80
81      _Thread_Dispatch_set_disable_level( 0 );
82
83      _Per_CPU_Change_state( self_cpu, PER_CPU_STATE_SHUTDOWN );
84
85      _CPU_Fatal_halt( _Per_CPU_Get_index( self_cpu ) );
86      /* does not continue past here */
87    }
88  }
89}
90
91void _SMP_Send_message( uint32_t cpu, uint32_t message )
92{
93  Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
94  ISR_Level level;
95
96  _Per_CPU_ISR_disable_and_acquire( per_cpu, level );
97  per_cpu->message |= message;
98  _Per_CPU_Release_and_ISR_enable( per_cpu, level );
99
100  _CPU_SMP_Send_interrupt( cpu );
101}
102
103void _SMP_Broadcast_message( uint32_t message )
104{
105  uint32_t self = _SMP_Get_current_processor();
106  uint32_t ncpus = _SMP_Get_processor_count();
107  uint32_t cpu;
108
109  for ( cpu = 0 ; cpu < ncpus ; ++cpu ) {
110    if ( cpu != self ) {
111      Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
112      ISR_Level level;
113
114      _Per_CPU_ISR_disable_and_acquire( per_cpu, level );
115      per_cpu->message |= message;
116      _Per_CPU_Release_and_ISR_enable( per_cpu, level );
117    }
118  }
119
120  bsp_smp_broadcast_interrupt();
121}
122
123void _SMP_Request_other_cores_to_perform_first_context_switch( void )
124{
125  uint32_t self = _SMP_Get_current_processor();
126  uint32_t ncpus = _SMP_Get_processor_count();
127  uint32_t cpu;
128
129  for ( cpu = 0 ; cpu < ncpus ; ++cpu ) {
130    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
131
132    if ( cpu != self ) {
133      _Per_CPU_Change_state( per_cpu, PER_CPU_STATE_BEGIN_MULTITASKING );
134    }
135  }
136}
137
138void _SMP_Request_other_cores_to_shutdown( void )
139{
140  uint32_t self = _SMP_Get_current_processor();
141  uint32_t ncpus = _SMP_Get_processor_count();
142  uint32_t cpu;
143
144  _SMP_Broadcast_message( RTEMS_BSP_SMP_SHUTDOWN );
145
146  for ( cpu = 0 ; cpu < ncpus ; ++cpu ) {
147    if ( cpu != self ) {
148      _Per_CPU_Wait_for_state(
149        _Per_CPU_Get_by_index( cpu ),
150        PER_CPU_STATE_SHUTDOWN
151      );
152    }
153  }
154}
Note: See TracBrowser for help on using the repository browser.