[rtems commit] score: Add and use Scheduler_EDF_Control

Sebastian Huber sebh at rtems.org
Fri Apr 4 09:42:14 UTC 2014


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Apr  3 11:53:48 2014 +0200

score: Add and use Scheduler_EDF_Control

---

 cpukit/sapi/include/confdefs.h                     |    9 ++++++---
 cpukit/score/include/rtems/score/scheduleredf.h    |   12 +++++++-----
 .../score/include/rtems/score/scheduleredfimpl.h   |   13 ++++++++++---
 cpukit/score/src/scheduleredf.c                    |   15 +++++++++------
 cpukit/score/src/scheduleredfenqueue.c             |    9 ++++-----
 cpukit/score/src/scheduleredfextract.c             |    9 ++++-----
 cpukit/score/src/scheduleredfyield.c               |    8 +++++---
 7 files changed, 45 insertions(+), 30 deletions(-)

diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index ef8f09a..16049f9 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -770,7 +770,7 @@ const rtems_libio_helper rtems_fs_init_helper =
    * define the memory used by the EDF scheduler
    */
   #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \
-    _Configure_From_workspace(0))
+    _Configure_From_workspace(sizeof(Scheduler_EDF_Control)))
   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
     _Configure_From_workspace(sizeof(Scheduler_EDF_Per_thread)))
 #endif
@@ -794,8 +794,11 @@ const rtems_libio_helper rtems_fs_init_helper =
    * define the memory used by the CBS scheduler
    */
   #define CONFIGURE_MEMORY_FOR_SCHEDULER ( \
-    _Configure_From_workspace((sizeof(Scheduler_CBS_Server) + \
-        sizeof(Scheduler_CBS_Server*)) * CONFIGURE_CBS_MAXIMUM_SERVERS))
+    _Configure_From_workspace(sizeof(Scheduler_EDF_Control)) + \
+      _Configure_From_workspace(CONFIGURE_CBS_MAXIMUM_SERVERS * \
+        sizeof(Scheduler_CBS_Server *)) + \
+      CONFIGURE_CBS_MAXIMUM_SERVERS * \
+        _Configure_From_workspace(sizeof(Scheduler_CBS_Server)))
   #define CONFIGURE_MEMORY_PER_TASK_FOR_SCHEDULER ( \
     _Configure_From_workspace(sizeof(Scheduler_CBS_Per_thread)))
 #endif
diff --git a/cpukit/score/include/rtems/score/scheduleredf.h b/cpukit/score/include/rtems/score/scheduleredf.h
index 153b882..2d5f537 100644
--- a/cpukit/score/include/rtems/score/scheduleredf.h
+++ b/cpukit/score/include/rtems/score/scheduleredf.h
@@ -66,6 +66,13 @@ extern "C" {
  */
 #define SCHEDULER_EDF_PRIO_MSB 0x80000000
 
+typedef struct {
+  /**
+   * Top of the ready queue.
+   */
+  RBTree_Control Ready;
+} Scheduler_EDF_Control;
+
 /**
  * @typedef Scheduler_EDF_Queue_state
  *
@@ -97,11 +104,6 @@ typedef struct {
 } Scheduler_EDF_Per_thread;
 
 /**
- * Top of the ready queue.
- */
-extern RBTree_Control _Scheduler_EDF_Ready_queue;
-
-/**
  * @brief Initialize EDF scheduler.
  *
  * This routine initializes the EDF scheduler.
diff --git a/cpukit/score/include/rtems/score/scheduleredfimpl.h b/cpukit/score/include/rtems/score/scheduleredfimpl.h
index 91df20a..aa1d215 100644
--- a/cpukit/score/include/rtems/score/scheduleredfimpl.h
+++ b/cpukit/score/include/rtems/score/scheduleredfimpl.h
@@ -31,12 +31,19 @@ extern "C" {
  * @{
  */
 
+RTEMS_INLINE_ROUTINE Scheduler_EDF_Control *_Scheduler_EDF_Instance( void )
+{
+  return _Scheduler.information;
+}
+
 RTEMS_INLINE_ROUTINE void _Scheduler_EDF_Schedule_body(
-  Thread_Control *thread,
-  bool force_dispatch
+  Thread_Control    *the_thread
+  bool               force_dispatch
 )
 {
-  RBTree_Node *first = _RBTree_First(&_Scheduler_EDF_Ready_queue, RBT_LEFT);
+  Scheduler_EDF_Control *scheduler =
+    _Scheduler_EDF_Instance();
+  RBTree_Node *first = _RBTree_First(&scheduler->Ready, RBT_LEFT);
   Scheduler_EDF_Per_thread *sched_info =
     _RBTree_Container_of(first, Scheduler_EDF_Per_thread, Node);
   Thread_Control *heir = (Thread_Control *) sched_info->thread;
diff --git a/cpukit/score/src/scheduleredf.c b/cpukit/score/src/scheduleredf.c
index 10d9ae0..14f784f 100644
--- a/cpukit/score/src/scheduleredf.c
+++ b/cpukit/score/src/scheduleredf.c
@@ -21,6 +21,7 @@
 #include <rtems/score/scheduleredf.h>
 #include <rtems/score/schedulerimpl.h>
 #include <rtems/score/thread.h>
+#include <rtems/score/wkspace.h>
 
 static int _Scheduler_EDF_RBTree_compare_function
 (
@@ -42,12 +43,14 @@ static int _Scheduler_EDF_RBTree_compare_function
 
 void _Scheduler_EDF_Initialize(void)
 {
+  Scheduler_EDF_Control *scheduler =
+    _Workspace_Allocate_or_fatal_error( sizeof( *scheduler ) );
+
   _RBTree_Initialize_empty(
-      &_Scheduler_EDF_Ready_queue,
-      &_Scheduler_EDF_RBTree_compare_function,
-      0
+    &scheduler->Ready,
+    _Scheduler_EDF_RBTree_compare_function,
+    0
   );
-}
 
-/* Instantiate any global variables needed by the EDF scheduler */
-RBTree_Control _Scheduler_EDF_Ready_queue;
+  _Scheduler.information = scheduler;
+}
diff --git a/cpukit/score/src/scheduleredfenqueue.c b/cpukit/score/src/scheduleredfenqueue.c
index ff10310..e7c2e44 100644
--- a/cpukit/score/src/scheduleredfenqueue.c
+++ b/cpukit/score/src/scheduleredfenqueue.c
@@ -18,19 +18,18 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/scheduler.h>
-#include <rtems/score/scheduleredf.h>
+#include <rtems/score/scheduleredfimpl.h>
 
 void _Scheduler_EDF_Enqueue(
   Thread_Control    *the_thread
 )
 {
+  Scheduler_EDF_Control *scheduler =
+    _Scheduler_EDF_Instance();
   Scheduler_EDF_Per_thread *sched_info =
     (Scheduler_EDF_Per_thread*) the_thread->scheduler_info;
   RBTree_Node *node = &(sched_info->Node);
 
-  _RBTree_Insert( &_Scheduler_EDF_Ready_queue, node );
+  _RBTree_Insert( &scheduler->Ready, node );
   sched_info->queue_state = SCHEDULER_EDF_QUEUE_STATE_YES;
 }
diff --git a/cpukit/score/src/scheduleredfextract.c b/cpukit/score/src/scheduleredfextract.c
index 434f891..0287b4e 100644
--- a/cpukit/score/src/scheduleredfextract.c
+++ b/cpukit/score/src/scheduleredfextract.c
@@ -18,19 +18,18 @@
 #include "config.h"
 #endif
 
-#include <rtems/system.h>
-#include <rtems/config.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/scheduleredf.h>
+#include <rtems/score/scheduleredfimpl.h>
 
 void _Scheduler_EDF_Extract(
   Thread_Control     *the_thread
 )
 {
+  Scheduler_EDF_Control *scheduler =
+    _Scheduler_EDF_Instance();
   Scheduler_EDF_Per_thread *sched_info =
     (Scheduler_EDF_Per_thread*) the_thread->scheduler_info;
   RBTree_Node *node = &(sched_info->Node);
 
-  _RBTree_Extract( &_Scheduler_EDF_Ready_queue, node );
+  _RBTree_Extract( &scheduler->Ready, node );
   sched_info->queue_state = SCHEDULER_EDF_QUEUE_STATE_NOT_PRESENTLY;
 }
diff --git a/cpukit/score/src/scheduleredfyield.c b/cpukit/score/src/scheduleredfyield.c
index ffe6b74..c985684 100644
--- a/cpukit/score/src/scheduleredfyield.c
+++ b/cpukit/score/src/scheduleredfyield.c
@@ -23,7 +23,9 @@
 
 void _Scheduler_EDF_Yield( Thread_Control *thread )
 {
-  ISR_Level                 level;
+  Scheduler_EDF_Control *scheduler =
+    _Scheduler_EDF_Instance();
+  ISR_Level              level;
 
   Scheduler_EDF_Per_thread *thread_info =
     (Scheduler_EDF_Per_thread *) thread->scheduler_info;
@@ -35,8 +37,8 @@ void _Scheduler_EDF_Yield( Thread_Control *thread )
    * The RBTree has more than one node, enqueue behind the tasks
    * with the same priority in case there are such ones.
    */
-  _RBTree_Extract( &_Scheduler_EDF_Ready_queue, thread_node );
-  _RBTree_Insert( &_Scheduler_EDF_Ready_queue, thread_node );
+  _RBTree_Extract( &scheduler->Ready, thread_node );
+  _RBTree_Insert( &scheduler->Ready, thread_node );
 
   _ISR_Flash( level );
 




More information about the vc mailing list