source: rtems/cpukit/score/src/smp.c @ 439c494

4.115
Last change on this file since 439c494 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.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.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/threaddispatch.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/config.h>
26
27void _SMP_Handler_initialize( void )
28{
29  uint32_t max_cpus = rtems_configuration_get_maximum_processors();
30  uint32_t cpu;
31
32  for ( cpu = 0 ; cpu < max_cpus; ++cpu ) {
33    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
34
35    _SMP_ticket_lock_Initialize( &per_cpu->Lock, "per-CPU" );
36  }
37
38  /*
39   * Discover and initialize the secondary cores in an SMP system.
40   */
41  max_cpus = _CPU_SMP_Initialize( max_cpus );
42
43  _SMP_Processor_count = max_cpus;
44}
45
46void _SMP_Request_start_multitasking( void )
47{
48  Per_CPU_Control *self_cpu = _Per_CPU_Get();
49  uint32_t ncpus = _SMP_Get_processor_count();
50  uint32_t cpu;
51
52  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_READY_TO_START_MULTITASKING );
53
54  for ( cpu = 0 ; cpu < ncpus ; ++cpu ) {
55    Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
56
57    _Per_CPU_State_change( per_cpu, PER_CPU_STATE_REQUEST_START_MULTITASKING );
58  }
59}
60
61void _SMP_Start_multitasking_on_secondary_processor( void )
62{
63  Per_CPU_Control *self_cpu = _Per_CPU_Get();
64
65  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_READY_TO_START_MULTITASKING );
66
67  _Thread_Start_multitasking();
68}
69
70void _SMP_Request_shutdown( void )
71{
72  Per_CPU_Control *self_cpu = _Per_CPU_Get();
73
74  _Per_CPU_State_change( self_cpu, PER_CPU_STATE_SHUTDOWN );
75
76  /*
77   * We have to drop the Giant lock here in order to give other processors the
78   * opportunity to receive the inter-processor interrupts issued previously.
79   * In case the executing thread still holds SMP locks, then other processors
80   * already waiting for this SMP lock will spin forever.
81   */
82  _Giant_Drop( self_cpu );
83}
84
85void _SMP_Send_message( uint32_t cpu, uint32_t message )
86{
87  Per_CPU_Control *per_cpu = _Per_CPU_Get_by_index( cpu );
88  ISR_Level level;
89
90  _Per_CPU_ISR_disable_and_acquire( per_cpu, level );
91  per_cpu->message |= message;
92  _Per_CPU_Release_and_ISR_enable( per_cpu, level );
93
94  _CPU_SMP_Send_interrupt( cpu );
95}
96
97void _SMP_Broadcast_message( uint32_t message )
98{
99  uint32_t self = _SMP_Get_current_processor();
100  uint32_t ncpus = _SMP_Get_processor_count();
101  uint32_t cpu;
102
103  _Assert( _Debug_Is_thread_dispatching_allowed() );
104
105  for ( cpu = 0 ; cpu < ncpus ; ++cpu ) {
106    if ( cpu != self ) {
107      _SMP_Send_message( cpu, message );
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.