[PATCH 2/6] score: Collect scheduler related fields in TCB

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jun 13 14:37:19 UTC 2014


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 +-
 cpukit/score/include/rtems/score/thread.h        |   59 +++++++++++++---------
 cpukit/score/include/rtems/score/threadimpl.h    |    4 +-
 cpukit/score/src/threadinitialize.c              |    5 +-
 testsuites/smptests/smpscheduler01/init.c        |    5 +-
 6 files changed, 46 insertions(+), 35 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/thread.h b/cpukit/score/include/rtems/score/thread.h
index a69653b..a9a3f9f 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -462,6 +462,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 {
@@ -503,12 +535,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. */
@@ -531,26 +562,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..af24a3a 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;
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);
-- 
1.7.7




More information about the devel mailing list