From edde99bd213d20c55430dd29089e0d8a807ab6d8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 14 Jun 2013 14:26:34 +0200 Subject: score: Rename rtems_smp_get_number_of_processors() Rename in rtems_smp_get_processor_count(). Always provide and . Add _SMP_Get_processor_count(). This function will be a compile time constant defined to be one on uni-processor configurations. This allows iterations over all processors without overhead on uni-processor configurations. --- c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c | 2 +- cpukit/libmisc/cpuuse/cpuusagereport.c | 2 +- cpukit/rtems/Makefile.am | 5 +-- cpukit/rtems/include/rtems.h | 2 - cpukit/rtems/include/rtems/rtems/smp.h | 46 +++++++++++---------- cpukit/rtems/preinstall.am | 9 ++--- cpukit/score/Makefile.am | 4 +- cpukit/score/include/rtems/score/smp.h | 60 +++++++++++++++------------- cpukit/score/preinstall.am | 9 ++--- cpukit/score/src/smp.c | 8 ++-- cpukit/score/src/threadcreateidle.c | 2 +- testsuites/smptests/smp01/init.c | 6 +-- testsuites/smptests/smp02/init.c | 2 +- testsuites/smptests/smp03/init.c | 8 ++-- testsuites/smptests/smp04/init.c | 12 +++--- testsuites/smptests/smp05/init.c | 2 +- testsuites/smptests/smp06/init.c | 2 +- testsuites/smptests/smp08/init.c | 2 +- testsuites/smptests/smp09/init.c | 2 +- testsuites/smptests/smpatomic01/init.c | 6 +-- testsuites/smptests/smpatomic02/init.c | 6 +-- testsuites/smptests/smpatomic03/init.c | 6 +-- testsuites/smptests/smpatomic04/init.c | 6 +-- testsuites/smptests/smpatomic05/init.c | 6 +-- testsuites/smptests/smpatomic06/init.c | 6 +-- testsuites/smptests/smpatomic07/init.c | 6 +-- testsuites/smptests/smplock01/init.c | 4 +- testsuites/sptests/spsize/size.c | 6 +-- 28 files changed, 117 insertions(+), 120 deletions(-) diff --git a/c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c b/c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c index 90818194cd..7dbd5bb12a 100644 --- a/c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c +++ b/c/src/lib/libbsp/sparc/leon3/smp/smp_leon3.c @@ -130,7 +130,7 @@ void bsp_smp_broadcast_interrupt(void) int max_cpus; cpu = bsp_smp_processor_id(); - max_cpus = rtems_smp_get_number_of_processors(); + max_cpus = rtems_smp_get_processor_count(); for ( dest_cpu=0 ; dest_cpu < max_cpus ; dest_cpu++ ) { if ( cpu == dest_cpu ) diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 0255c19848..238d91a21d 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -39,7 +39,7 @@ } #else int cpu; - for ( cpu=0 ; cpu < rtems_smp_get_number_of_processors() ; cpu++ ) { + for ( cpu=0 ; cpu < rtems_smp_get_processor_count() ; cpu++ ) { Per_CPU_Control *p = &_Per_CPU_Information[cpu]; if ( p->executing->Object.id == the_thread->Object.id ) { *time_of_context_switch = p->time_of_last_context_switch; diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index 768d451588..a9b4ca848b 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -34,6 +34,7 @@ include_rtems_rtems_HEADERS += include/rtems/rtems/region.h include_rtems_rtems_HEADERS += include/rtems/rtems/rtemsapi.h include_rtems_rtems_HEADERS += include/rtems/rtems/sem.h include_rtems_rtems_HEADERS += include/rtems/rtems/signal.h +include_rtems_rtems_HEADERS += include/rtems/rtems/smp.h include_rtems_rtems_HEADERS += include/rtems/rtems/status.h include_rtems_rtems_HEADERS += include/rtems/rtems/support.h include_rtems_rtems_HEADERS += include/rtems/rtems/tasks.h @@ -54,10 +55,6 @@ include_rtems_rtems_HEADERS += include/rtems/rtems/signalmp.h include_rtems_rtems_HEADERS += include/rtems/rtems/taskmp.h endif -if HAS_SMP -include_rtems_rtems_HEADERS += include/rtems/rtems/smp.h -endif - include_rtems_rtems_HEADERS += inline/rtems/rtems/asr.inl include_rtems_rtems_HEADERS += inline/rtems/rtems/attr.inl include_rtems_rtems_HEADERS += inline/rtems/rtems/barrier.inl diff --git a/cpukit/rtems/include/rtems.h b/cpukit/rtems/include/rtems.h index a644fa051c..ab727b250f 100644 --- a/cpukit/rtems/include/rtems.h +++ b/cpukit/rtems/include/rtems.h @@ -73,9 +73,7 @@ extern "C" { #if defined(RTEMS_MULTIPROCESSING) #include #endif -#if defined(RTEMS_SMP) #include -#endif #include diff --git a/cpukit/rtems/include/rtems/rtems/smp.h b/cpukit/rtems/include/rtems/rtems/smp.h index 1b0618ef4a..d8431b07f1 100644 --- a/cpukit/rtems/include/rtems/rtems/smp.h +++ b/cpukit/rtems/include/rtems/rtems/smp.h @@ -1,16 +1,13 @@ /** - * @file rtems/rtems/smp.h + * @file * - * @defgroup ClassicSMP Classic API SMP Services + * @ingroup ClassicSMP * - * @ingroup ClassicRTEMS - * @brief SMP information and services. - * - * Most of the SMP interface is hidden from the application - * and exists between the BSP and RTEMS. + * @brief SMP Services API */ -/* COPYRIGHT (c) 1989-2011. +/* + * COPYRIGHT (c) 1989-2011. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -28,25 +25,34 @@ extern "C" { #include /** - * @defgroup ClassicSMP Classic API SMP Services + * @defgroup ClassicSMP SMP Services + * + * @ingroup ClassicRTEMS + * + * This encapsulates functionality which is useful for SMP applications. * - * @ingroup ClassicRTEMS + * This API is also available on uni-processor configurations. Here compile + * time constants are used whenever possible. * - * This encapsulates functionality which is useful for SMP applications. + * @{ */ -/**@{*/ /** - * @brief Obtain Number of Cores in System + * @brief Returns the count of processors in the system. + * + * On uni-processor configurations this is a compile time constant and defined + * to be one. * - * This method returns the number of CPU cores that are currently in - * the system. This will always be less than or equal to the number - * of maximum number of cores which were configured. + * On SMP configurations this returns the value of a global variable set during + * system initialization to indicate the count of processors. The processor + * count depends on the hardware and application configuration. The value will + * always be less than or equal to the maximum count of application configured + * processors. * - * @retval This method returns the number of cores in this system. + * @return The count of processors in the system. */ -#define rtems_smp_get_number_of_processors() \ - (_SMP_Processor_count) +#define rtems_smp_get_processor_count() \ + _SMP_Get_processor_count() /** * @brief Obtain Current Core Number @@ -58,7 +64,7 @@ extern "C" { #define rtems_smp_get_current_processor() \ bsp_smp_processor_id() -/**@}*/ +/** @} */ #ifdef __cplusplus } diff --git a/cpukit/rtems/preinstall.am b/cpukit/rtems/preinstall.am index f64600fe10..8a0f780562 100644 --- a/cpukit/rtems/preinstall.am +++ b/cpukit/rtems/preinstall.am @@ -107,6 +107,10 @@ $(PROJECT_INCLUDE)/rtems/rtems/signal.h: include/rtems/rtems/signal.h $(PROJECT_ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/signal.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/signal.h +$(PROJECT_INCLUDE)/rtems/rtems/smp.h: include/rtems/rtems/smp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/smp.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/smp.h + $(PROJECT_INCLUDE)/rtems/rtems/status.h: include/rtems/rtems/status.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/status.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/status.h @@ -168,11 +172,6 @@ $(PROJECT_INCLUDE)/rtems/rtems/taskmp.h: include/rtems/rtems/taskmp.h $(PROJECT_ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/taskmp.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/taskmp.h endif -if HAS_SMP -$(PROJECT_INCLUDE)/rtems/rtems/smp.h: include/rtems/rtems/smp.h $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/smp.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/smp.h -endif $(PROJECT_INCLUDE)/rtems/rtems/asr.inl: inline/rtems/rtems/asr.inl $(PROJECT_INCLUDE)/rtems/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtems/asr.inl PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtems/asr.inl diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 9aa5890245..a897e60709 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -40,6 +40,7 @@ include_rtems_score_HEADERS += include/rtems/score/schedulercbs.h include_rtems_score_HEADERS += include/rtems/score/scheduleredf.h include_rtems_score_HEADERS += include/rtems/score/schedulerpriority.h include_rtems_score_HEADERS += include/rtems/score/schedulersimple.h +include_rtems_score_HEADERS += include/rtems/score/smp.h include_rtems_score_HEADERS += include/rtems/score/smplock.h include_rtems_score_HEADERS += include/rtems/score/stack.h include_rtems_score_HEADERS += include/rtems/score/states.h @@ -62,9 +63,6 @@ include_rtems_score_HEADERS += include/rtems/score/basedefs.h include_rtems_score_HEADERS += include/rtems/score/atomic.h include_rtems_score_HEADERS += include/rtems/score/genericcpuatomic.h include_rtems_score_HEADERS += include/rtems/score/genericatomicops.h -if HAS_SMP -include_rtems_score_HEADERS += include/rtems/score/smp.h -endif if HAS_PTHREADS include_rtems_score_HEADERS += include/rtems/score/corespinlock.h diff --git a/cpukit/score/include/rtems/score/smp.h b/cpukit/score/include/rtems/score/smp.h index c7de6d64a9..ea073ac24b 100644 --- a/cpukit/score/include/rtems/score/smp.h +++ b/cpukit/score/include/rtems/score/smp.h @@ -1,10 +1,9 @@ /** - * @file rtems/score/smp.h + * @file * - * @brief Interface to the SuperCore SMP Support used Internally to RTEMS + * @ingroup ScoreSMP * - * This include file defines the interface to the SuperCore - * SMP support that is used internally to RTEMS. + * @brief SuperCore SMP Support API */ /* @@ -19,24 +18,22 @@ #ifndef _RTEMS_SCORE_SMP_H #define _RTEMS_SCORE_SMP_H -#if defined (RTEMS_SMP) -#include +#include + +#ifdef __cplusplus +extern "C" { +#endif /** - * @defgroup SuperCoreSMP SMP Support + * @defgroup ScoreSMP SMP Support + * + * @ingroup Score * - * @ingroup Score + * This defines the interface of the SuperCore SMP support. * - * This defines the interface of the SuperCore support - * code for SMP support. + * @{ */ -/**@{*/ - -#ifdef __cplusplus -extern "C" { -#endif - /** * This defines the bit which indicates the interprocessor interrupt * has been requested so that RTEMS will reschedule on this CPU @@ -58,14 +55,20 @@ extern "C" { */ #define RTEMS_BSP_SMP_SHUTDOWN 0x04 -#ifndef ASM -/** - * @brief Number of CPUs in a SMP system. - * - * This variable is set during the SMP initialization sequence to - * indicate the number of CPUs in this system. - */ -SCORE_EXTERN uint32_t _SMP_Processor_count; +#if !defined( ASM ) + +#if defined( RTEMS_SMP ) + SCORE_EXTERN uint32_t _SMP_Processor_count; + + static inline uint32_t _SMP_Get_processor_count( void ) + { + return _SMP_Processor_count; + } +#else + #define _SMP_Get_processor_count() ( ( uint32_t ) 1 ) +#endif + +#if defined( RTEMS_SMP ) /** * @brief Sends a SMP message to a processor. @@ -114,14 +117,15 @@ void _SMP_Request_other_cores_to_dispatch(void); */ void _SMP_Request_other_cores_to_shutdown(void); -#endif +#endif /* defined( RTEMS_SMP ) */ + +#endif /* !defined( ASM ) */ + +/** @} */ #ifdef __cplusplus } #endif -#endif - -/**@}*/ #endif /* end of include file */ diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am index 2cbbd8c0d5..dc84b216b1 100644 --- a/cpukit/score/preinstall.am +++ b/cpukit/score/preinstall.am @@ -143,6 +143,10 @@ $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h: include/rtems/score/schedulers $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/schedulersimple.h +$(PROJECT_INCLUDE)/rtems/score/smp.h: include/rtems/score/smp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/smp.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/smp.h + $(PROJECT_INCLUDE)/rtems/score/smplock.h: include/rtems/score/smplock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/smplock.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/smplock.h @@ -231,11 +235,6 @@ $(PROJECT_INCLUDE)/rtems/score/genericatomicops.h: include/rtems/score/genericat $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/genericatomicops.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/genericatomicops.h -if HAS_SMP -$(PROJECT_INCLUDE)/rtems/score/smp.h: include/rtems/score/smp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/smp.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/smp.h -endif if HAS_PTHREADS $(PROJECT_INCLUDE)/rtems/score/corespinlock.h: include/rtems/score/corespinlock.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/corespinlock.h diff --git a/cpukit/score/src/smp.c b/cpukit/score/src/smp.c index a8d8f4986f..10acbe25de 100644 --- a/cpukit/score/src/smp.c +++ b/cpukit/score/src/smp.c @@ -126,7 +126,7 @@ void _SMP_Send_message( int cpu, uint32_t message ) void _SMP_Broadcast_message( uint32_t message ) { int self = bsp_smp_processor_id(); - int ncpus = _SMP_Processor_count; + int ncpus = _SMP_Get_processor_count(); int cpu; for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { @@ -146,7 +146,7 @@ void _SMP_Broadcast_message( uint32_t message ) void _SMP_Request_other_cores_to_perform_first_context_switch( void ) { int self = bsp_smp_processor_id(); - int ncpus = _SMP_Processor_count; + int ncpus = _SMP_Get_processor_count(); int cpu; for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { @@ -165,7 +165,7 @@ void _SMP_Request_other_cores_to_dispatch( void ) { if ( _System_state_Is_up( _System_state_Get() ) ) { int self = bsp_smp_processor_id(); - int ncpus = _SMP_Processor_count; + int ncpus = _SMP_Get_processor_count(); int cpu; for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { @@ -185,7 +185,7 @@ void _SMP_Request_other_cores_to_dispatch( void ) void _SMP_Request_other_cores_to_shutdown( void ) { int self = bsp_smp_processor_id(); - int ncpus = _SMP_Processor_count; + int ncpus = _SMP_Get_processor_count(); int cpu; _SMP_Broadcast_message( RTEMS_BSP_SMP_SHUTDOWN ); diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c index e4581c8ecb..f90db795bf 100644 --- a/cpukit/score/src/threadcreateidle.c +++ b/cpukit/score/src/threadcreateidle.c @@ -89,7 +89,7 @@ void _Thread_Create_idle( void ) #if defined(RTEMS_SMP) int cpu; - for ( cpu=0 ; cpu < _SMP_Processor_count ; cpu++ ) { + for ( cpu=0 ; cpu < _SMP_Get_processor_count() ; cpu++ ) { _Thread_Create_idle_helper( _Objects_Build_name( 'I', 'D', 'L', 'E' ), cpu diff --git a/testsuites/smptests/smp01/init.c b/testsuites/smptests/smp01/init.c index af2a36744a..b47f1b4f50 100644 --- a/testsuites/smptests/smp01/init.c +++ b/testsuites/smptests/smp01/init.c @@ -44,12 +44,12 @@ rtems_task Init( locked_printf( "\n\n*** SMP01 TEST ***\n" ); /* Initialize the TaskRan array */ - for ( i=0; i 1 ); + rtems_test_assert( rtems_smp_get_processor_count() > 1 ); cpu_num = bsp_smp_processor_id(); diff --git a/testsuites/smptests/smp08/init.c b/testsuites/smptests/smp08/init.c index 8e8de7c052..0c7740b32e 100644 --- a/testsuites/smptests/smp08/init.c +++ b/testsuites/smptests/smp08/init.c @@ -73,7 +73,7 @@ rtems_task Init( /* Show that the init task is running on this cpu */ PrintTaskInfo( "Init", &time ); - for ( i=1; i <= rtems_smp_get_number_of_processors() *3; i++ ) { + for ( i=1; i <= rtems_smp_get_processor_count() *3; i++ ) { sprintf(ch, "%02" PRId32, i ); status = rtems_task_create( diff --git a/testsuites/smptests/smp09/init.c b/testsuites/smptests/smp09/init.c index c599a7f15e..976cb35195 100644 --- a/testsuites/smptests/smp09/init.c +++ b/testsuites/smptests/smp09/init.c @@ -42,7 +42,7 @@ rtems_task Init( for ( killtime=0; killtime<1000000; killtime++ ) ; - for ( i=0; i