[PATCH 03/12] score: Add and use _Per_CPU_Acquire_all().

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Aug 5 14:08:10 UTC 2013


Add and use _Per_CPU_Release_all().

The context switch user extensions are invoked in _Thread_Dispatch().
This change is necessary to avoid the giant lock in _Thread_Dispatch().
---
 cpukit/score/include/rtems/score/percpu.h |   30 +++++++++++++++++++++++++++++
 cpukit/score/src/userextaddset.c          |    8 ++++++-
 cpukit/score/src/userextremoveset.c       |   10 +++++++-
 3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/cpukit/score/include/rtems/score/percpu.h b/cpukit/score/include/rtems/score/percpu.h
index 6e3a18e..7a4c70e 100644
--- a/cpukit/score/include/rtems/score/percpu.h
+++ b/cpukit/score/include/rtems/score/percpu.h
@@ -235,6 +235,36 @@ extern Per_CPU_Control_envelope _Per_CPU_Information[] CPU_STRUCTURE_ALIGNMENT;
   _ISR_lock_Release( &( per_cpu )->lock )
 
 #if defined( RTEMS_SMP )
+#define _Per_CPU_Acquire_all( isr_cookie ) \
+  do { \
+    uint32_t ncpus = _SMP_Get_processor_count(); \
+    uint32_t cpu; \
+    _ISR_Disable( isr_cookie ); \
+    for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \
+      _Per_CPU_Acquire( _Per_CPU_Get_by_index( cpu ) ); \
+    } \
+  } while ( 0 )
+#else
+#define _Per_CPU_Acquire_all( isr_cookie ) \
+  _ISR_Disable( isr_cookie )
+#endif
+
+#if defined( RTEMS_SMP )
+#define _Per_CPU_Release_all( isr_cookie ) \
+  do { \
+    uint32_t ncpus = _SMP_Get_processor_count(); \
+    uint32_t cpu; \
+    for ( cpu = 0 ; cpu < ncpus ; ++cpu ) { \
+      _Per_CPU_Release( _Per_CPU_Get_by_index( cpu ) ); \
+    } \
+    _ISR_Enable( isr_cookie ); \
+  } while ( 0 )
+#else
+#define _Per_CPU_Release_all( isr_cookie ) \
+  _ISR_Enable( isr_cookie )
+#endif
+
+#if defined( RTEMS_SMP )
 static inline Per_CPU_Control *_Per_CPU_Get( void )
 {
   _Assert_Thread_dispatching_repressed();
diff --git a/cpukit/score/src/userextaddset.c b/cpukit/score/src/userextaddset.c
index d24dc4a..270d93c 100644
--- a/cpukit/score/src/userextaddset.c
+++ b/cpukit/score/src/userextaddset.c
@@ -20,6 +20,7 @@
 #endif
 
 #include <rtems/score/userextimpl.h>
+#include <rtems/score/percpu.h>
 
 void _User_extensions_Add_set(
   User_extensions_Control *the_extension
@@ -32,11 +33,16 @@ void _User_extensions_Add_set(
    */
 
   if ( the_extension->Callouts.thread_switch != NULL ) {
+    ISR_Level level;
+
     the_extension->Switch.thread_switch =
       the_extension->Callouts.thread_switch;
-    _Chain_Append(
+
+    _Per_CPU_Acquire_all( level );
+    _Chain_Append_unprotected(
       &_User_extensions_Switches_list,
       &the_extension->Switch.Node
     );
+    _Per_CPU_Release_all( level );
   }
 }
diff --git a/cpukit/score/src/userextremoveset.c b/cpukit/score/src/userextremoveset.c
index e90ff77..64fb166 100644
--- a/cpukit/score/src/userextremoveset.c
+++ b/cpukit/score/src/userextremoveset.c
@@ -20,6 +20,7 @@
 #endif
 
 #include <rtems/score/userextimpl.h>
+#include <rtems/score/percpu.h>
 
 void _User_extensions_Remove_set (
   User_extensions_Control  *the_extension
@@ -31,6 +32,11 @@ void _User_extensions_Remove_set (
    * If a switch handler is present, remove it.
    */
 
-  if ( the_extension->Callouts.thread_switch != NULL )
-    _Chain_Extract( &the_extension->Switch.Node );
+  if ( the_extension->Callouts.thread_switch != NULL ) {
+    ISR_Level level;
+
+    _Per_CPU_Acquire_all( level );
+    _Chain_Extract_unprotected( &the_extension->Switch.Node );
+    _Per_CPU_Release_all( level );
+  }
 }
-- 
1.7.7




More information about the devel mailing list