[PATCH 5/5] score: Use Scheduler_Context for SMP scheduler

Sebastian Huber sebastian.huber at embedded-brains.de
Tue May 13 14:18:33 UTC 2014


Use the basic Scheduler_Context for the general SMP scheduler operations
to avoid usage of structure offsets to get the specialized context
variants.
---
 .../score/include/rtems/score/schedulersmpimpl.h   |   67 ++++++++++++--------
 cpukit/score/src/schedulerprioritysmp.c            |   46 +++++++-------
 cpukit/score/src/schedulersimplesmp.c              |   48 +++++++-------
 3 files changed, 88 insertions(+), 73 deletions(-)

diff --git a/cpukit/score/include/rtems/score/schedulersmpimpl.h b/cpukit/score/include/rtems/score/schedulersmpimpl.h
index 580c641..8800d85 100644
--- a/cpukit/score/include/rtems/score/schedulersmpimpl.h
+++ b/cpukit/score/include/rtems/score/schedulersmpimpl.h
@@ -314,24 +314,31 @@ extern "C" {
  */
 
 typedef Thread_Control *( *Scheduler_SMP_Get_highest_ready )(
-  Scheduler_SMP_Context *self
+  Scheduler_Context *context
 );
 
 typedef void ( *Scheduler_SMP_Extract )(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread
 );
 
 typedef void ( *Scheduler_SMP_Insert )(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread_to_insert
 );
 
 typedef void ( *Scheduler_SMP_Move )(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread_to_move
 );
 
+static inline Scheduler_SMP_Context *_Scheduler_SMP_Get_self(
+  Scheduler_Context *context
+)
+{
+  return (Scheduler_SMP_Context *) context;
+}
+
 static inline void _Scheduler_SMP_Initialize(
   Scheduler_SMP_Context *self
 )
@@ -469,7 +476,7 @@ static inline Thread_Control *_Scheduler_SMP_Get_lowest_scheduled(
  * of scheduled nodes to the set of ready nodes.
  */
 static inline void _Scheduler_SMP_Enqueue_ordered(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Chain_Node_order order,
   Scheduler_SMP_Get_highest_ready get_highest_ready,
@@ -479,10 +486,11 @@ static inline void _Scheduler_SMP_Enqueue_ordered(
   Scheduler_SMP_Move move_from_scheduled_to_ready
 )
 {
+  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
   Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
 
   if ( node->state == SCHEDULER_SMP_IN_THE_AIR ) {
-    Thread_Control *highest_ready = ( *get_highest_ready )( self );
+    Thread_Control *highest_ready = ( *get_highest_ready )( &self->Base );
 
     /*
      * The thread has been extracted from the scheduled chain.  We have to
@@ -496,14 +504,15 @@ static inline void _Scheduler_SMP_Enqueue_ordered(
     ) {
       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_READY );
       _Scheduler_SMP_Allocate_processor( self, highest_ready, thread );
-      ( *insert_ready )( self, thread );
-      ( *move_from_ready_to_scheduled )( self, highest_ready );
+      ( *insert_ready )( &self->Base, thread );
+      ( *move_from_ready_to_scheduled )( &self->Base, highest_ready );
     } else {
       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_SCHEDULED );
-      ( *insert_scheduled )( self, thread );
+      ( *insert_scheduled )( &self->Base, thread );
     }
   } else {
-    Thread_Control *lowest_scheduled = _Scheduler_SMP_Get_lowest_scheduled( self );
+    Thread_Control *lowest_scheduled =
+      _Scheduler_SMP_Get_lowest_scheduled( self );
 
     /*
      * The scheduled chain is empty if nested interrupts change the priority of
@@ -521,27 +530,28 @@ static inline void _Scheduler_SMP_Enqueue_ordered(
         SCHEDULER_SMP_READY
       );
       _Scheduler_SMP_Allocate_processor( self, thread, lowest_scheduled );
-      ( *insert_scheduled )( self, thread );
-      ( *move_from_scheduled_to_ready )( self, lowest_scheduled );
+      ( *insert_scheduled )( &self->Base, thread );
+      ( *move_from_scheduled_to_ready )( &self->Base, lowest_scheduled );
     } else {
       _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_READY );
-      ( *insert_ready )( self, thread );
+      ( *insert_ready )( &self->Base, thread );
     }
   }
 }
 
 static inline void _Scheduler_SMP_Schedule_highest_ready(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *victim,
   Scheduler_SMP_Get_highest_ready get_highest_ready,
   Scheduler_SMP_Move move_from_ready_to_scheduled
 )
 {
-  Thread_Control *highest_ready = ( *get_highest_ready )( self );
+  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
+  Thread_Control *highest_ready = ( *get_highest_ready )( &self->Base );
 
   _Scheduler_SMP_Allocate_processor( self, highest_ready, victim );
 
-  ( *move_from_ready_to_scheduled )( self, highest_ready );
+  ( *move_from_ready_to_scheduled )( &self->Base, highest_ready );
 }
 
 /**
@@ -554,7 +564,7 @@ static inline void _Scheduler_SMP_Schedule_highest_ready(
  * of ready nodes to the set of scheduled nodes.
  */
 static inline void _Scheduler_SMP_Schedule(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Scheduler_SMP_Get_highest_ready get_highest_ready,
   Scheduler_SMP_Move move_from_ready_to_scheduled
@@ -566,7 +576,7 @@ static inline void _Scheduler_SMP_Schedule(
     _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_BLOCKED );
 
     _Scheduler_SMP_Schedule_highest_ready(
-      self,
+      context,
       thread,
       get_highest_ready,
       move_from_ready_to_scheduled
@@ -575,17 +585,17 @@ static inline void _Scheduler_SMP_Schedule(
 }
 
 static inline void _Scheduler_SMP_Block(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Scheduler_SMP_Extract extract,
   Scheduler_SMP_Get_highest_ready get_highest_ready,
   Scheduler_SMP_Move move_from_ready_to_scheduled
 )
 {
-  ( *extract )( self, thread );
+  ( *extract )( context, thread );
 
   _Scheduler_SMP_Schedule(
-    self,
+    context,
     thread,
     get_highest_ready,
     move_from_ready_to_scheduled
@@ -601,19 +611,21 @@ static inline void _Scheduler_SMP_Block(
  * ready nodes.
  */
 static inline void _Scheduler_SMP_Extract(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Scheduler_SMP_Extract extract
 )
 {
-  ( *extract )( self, thread );
+  ( *extract )( context, thread );
 }
 
 static inline void _Scheduler_SMP_Insert_scheduled_lifo(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
+  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
+
   _Chain_Insert_ordered_unprotected(
     &self->Scheduled,
     &thread->Object.Node,
@@ -622,10 +634,12 @@ static inline void _Scheduler_SMP_Insert_scheduled_lifo(
 }
 
 static inline void _Scheduler_SMP_Insert_scheduled_fifo(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
+  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
+
   _Chain_Insert_ordered_unprotected(
     &self->Scheduled,
     &thread->Object.Node,
@@ -634,11 +648,12 @@ static inline void _Scheduler_SMP_Insert_scheduled_fifo(
 }
 
 static inline void _Scheduler_SMP_Start_idle(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Per_CPU_Control *cpu
 )
 {
+  Scheduler_SMP_Context *self = _Scheduler_SMP_Get_self( context );
   Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
 
   node->state = SCHEDULER_SMP_SCHEDULED;
diff --git a/cpukit/score/src/schedulerprioritysmp.c b/cpukit/score/src/schedulerprioritysmp.c
index 65a847c..8c91633 100644
--- a/cpukit/score/src/schedulerprioritysmp.c
+++ b/cpukit/score/src/schedulerprioritysmp.c
@@ -36,11 +36,9 @@ _Scheduler_priority_SMP_Get_context( const Scheduler_Control *scheduler )
 }
 
 static Scheduler_priority_SMP_Context *
-_Scheduler_priority_SMP_Self_from_SMP_base( Scheduler_SMP_Context *smp_base )
+_Scheduler_priority_SMP_Get_self( Scheduler_Context *context )
 {
-  return (Scheduler_priority_SMP_Context *)
-    ( (char *) smp_base
-      - offsetof( Scheduler_priority_SMP_Context, Base ) );
+  return (Scheduler_priority_SMP_Context *) context;
 }
 
 static Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Node_get(
@@ -91,11 +89,11 @@ void _Scheduler_priority_SMP_Update(
 }
 
 static Thread_Control *_Scheduler_priority_SMP_Get_highest_ready(
-  Scheduler_SMP_Context *smp_base
+  Scheduler_Context *context
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Thread_Control *highest_ready = NULL;
 
   if ( !_Priority_bit_map_Is_empty( &self->Bit_map ) ) {
@@ -109,12 +107,12 @@ static Thread_Control *_Scheduler_priority_SMP_Get_highest_ready(
 }
 
 static void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *scheduled_to_ready
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Scheduler_priority_SMP_Node *node =
     _Scheduler_priority_SMP_Node_get( scheduled_to_ready );
 
@@ -127,12 +125,12 @@ static void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
 }
 
 static void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *ready_to_scheduled
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Scheduler_priority_SMP_Node *node =
     _Scheduler_priority_SMP_Node_get( ready_to_scheduled );
 
@@ -148,12 +146,12 @@ static void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
 }
 
 static void _Scheduler_priority_SMP_Insert_ready_lifo(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Scheduler_priority_SMP_Node *node =
     _Scheduler_priority_SMP_Node_get( thread );
 
@@ -165,12 +163,12 @@ static void _Scheduler_priority_SMP_Insert_ready_lifo(
 }
 
 static void _Scheduler_priority_SMP_Insert_ready_fifo(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Scheduler_priority_SMP_Node *node =
     _Scheduler_priority_SMP_Node_get( thread );
 
@@ -182,12 +180,12 @@ static void _Scheduler_priority_SMP_Insert_ready_fifo(
 }
 
 static void _Scheduler_priority_SMP_Do_extract(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_priority_SMP_Context *self =
-    _Scheduler_priority_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_priority_SMP_Get_self( context );
   Scheduler_priority_SMP_Node *node =
     _Scheduler_priority_SMP_Node_get( thread );
 
@@ -213,7 +211,7 @@ void _Scheduler_priority_SMP_Block(
     _Scheduler_priority_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Block(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_priority_SMP_Do_extract,
     _Scheduler_priority_SMP_Get_highest_ready,
@@ -222,7 +220,7 @@ void _Scheduler_priority_SMP_Block(
 }
 
 static void _Scheduler_priority_SMP_Enqueue_ordered(
-  Scheduler_SMP_Context *self,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Chain_Node_order order,
   Scheduler_SMP_Insert insert_ready,
@@ -230,7 +228,7 @@ static void _Scheduler_priority_SMP_Enqueue_ordered(
 )
 {
   _Scheduler_SMP_Enqueue_ordered(
-    self,
+    context,
     thread,
     order,
     _Scheduler_priority_SMP_Get_highest_ready,
@@ -250,7 +248,7 @@ void _Scheduler_priority_SMP_Enqueue_lifo(
     _Scheduler_priority_SMP_Get_context( scheduler );
 
   _Scheduler_priority_SMP_Enqueue_ordered(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_Insert_priority_lifo_order,
     _Scheduler_priority_SMP_Insert_ready_lifo,
@@ -267,7 +265,7 @@ void _Scheduler_priority_SMP_Enqueue_fifo(
     _Scheduler_priority_SMP_Get_context( scheduler );
 
   _Scheduler_priority_SMP_Enqueue_ordered(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_Insert_priority_fifo_order,
     _Scheduler_priority_SMP_Insert_ready_fifo,
@@ -284,7 +282,7 @@ void _Scheduler_priority_SMP_Extract(
     _Scheduler_priority_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Extract(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_priority_SMP_Do_extract
   );
@@ -314,7 +312,7 @@ void _Scheduler_priority_SMP_Schedule(
     _Scheduler_priority_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Schedule(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_priority_SMP_Get_highest_ready,
     _Scheduler_priority_SMP_Move_from_ready_to_scheduled
@@ -330,5 +328,5 @@ void _Scheduler_priority_SMP_Start_idle(
   Scheduler_priority_SMP_Context *self =
     _Scheduler_priority_SMP_Get_context( scheduler );
 
-  _Scheduler_SMP_Start_idle( &self->Base, thread, cpu );
+  _Scheduler_SMP_Start_idle( &self->Base.Base, thread, cpu );
 }
diff --git a/cpukit/score/src/schedulersimplesmp.c b/cpukit/score/src/schedulersimplesmp.c
index 89453ac..e7e1ec6 100644
--- a/cpukit/score/src/schedulersimplesmp.c
+++ b/cpukit/score/src/schedulersimplesmp.c
@@ -29,10 +29,9 @@ _Scheduler_simple_SMP_Get_context( const Scheduler_Control *scheduler )
 }
 
 static Scheduler_simple_SMP_Context *
-_Scheduler_simple_SMP_Self_from_SMP_base( Scheduler_SMP_Context *smp_base )
+_Scheduler_simple_SMP_Get_self( Scheduler_Context *context )
 {
-  return (Scheduler_simple_SMP_Context *)
-    ( (char *) smp_base - offsetof( Scheduler_simple_SMP_Context, Base ) );
+  return (Scheduler_simple_SMP_Context *) context;
 }
 
 void _Scheduler_simple_SMP_Initialize( const Scheduler_Control *scheduler )
@@ -57,11 +56,11 @@ bool _Scheduler_simple_SMP_Allocate(
 }
 
 static Thread_Control *_Scheduler_simple_SMP_Get_highest_ready(
-  Scheduler_SMP_Context *smp_base
+  Scheduler_Context *context
 )
 {
   Scheduler_simple_SMP_Context *self =
-    _Scheduler_simple_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_simple_SMP_Get_self( context );
   Thread_Control *highest_ready = NULL;
   Chain_Control *ready = &self->Ready;
 
@@ -73,12 +72,12 @@ static Thread_Control *_Scheduler_simple_SMP_Get_highest_ready(
 }
 
 static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *scheduled_to_ready
 )
 {
   Scheduler_simple_SMP_Context *self =
-    _Scheduler_simple_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_simple_SMP_Get_self( context );
 
   _Chain_Extract_unprotected( &scheduled_to_ready->Object.Node );
   _Scheduler_simple_Insert_priority_lifo(
@@ -88,24 +87,27 @@ static void _Scheduler_simple_SMP_Move_from_scheduled_to_ready(
 }
 
 static void _Scheduler_simple_SMP_Move_from_ready_to_scheduled(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *ready_to_scheduled
 )
 {
+  Scheduler_simple_SMP_Context *self =
+    _Scheduler_simple_SMP_Get_self( context );
+
   _Chain_Extract_unprotected( &ready_to_scheduled->Object.Node );
   _Scheduler_simple_Insert_priority_fifo(
-    &smp_base->Scheduled,
+    &self->Base.Scheduled,
     ready_to_scheduled
   );
 }
 
 static void _Scheduler_simple_SMP_Insert_ready_lifo(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_simple_SMP_Context *self =
-    _Scheduler_simple_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_simple_SMP_Get_self( context );
 
   _Chain_Insert_ordered_unprotected(
     &self->Ready,
@@ -115,12 +117,12 @@ static void _Scheduler_simple_SMP_Insert_ready_lifo(
 }
 
 static void _Scheduler_simple_SMP_Insert_ready_fifo(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_simple_SMP_Context *self =
-    _Scheduler_simple_SMP_Self_from_SMP_base( smp_base );
+    _Scheduler_simple_SMP_Get_self( context );
 
   _Chain_Insert_ordered_unprotected(
     &self->Ready,
@@ -130,13 +132,13 @@ static void _Scheduler_simple_SMP_Insert_ready_fifo(
 }
 
 static void _Scheduler_simple_SMP_Do_extract(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread
 )
 {
   Scheduler_SMP_Node *node = _Scheduler_SMP_Node_get( thread );
 
-  (void) smp_base;
+  (void) context;
 
   if ( node->state == SCHEDULER_SMP_SCHEDULED ) {
     _Scheduler_SMP_Node_change_state( node, SCHEDULER_SMP_IN_THE_AIR );
@@ -156,7 +158,7 @@ void _Scheduler_simple_SMP_Block(
     _Scheduler_simple_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Block(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_SMP_Do_extract,
     _Scheduler_simple_SMP_Get_highest_ready,
@@ -165,7 +167,7 @@ void _Scheduler_simple_SMP_Block(
 }
 
 static void _Scheduler_simple_SMP_Enqueue_ordered(
-  Scheduler_SMP_Context *smp_base,
+  Scheduler_Context *context,
   Thread_Control *thread,
   Chain_Node_order order,
   Scheduler_SMP_Insert insert_ready,
@@ -173,7 +175,7 @@ static void _Scheduler_simple_SMP_Enqueue_ordered(
 )
 {
   _Scheduler_SMP_Enqueue_ordered(
-    smp_base,
+    context,
     thread,
     order,
     _Scheduler_simple_SMP_Get_highest_ready,
@@ -193,7 +195,7 @@ void _Scheduler_simple_SMP_Enqueue_priority_lifo(
     _Scheduler_simple_SMP_Get_context( scheduler );
 
   _Scheduler_simple_SMP_Enqueue_ordered(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_Insert_priority_lifo_order,
     _Scheduler_simple_SMP_Insert_ready_lifo,
@@ -210,7 +212,7 @@ void _Scheduler_simple_SMP_Enqueue_priority_fifo(
     _Scheduler_simple_SMP_Get_context( scheduler );
 
   _Scheduler_simple_SMP_Enqueue_ordered(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_Insert_priority_fifo_order,
     _Scheduler_simple_SMP_Insert_ready_fifo,
@@ -227,7 +229,7 @@ void _Scheduler_simple_SMP_Extract(
     _Scheduler_simple_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Extract(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_SMP_Do_extract
   );
@@ -257,7 +259,7 @@ void _Scheduler_simple_SMP_Schedule(
     _Scheduler_simple_SMP_Get_context( scheduler );
 
   _Scheduler_SMP_Schedule(
-    &self->Base,
+    &self->Base.Base,
     thread,
     _Scheduler_simple_SMP_Get_highest_ready,
     _Scheduler_simple_SMP_Move_from_ready_to_scheduled
@@ -273,5 +275,5 @@ void _Scheduler_simple_SMP_Start_idle(
   Scheduler_simple_SMP_Context *self =
     _Scheduler_simple_SMP_Get_context( scheduler );
 
-  _Scheduler_SMP_Start_idle( &self->Base, thread, cpu );
+  _Scheduler_SMP_Start_idle( &self->Base.Base, thread, cpu );
 }
-- 
1.7.7




More information about the devel mailing list