[rtems commit] score: Collect scheduler related fields in TCB

Sebastian Huber sebh at rtems.org
Mon Jun 23 08:27:13 UTC 2014


Module:    rtems
Branch:    master
Commit:    2d36931823be8be0c0fdf839f941cf20dd755523
Changeset: http://git.rtems.org/rtems/commit/?id=2d36931823be8be0c0fdf839f941cf20dd755523

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jun 11 11:03:25 2014 +0200

score: Collect scheduler related fields in TCB

Add Thread_Scheduler_control to collect scheduler related fields of the
TCB.

---

 cpukit/sapi/include/confdefs.h                     |    2 +-
 cpukit/score/include/rtems/score/schedulerimpl.h   |    6 +-
 .../score/include/rtems/score/schedulersmpimpl.h   |    2 +-
 cpukit/score/include/rtems/score/thread.h          |   59 ++++++++++++--------
 cpukit/score/include/rtems/score/threadimpl.h      |    6 +-
 cpukit/score/src/threadinitialize.c                |    5 +-
 testsuites/smptests/smpscheduler01/init.c          |    5 +-
 7 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 9a4149e..f821e04 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -2581,7 +2581,7 @@ const rtems_libio_helper rtems_fs_init_helper =
 
   const Thread_Control_add_on _Thread_Control_add_ons[] = {
     {
-      offsetof( Configuration_Thread_control, Control.scheduler_node ),
+      offsetof( Configuration_Thread_control, Control.Scheduler.node ),
       offsetof( Configuration_Thread_control, Scheduler )
     }, {
       offsetof(
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index ad4c799..364c658 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -47,7 +47,7 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get(
 )
 {
 #if defined(RTEMS_SMP)
-  return the_thread->scheduler;
+  return the_thread->Scheduler.control;
 #else
   (void) the_thread;
 
@@ -375,7 +375,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Set(
   if ( current_scheduler != scheduler ) {
     _Thread_Set_state( the_thread, STATES_MIGRATING );
     _Scheduler_Node_destroy( current_scheduler, the_thread );
-    the_thread->scheduler = scheduler;
+    the_thread->Scheduler.control = scheduler;
     _Scheduler_Node_initialize( scheduler, the_thread );
     _Scheduler_Update_priority( the_thread, the_thread->current_priority );
     _Thread_Clear_state( the_thread, STATES_MIGRATING );
@@ -649,7 +649,7 @@ RTEMS_INLINE_ROUTINE Scheduler_Node *_Scheduler_Node_get(
   Thread_Control *the_thread
 )
 {
-  return the_thread->scheduler_node;
+  return the_thread->Scheduler.node;
 }
 
 /** @} */
diff --git a/cpukit/score/include/rtems/score/schedulersmpimpl.h b/cpukit/score/include/rtems/score/schedulersmpimpl.h
index 9d74434..fd42f5a 100644
--- a/cpukit/score/include/rtems/score/schedulersmpimpl.h
+++ b/cpukit/score/include/rtems/score/schedulersmpimpl.h
@@ -420,7 +420,7 @@ static inline void _Scheduler_SMP_Allocate_processor(
       _Scheduler_SMP_Update_heir( cpu_self, cpu_of_scheduled, scheduled );
     } else {
       /* We have to force a migration to our processor set */
-      _Assert( scheduled->debug_real_cpu->heir != scheduled );
+      _Assert( scheduled->Scheduler.debug_real_cpu->heir != scheduled );
       heir = scheduled;
     }
   } else {
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 6ac4ecc..28844c3 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -446,6 +446,38 @@ typedef struct {
 } Thread_Life_control;
 
 /**
+ * @brief Thread scheduler control.
+ */
+typedef struct {
+#if defined(RTEMS_SMP)
+  /**
+   * @brief The current scheduler control of this thread.
+   */
+  const struct Scheduler_Control *control;
+#endif
+
+  /**
+   * @brief The current scheduler node of this thread.
+   */
+  struct Scheduler_Node *node;
+
+#if defined(RTEMS_SMP)
+  /**
+   * @brief The processor assigned by the current scheduler.
+   */
+  Per_CPU_Control *cpu;
+
+#if defined(RTEMS_DEBUG)
+  /**
+   * @brief The processor on which this thread executed the last time or is
+   * executing.
+   */
+  Per_CPU_Control *debug_real_cpu;
+#endif
+#endif
+} Thread_Scheduler_control;
+
+/**
  *  This structure defines the Thread Control Block (TCB).
  */
 struct Thread_Control_struct {
@@ -487,12 +519,11 @@ struct Thread_Control_struct {
 #endif
   /** This field is true if the thread is preemptible. */
   bool                                  is_preemptible;
-#if defined(RTEMS_SMP)
+
   /**
-   * @brief The scheduler of this thread.
+   * @brief Scheduler related control.
    */
-  const struct Scheduler_Control       *scheduler;
-#endif
+  Thread_Scheduler_control              Scheduler;
 
 #if __RTEMS_ADA__
   /** This field is the GNAT self context pointer. */
@@ -515,26 +546,6 @@ struct Thread_Control_struct {
    */
   Thread_CPU_usage_t                    cpu_time_used;
 
-  /**
-   * @brief The scheduler node of this thread for the real scheduler.
-   */
-  struct Scheduler_Node                *scheduler_node;
-
-#ifdef RTEMS_SMP
-  /**
-   * @brief The processor assigned by the scheduler.
-   */
-  Per_CPU_Control                      *cpu;
-
-#ifdef RTEMS_DEBUG
-  /**
-   * @brief The processor on which this thread executed the last time or is
-   * executing.
-   */
-  Per_CPU_Control                      *debug_real_cpu;
-#endif
-#endif
-
   /** This field contains information about the starting state of
    *  this thread.
    */
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 829e445..b602b34 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -408,7 +408,7 @@ RTEMS_INLINE_ROUTINE Per_CPU_Control *_Thread_Get_CPU(
 )
 {
 #if defined(RTEMS_SMP)
-  return thread->cpu;
+  return thread->Scheduler.cpu;
 #else
   (void) thread;
 
@@ -422,7 +422,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Set_CPU(
 )
 {
 #if defined(RTEMS_SMP)
-  thread->cpu = cpu;
+  thread->Scheduler.cpu = cpu;
 #else
   (void) thread;
   (void) cpu;
@@ -804,7 +804,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Debug_set_real_processor(
 )
 {
 #if defined(RTEMS_SMP) && defined(RTEMS_DEBUG)
-  the_thread->debug_real_cpu = cpu;
+  the_thread->Scheduler.debug_real_cpu = cpu;
 #else
   (void) the_thread;
   (void) cpu;
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index 2a79549..e6c4985 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -159,6 +159,7 @@ bool _Thread_Initialize(
    *  General initialization
    */
 
+  the_thread->Start.isr_level        = isr_level;
   the_thread->Start.is_preemptible   = is_preemptible;
   the_thread->Start.budget_algorithm = budget_algorithm;
   the_thread->Start.budget_callout   = budget_callout;
@@ -179,10 +180,8 @@ bool _Thread_Initialize(
     #endif
   }
 
-  the_thread->Start.isr_level         = isr_level;
-
 #if defined(RTEMS_SMP)
-  the_thread->scheduler               = scheduler;
+  the_thread->Scheduler.control = scheduler;
   _Resource_Node_initialize( &the_thread->Resource_node );
   _CPU_Context_Set_is_executing( &the_thread->Registers, false );
 #endif
diff --git a/testsuites/smptests/smpscheduler01/init.c b/testsuites/smptests/smpscheduler01/init.c
index 10ac735..db61933 100644
--- a/testsuites/smptests/smpscheduler01/init.c
+++ b/testsuites/smptests/smpscheduler01/init.c
@@ -17,6 +17,7 @@
 #endif
 
 #include <rtems.h>
+#include <rtems/score/threadimpl.h>
 
 #include "tmacros.h"
 
@@ -89,8 +90,8 @@ static bool is_per_cpu_state_ok(void)
         ++count;
       }
 
-      ok = ok && executing->cpu == cpu;
-      ok = ok && heir->cpu == cpu;
+      ok = ok && _Thread_Get_CPU( executing ) == cpu;
+      ok = ok && _Thread_Get_CPU( heir ) == cpu;
     }
 
     ok = ok && (count == 1);



More information about the vc mailing list