summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-16 20:05:06 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2011-03-16 20:05:06 +0000
commit06dcaf09e6c0eae0b3a3c8d84adb663d03a53a4b (patch)
tree931cf314d5a87d1d3dcd6e5c366b5ce58270a6aa /cpukit/score/src
parent2011-03-16 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-06dcaf09e6c0eae0b3a3c8d84adb663d03a53a4b.tar.bz2
2011-03-16 Jennifer Averett <jennifer.averett@OARcorp.com>
PR 1729/cpukit * configure.ac, sapi/include/confdefs.h, sapi/src/exinit.c, score/Makefile.am, score/preinstall.am, score/cpu/i386/rtems/score/cpu.h, score/cpu/sparc/cpu_asm.S, score/cpu/sparc/rtems/score/cpu.h, score/include/rtems/score/basedefs.h, score/include/rtems/score/context.h, score/include/rtems/score/percpu.h, score/src/percpu.c, score/src/thread.c, score/src/threadcreateidle.c: Add next step in SMP support. This adds an allocated array of the Per_CPU structures to support multiple cpus vs a single instance of the structure which is still used if SMP support is disabled. Configuration support is also added to explicitly enable or disable SMP. But SMP can only be enabled for the CPUs which will support it initially -- SPARC and i386. With the stub BSP support, a BSP can be run as a single core SMP system from an RTEMS data structure standpoint. * aclocal/check-smp.m4, aclocal/enable-smp.m4, score/include/rtems/bspsmp.h, score/include/rtems/score/smplock.h, score/src/smp.c, score/src/smplock.c: New files.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/percpu.c49
-rw-r--r--cpukit/score/src/smp.c153
-rw-r--r--cpukit/score/src/smplock.c49
-rw-r--r--cpukit/score/src/thread.c46
-rw-r--r--cpukit/score/src/threadcreateidle.c44
5 files changed, 303 insertions, 38 deletions
diff --git a/cpukit/score/src/percpu.c b/cpukit/score/src/percpu.c
index 4c719af6db..2d429b4db9 100644
--- a/cpukit/score/src/percpu.c
+++ b/cpukit/score/src/percpu.c
@@ -1,5 +1,5 @@
/*
- * COPYRIGHT (c) 1989-2010.
+ * COPYRIGHT (c) 1989-2011.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -19,11 +19,46 @@
#include <rtems/score/wkspace.h>
#include <rtems/score/wkspace.h>
#include <rtems/config.h>
+#include <rtems/bspsmp.h>
#include <string.h>
-/*
- * On single core systems, we can efficiently directly access a single
- * statically allocated per cpu structure. And the fields are initialized
- * as individual elements just like it has always been done.
- */
-Per_CPU_Control _Per_CPU_Information;
+#if defined(RTEMS_SMP)
+ void _SMP_Handler_initialize(void)
+ {
+ int cpu;
+ size_t size;
+ uintptr_t ptr;
+
+ /*
+ * Initialize per CPU structures.
+ */
+ size = (_SMP_Processor_count) * sizeof(Per_CPU_Control);
+ memset( _Per_CPU_Information, '\0', size );
+
+ /*
+ * Initialize per cpu pointer table
+ */
+ size = Configuration.interrupt_stack_size;
+ _Per_CPU_Information_p[0] = &_Per_CPU_Information[0];
+ for (cpu=1 ; cpu < _SMP_Processor_count ; cpu++ ) {
+ Per_CPU_Control *p = &_Per_CPU_Information[cpu];
+
+ _Per_CPU_Information_p[cpu] = p;
+
+ p->interrupt_stack_low = _Workspace_Allocate_or_fatal_error( size );
+
+ ptr = (uintptr_t) _Addresses_Add_offset( p->interrupt_stack_low, size );
+ ptr &= ~CPU_STACK_ALIGNMENT;
+ p->interrupt_stack_high = (void *)ptr;
+ p->state = RTEMS_BSP_SMP_CPU_INITIAL_STATE;
+ RTEMS_COMPILER_MEMORY_BARRIER();
+ }
+ }
+#else
+ /*
+ * On single core systems, we can efficiently directly access a single
+ * statically allocated per cpu structure. And the fields are initialized
+ * as individual elements just like it has always been done.
+ */
+ Per_CPU_Control _Per_CPU_Information[1];
+#endif
diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c
new file mode 100644
index 0000000000..4a0c13947f
--- /dev/null
+++ b/cpukit/score/src/smp.c
@@ -0,0 +1,153 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/bspsmp.h>
+#include <rtems/score/thread.h>
+
+#if defined(RTEMS_SMP)
+#define SMP_DEBUG
+
+#if defined(SMP_DEBUG)
+ #include <rtems/bspIo.h>
+#endif
+
+void rtems_smp_run_first_task(int cpu)
+{
+ Thread_Control *heir;
+
+ /*
+ * This CPU has an heir thread so we need to dispatch it.
+ */
+ heir = _Thread_Heir;
+
+ /*
+ * This is definitely a hack until we have SMP scheduling. Since there
+ * is only one executing and heir right now, we have to fake this out.
+ */
+ _Thread_Dispatch_disable_level = 1;
+ _Thread_Executing = heir;
+ _CPU_Context_switch_to_first_task_smp( &heir->Registers );
+}
+
+void rtems_smp_secondary_cpu_initialize(void)
+{
+ int cpu;
+
+ cpu = bsp_smp_processor_id();
+
+ bsp_smp_secondary_cpu_initialize(cpu);
+
+ #if defined(SMP_DEBUG)
+ printk( "Made it to %d -- ", cpu );
+ #endif
+
+ /*
+ * Inform the primary CPU that this secondary CPU is initialized
+ * and ready to dispatch to the first thread it is supposed to
+ * execute when the primary CPU is ready.
+ */
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
+
+ /*
+ * HACK: Should not have to enable interrupts in real system here.
+ * It should happen as part of switching to the first task.
+ */
+
+ _Per_CPU_Information[cpu].isr_nest_level = 1;
+ _ISR_Set_level( 0 );
+ while(1) ;
+}
+
+void rtems_smp_process_interrupt(void)
+{
+ int cpu;
+ uint32_t message;
+ ISR_Level level;
+
+ cpu = bsp_smp_processor_id();
+
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ message = _Per_CPU_Information[cpu].message;
+ _Per_CPU_Information[cpu].message &= ~message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+
+ #if defined(SMP_DEBUG)
+ {
+ void *sp = __builtin_frame_address(0);
+ if ( !(message & RTEMS_BSP_SMP_SHUTDOWN) )
+ printk( "ISR on CPU %d -- (0x%02x) (0x%p)\n", cpu, message, sp );
+ printk( "Dispatch level %d\n", _Thread_Dispatch_disable_level );
+ }
+ #endif
+
+ if ( message & RTEMS_BSP_SMP_FIRST_TASK ) {
+ _Per_CPU_Information[cpu].isr_nest_level = 0;
+ _Per_CPU_Information[cpu].message = 0;
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_INITIALIZED;
+ rtems_smp_run_first_task(cpu);
+ /* does not return */
+ }
+
+ if ( message & RTEMS_BSP_SMP_SHUTDOWN ) {
+ ISR_Level level;
+ _Thread_Dispatch_disable_level = 0;
+ _Per_CPU_Information[cpu].isr_nest_level = 0;
+ _Per_CPU_Information[cpu].state = RTEMS_BSP_SMP_CPU_SHUTDOWN;
+ _ISR_Disable( level );
+ while(1)
+ ;
+ /* does not continue past here */
+ }
+
+ if ( message & RTEMS_BSP_SMP_CONTEXT_SWITCH_NECESSARY ) {
+ printk( "switch needed\n" );
+ _Per_CPU_Information[cpu].dispatch_necessary = true;
+ }
+}
+
+void rtems_smp_send_message(
+ int cpu,
+ uint32_t message
+)
+{
+ ISR_Level level;
+
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ _Per_CPU_Information[cpu].message |= message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+ bsp_smp_interrupt_cpu( cpu );
+}
+
+void rtems_smp_broadcast_message(
+ uint32_t message
+)
+{
+ int dest_cpu;
+ int cpu;
+ ISR_Level level;
+
+ cpu = bsp_smp_processor_id();
+
+ for ( dest_cpu=0 ; dest_cpu < _SMP_Processor_count; dest_cpu++ ) {
+ if ( cpu == dest_cpu )
+ continue;
+ level = _SMP_lock_Spinlock_Obtain( &_Per_CPU_Information[cpu].lock );
+ _Per_CPU_Information[dest_cpu].message |= message;
+ _SMP_lock_Spinlock_Release( &_Per_CPU_Information[cpu].lock, level );
+ }
+ bsp_smp_broadcast_interrupt();
+}
+#endif
diff --git a/cpukit/score/src/smplock.c b/cpukit/score/src/smplock.c
new file mode 100644
index 0000000000..1dd691835b
--- /dev/null
+++ b/cpukit/score/src/smplock.c
@@ -0,0 +1,49 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/system.h>
+#include <rtems/score/smplock.h>
+
+void _SMP_lock_Spinlock_Initialize(
+ SMP_lock_Control *lock
+)
+{
+ *lock = 0;
+}
+
+ISR_Level _SMP_lock_Spinlock_Obtain(
+ SMP_lock_Control *lock
+)
+{
+ ISR_Level level;
+ uint32_t value = 1;
+ uint32_t previous;
+
+ /* Note: Disable provides an implicit memory barrier. */
+ _ISR_Disable( level );
+ do {
+ SMP_CPU_SWAP( lock, value, previous );
+ } while (previous == 1);
+ return level;
+}
+
+void _SMP_lock_Spinlock_Release(
+ SMP_lock_Control *lock,
+ ISR_Level level
+)
+{
+ *lock = 0;
+ _ISR_Enable( level );
+}
diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c
index 6284e4b3e3..7a0eb38502 100644
--- a/cpukit/score/src/thread.c
+++ b/cpukit/score/src/thread.c
@@ -2,7 +2,7 @@
* Thread Handler
*
*
- * COPYRIGHT (c) 1989-2008.
+ * COPYRIGHT (c) 1989-2011.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -33,8 +33,11 @@
#include <rtems/score/wkspace.h>
#include <rtems/config.h>
-/*PAGE
- *
+#if defined(RTEMS_SMP)
+ #include <rtems/bspsmp.h>
+#endif
+
+/*
* _Thread_Handler_initialization
*
* This routine initializes all thread manager related data structures.
@@ -48,6 +51,7 @@ void _Thread_Handler_initialization(void)
{
uint32_t ticks_per_timeslice;
uint32_t maximum_extensions;
+ uint32_t maximum_internal_threads;
#if defined(RTEMS_MULTIPROCESSING)
uint32_t maximum_proxies;
#endif
@@ -80,32 +84,40 @@ void _Thread_Handler_initialization(void)
_Thread_Ticks_per_timeslice = ticks_per_timeslice;
-#if defined(RTEMS_MULTIPROCESSING)
- _Thread_MP_Handler_initialization( maximum_proxies );
-#endif
+ #if defined(RTEMS_MULTIPROCESSING)
+ _Thread_MP_Handler_initialization( maximum_proxies );
+ #endif
/*
- * Initialize this class of objects.
+ * Initialize the internal class of threads. We need an IDLE thread
+ * per CPU in an SMP system. In addition, if this is a loosely
+ * coupled multiprocessing system, account for the MPCI Server Thread.
*/
+ #if defined(RTEMS_SMP)
+ maximum_internal_threads = rtems_smp_maximum_processors;
+ #else
+ maximum_internal_threads = 1;
+ #endif
+
+ #if defined(RTEMS_MULTIPROCESSING)
+ if ( _System_state_Is_multiprocessing )
+ maximum_internal_threads += 1;
+ #endif
_Objects_Initialize_information(
&_Thread_Internal_information,
OBJECTS_INTERNAL_API,
OBJECTS_INTERNAL_THREADS,
-#if defined(RTEMS_MULTIPROCESSING)
- ( _System_state_Is_multiprocessing ) ? 2 : 1,
-#else
- 1,
-#endif
+ maximum_internal_threads,
sizeof( Thread_Control ),
/* size of this object's control block */
false, /* true if names for this object are strings */
8 /* maximum length of each object's name */
-#if defined(RTEMS_MULTIPROCESSING)
- ,
- false, /* true if this is a global object class */
- NULL /* Proxy extraction support callout */
-#endif
+ #if defined(RTEMS_MULTIPROCESSING)
+ ,
+ false, /* true if this is a global object class */
+ NULL /* Proxy extraction support callout */
+ #endif
);
}
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
index bea6a23b89..6a4bf65e9c 100644
--- a/cpukit/score/src/threadcreateidle.c
+++ b/cpukit/score/src/threadcreateidle.c
@@ -2,7 +2,7 @@
* Thread Handler
*
*
- * COPYRIGHT (c) 1989-2008.
+ * COPYRIGHT (c) 1989-2011.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -30,24 +30,24 @@
#include <rtems/score/userext.h>
#include <rtems/score/wkspace.h>
#include <rtems/config.h>
+#include <rtems/bspsmp.h>
-/*PAGE
- *
- * _Thread_Create_idle
- */
-
-void _Thread_Create_idle( void )
+static inline void _Thread_Create_idle_helper(
+ uint32_t name_u32,
+ int cpu
+)
{
- Objects_Name name;
+ Objects_Name name;
+ Thread_Control *idle;
- name.name_u32 = _Objects_Build_name( 'I', 'D', 'L', 'E' );
+ name.name_u32 = name_u32;
/*
* The entire workspace is zeroed during its initialization. Thus, all
* fields not explicitly assigned were explicitly zeroed by
* _Workspace_Initialization.
*/
- _Thread_Idle = _Thread_Internal_allocate();
+ idle = _Thread_Internal_allocate();
/*
* This is only called during initialization and we better be sure
@@ -58,7 +58,7 @@ void _Thread_Create_idle( void )
_Thread_Initialize(
&_Thread_Internal_information,
- _Thread_Idle,
+ idle,
NULL, /* allocate the stack */
_Stack_Ensure_minimum( Configuration.idle_task_stack_size ),
CPU_IDLE_TASK_IS_FP,
@@ -76,15 +76,31 @@ void _Thread_Create_idle( void )
* WARNING!!! This is necessary to "kick" start the system and
* MUST be done before _Thread_Start is invoked.
*/
- _Thread_Heir =
- _Thread_Executing = _Thread_Idle;
+ _Per_CPU_Information[ cpu ].idle =
+ _Per_CPU_Information[ cpu ].heir =
+ _Per_CPU_Information[ cpu ].executing = idle;
_Thread_Start(
- _Thread_Idle,
+ idle,
THREAD_START_NUMERIC,
Configuration.idle_task,
NULL,
0
);
+}
+
+void _Thread_Create_idle( void )
+{
+ #if defined(RTEMS_SMP)
+ int cpu;
+ for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) {
+ _Thread_Create_idle_helper(
+ _Objects_Build_name( 'I', 'D', 'L', 'E' ),
+ cpu
+ );
+ }
+ #else
+ _Thread_Create_idle_helper(_Objects_Build_name( 'I', 'D', 'L', 'E' ), 0);
+ #endif
}