source: rtems/cpukit/score/src/smp.c @ d7c3883

4.115
Last change on this file since d7c3883 was d7c3883, checked in by Jennifer Averett <Jennifer.Averett@…>, on 04/21/11 at 19:05:15

2011-04-21 Jennifer Averett <Jennifer.Averett@…

PR 1777/cpukit

  • libcsupport/src/malloc_deferred.c, libcsupport/src/realloc.c, score/Makefile.am, score/cpu/lm32/irq.c, score/cpu/nios2/irq.c, score/include/rtems/score/coremutex.h, score/include/rtems/score/thread.h, score/inline/rtems/score/thread.inl, score/src/heapfree.c, score/src/pheapwalk.c, score/src/smp.c, score/src/threaddispatch.c: Consolidated access to _Thread_Dispatch_disable_level.
  • score/src/threaddisabledispatch.c, score/src/threadenabledispatch.c: New files.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems/system.h>
17#include <rtems/bspsmp.h>
18#include <rtems/score/thread.h>
19
20#if defined(RTEMS_SMP)
21#define SMP_DEBUG
22
23#if defined(SMP_DEBUG)
24  #include <rtems/bspIo.h>
25#endif
26
27void rtems_smp_run_first_task(int cpu)
28{
29  Thread_Control *heir;
30
31  /*
32   *  This CPU has an heir thread so we need to dispatch it.
33   */
34  heir = _Thread_Heir;
35
36  /*
37   *  This is definitely a hack until we have SMP scheduling.  Since there
38   *  is only one executing and heir right now, we have to fake this out.
39   */
40  _Thread_Dispatch_set_disable_level(1);
41  _Thread_Executing = heir;
42  _CPU_Context_switch_to_first_task_smp( &heir->Registers );
43}
44
45void rtems_smp_secondary_cpu_initialize(void)
46{
47  int cpu;
48
49  cpu = bsp_smp_processor_id();
50
51  bsp_smp_secondary_cpu_initialize(cpu);
52
53  #if defined(SMP_DEBUG)
54    printk( "Made it to %d -- ", cpu );
55  #endif
56
57  /*
58   *  Inform the primary CPU that this secondary CPU is initialized
59   *  and ready to dispatch to the first thread it is supposed to
60   *  execute when the primary CPU is ready.
61   */
62  _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
63
64  /*
65   *  HACK: Should not have to enable interrupts in real system here.
66   *        It should happen as part of switching to the first task.
67   */
68   
69  _Per_CPU_Information[cpu].isr_nest_level = 1;
70  _ISR_Set_level( 0 );
71  while(1) ;
72}
73
74void rtems_smp_process_interrupt(void)
75{
76  int        cpu;
77  uint32_t   message;
78  ISR_Level  level;
79
80  cpu = bsp_smp_processor_id();
81
82  level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
83    message = _Per_CPU_Information[cpu].message;
84    _Per_CPU_Information[cpu].message &= ~message;
85  _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
86
87  #if defined(SMP_DEBUG)
88    {
89      void *sp = __builtin_frame_address(0);
90      if ( !(message & RTEMS_BSP_SMP_SHUTDOWN) )
91        printk( "ISR on CPU %d -- (0x%02x) (0x%p)\n", cpu, message, sp );
92      printk( "Dispatch level %d\n", _Thread_Dispatch_disable_level );
93    }
94  #endif
95
96  if ( message & RTEMS_BSP_SMP_FIRST_TASK ) {
97    _Per_CPU_Information[cpu].isr_nest_level = 0;
98    _Per_CPU_Information[cpu].message = 0;
99    _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
100    rtems_smp_run_first_task(cpu);
101    /* does not return */
102  }
103
104  if ( message & RTEMS_BSP_SMP_SHUTDOWN ) {
105    ISR_Level level;
106    _Thread_Dispatch_set_disable_level(0);
107    _Per_CPU_Information[cpu].isr_nest_level = 0;
108    _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_SHUTDOWN;
109    _ISR_Disable( level );
110    while(1)
111      ;
112    /* does not continue past here */
113  }
114
115  if ( message & RTEMS_BSP_SMP_CONTEXT_SWITCH_NECESSARY ) {
116    printk( "switch needed\n" );
117    _Per_CPU_Information[cpu].dispatch_necessary = true;
118  }
119}
120
121void rtems_smp_send_message(
122  int       cpu,
123  uint32_t  message
124)
125{
126  ISR_Level level;
127
128  level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
129    _Per_CPU_Information[cpu].message |= message;
130  _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
131  bsp_smp_interrupt_cpu( cpu );
132}
133
134void rtems_smp_broadcast_message(
135  uint32_t  message
136)
137{
138  int        dest_cpu;
139  int        cpu;
140  ISR_Level  level;
141
142  cpu = bsp_smp_processor_id();
143
144  for ( dest_cpu=0 ; dest_cpu <  _SMP_Processor_count; dest_cpu++ ) {
145    if ( cpu == dest_cpu )
146      continue;
147    level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
148      _Per_CPU_Information[dest_cpu].message |= message;
149    _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
150  }
151  bsp_smp_broadcast_interrupt();
152}
153#endif
Note: See TracBrowser for help on using the repository browser.