[PATCH 07/12] scheduler: Add start idle thread operation

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Jun 12 15:12:33 UTC 2013


Add and use _Scheduler_Start_idle().
---
 cpukit/posix/src/pthreadcreate.c                   |    3 +-
 cpukit/rtems/src/taskstart.c                       |   20 +++++++++++++----
 cpukit/score/Makefile.am                           |    1 +
 cpukit/score/include/rtems/score/scheduler.h       |   17 +++++++++++++++
 cpukit/score/include/rtems/score/schedulercbs.h    |    3 +-
 cpukit/score/include/rtems/score/scheduleredf.h    |    3 +-
 .../score/include/rtems/score/schedulerpriority.h  |    3 +-
 cpukit/score/include/rtems/score/schedulersimple.h |    3 +-
 cpukit/score/include/rtems/score/thread.h          |    6 ++++-
 cpukit/score/inline/rtems/score/scheduler.inl      |   16 ++++++++++++++
 cpukit/score/src/schedulerdefaultstartidle.c       |   22 ++++++++++++++++++++
 cpukit/score/src/threadcreateidle.c                |    3 +-
 cpukit/score/src/threadstart.c                     |   10 +++++++-
 13 files changed, 96 insertions(+), 14 deletions(-)
 create mode 100644 cpukit/score/src/schedulerdefaultstartidle.c

diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 9585772..53e4cdd 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -203,7 +203,8 @@ int pthread_create(
     THREAD_START_POINTER,
     start_routine,
     arg,
-    0                     /* unused */
+    0,                    /* unused */
+    NULL
   );
 
   #if defined(RTEMS_DEBUG)
diff --git a/cpukit/rtems/src/taskstart.c b/cpukit/rtems/src/taskstart.c
index 3700139..e9ff378 100644
--- a/cpukit/rtems/src/taskstart.c
+++ b/cpukit/rtems/src/taskstart.c
@@ -58,6 +58,7 @@ rtems_status_code rtems_task_start(
 {
   register Thread_Control *the_thread;
   Objects_Locations        location;
+  bool                     successfully_started;
 
   if ( entry_point == NULL )
     return RTEMS_INVALID_ADDRESS;
@@ -66,13 +67,22 @@ rtems_status_code rtems_task_start(
   switch ( location ) {
 
     case OBJECTS_LOCAL:
-      if ( _Thread_Start(
-             the_thread, THREAD_START_NUMERIC, entry_point, NULL, argument ) ) {
-        _Objects_Put( &the_thread->Object );
+      successfully_started = _Thread_Start(
+        the_thread,
+        THREAD_START_NUMERIC,
+        entry_point,
+        NULL,
+        argument,
+        NULL
+      );
+
+      _Objects_Put( &the_thread->Object );
+
+      if ( successfully_started ) {
         return RTEMS_SUCCESSFUL;
+      } else {
+        return RTEMS_INCORRECT_STATE;
       }
-      _Objects_Put( &the_thread->Object );
-      return RTEMS_INCORRECT_STATE;
 
 #if defined(RTEMS_MULTIPROCESSING)
     case OBJECTS_REMOTE:
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 9aa5890..9bc40b1 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -199,6 +199,7 @@ libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \
 
 ## SCHEDULER_C_FILES
 libscore_a_SOURCES += src/scheduler.c
+libscore_a_SOURCES += src/schedulerdefaultstartidle.c
 
 ## SCHEDULERPRIORITY_C_FILES
 libscore_a_SOURCES += src/schedulerpriority.c \
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
index 5c35a36..9e08b23 100644
--- a/cpukit/score/include/rtems/score/scheduler.h
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -89,6 +89,12 @@ typedef struct {
   /** perform scheduler update actions required at each clock tick */
   void ( *tick )(void);
 
+  /**
+   * @brief Starts the idle thread for a particular processor.
+   *
+   * @see _Scheduler_Start_idle().
+   */
+  void ( *start_idle )( Thread_Control *thread, Per_CPU_Control *processor );
 } Scheduler_Operations;
 
 /**
@@ -139,6 +145,17 @@ extern Scheduler_Control  _Scheduler;
  */
 void _Scheduler_Handler_initialization( void );
 
+/**
+ * @brief Unblocks the thread.
+ *
+ * @param[in/out] thread An idle thread.
+ * @param[in] processor This parameter is unused.
+ */
+void _Scheduler_default_Start_idle(
+  Thread_Control  *thread,
+  Per_CPU_Control *processor
+);
+
 #ifndef __RTEMS_APPLICATION__
 #include <rtems/score/scheduler.inl>
 #endif
diff --git a/cpukit/score/include/rtems/score/schedulercbs.h b/cpukit/score/include/rtems/score/schedulercbs.h
index 53452e0..41f8ab0 100644
--- a/cpukit/score/include/rtems/score/schedulercbs.h
+++ b/cpukit/score/include/rtems/score/schedulercbs.h
@@ -60,7 +60,8 @@ extern "C" {
     _Scheduler_EDF_Extract,          /* extract entry point */ \
     _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
     _Scheduler_CBS_Release_job,      /* new period of task */ \
-    _Scheduler_priority_Tick         /* tick entry point */ \
+    _Scheduler_priority_Tick,        /* tick entry point */ \
+    _Scheduler_default_Start_idle    /* start idle entry point */ \
   }
 
 /* Return values for CBS server. */
diff --git a/cpukit/score/include/rtems/score/scheduleredf.h b/cpukit/score/include/rtems/score/scheduleredf.h
index 24f9a1a..e84b3f5 100644
--- a/cpukit/score/include/rtems/score/scheduleredf.h
+++ b/cpukit/score/include/rtems/score/scheduleredf.h
@@ -53,7 +53,8 @@ extern "C" {
     _Scheduler_EDF_Extract,          /* extract entry point */ \
     _Scheduler_EDF_Priority_compare, /* compares two priorities */ \
     _Scheduler_EDF_Release_job,      /* new period of task */ \
-    _Scheduler_priority_Tick         /* tick entry point */ \
+    _Scheduler_priority_Tick,        /* tick entry point */ \
+    _Scheduler_default_Start_idle    /* start idle entry point */ \
   }
 
 /**
diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
index f97bb7f..81c3582 100644
--- a/cpukit/score/include/rtems/score/schedulerpriority.h
+++ b/cpukit/score/include/rtems/score/schedulerpriority.h
@@ -52,7 +52,8 @@ extern "C" {
     _Scheduler_priority_Extract,          /* extract entry point */ \
     _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     _Scheduler_priority_Release_job,      /* new period of task */ \
-    _Scheduler_priority_Tick              /* tick entry point */ \
+    _Scheduler_priority_Tick,             /* tick entry point */ \
+    _Scheduler_default_Start_idle         /* start idle entry point */ \
   }
 
 /**
diff --git a/cpukit/score/include/rtems/score/schedulersimple.h b/cpukit/score/include/rtems/score/schedulersimple.h
index df52a58..6682074 100644
--- a/cpukit/score/include/rtems/score/schedulersimple.h
+++ b/cpukit/score/include/rtems/score/schedulersimple.h
@@ -50,7 +50,8 @@ extern "C" {
     _Scheduler_simple_Extract,            /* extract entry point */ \
     _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     _Scheduler_priority_Release_job,      /* new period of task */ \
-    _Scheduler_priority_Tick              /* tick entry point */ \
+    _Scheduler_priority_Tick,             /* tick entry point */ \
+    _Scheduler_default_Start_idle         /* start idle entry point */ \
   }
 
 /**
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index 3cddb5a..60583a7 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -571,13 +571,17 @@ bool _Thread_Initialize(
  *  @param entry_point
  *  @param pointer_argument
  *  @param numeric_argument
+ *  @param[in/out] processor The processor if used to start an idle thread
+ *  during system initialization.  Must be set to @c NULL to start a normal
+ *  thread.
  */
 bool _Thread_Start(
   Thread_Control            *the_thread,
   Thread_Start_types         the_prototype,
   void                      *entry_point,
   void                      *pointer_argument,
-  Thread_Entry_numeric_type  numeric_argument
+  Thread_Entry_numeric_type  numeric_argument,
+  Per_CPU_Control           *processor
 );
 
 /**
diff --git a/cpukit/score/inline/rtems/score/scheduler.inl b/cpukit/score/inline/rtems/score/scheduler.inl
index e3ced39..3201c23 100644
--- a/cpukit/score/inline/rtems/score/scheduler.inl
+++ b/cpukit/score/inline/rtems/score/scheduler.inl
@@ -208,6 +208,22 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Tick( void )
   _Scheduler.Operations.tick();
 }
 
+/**
+ * @brief Starts the idle thread for a particular processor.
+ *
+ * @param[in/out] thread The idle thread for the processor.
+ * @parma[in/out] processor The processor for the idle thread.
+ *
+ * @see _Thread_Create_idle().
+ */
+RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle(
+  Thread_Control *thread,
+  Per_CPU_Control *processor
+)
+{
+  ( *_Scheduler.Operations.start_idle )( thread, processor );
+}
+
 /** @} */
 
 #endif
diff --git a/cpukit/score/src/schedulerdefaultstartidle.c b/cpukit/score/src/schedulerdefaultstartidle.c
new file mode 100644
index 0000000..043fe68
--- /dev/null
+++ b/cpukit/score/src/schedulerdefaultstartidle.c
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2013 embedded brains GmbH
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/scheduler.h>
+
+void _Scheduler_default_Start_idle(
+  Thread_Control  *thread,
+  Per_CPU_Control *processor
+)
+{
+  (void) processor;
+  _Scheduler_Unblock( thread );
+}
diff --git a/cpukit/score/src/threadcreateidle.c b/cpukit/score/src/threadcreateidle.c
index 11460e0..a79f713 100644
--- a/cpukit/score/src/threadcreateidle.c
+++ b/cpukit/score/src/threadcreateidle.c
@@ -72,7 +72,8 @@ static void _Thread_Create_idle_for_cpu( Per_CPU_Control *per_cpu )
     THREAD_START_NUMERIC,
     rtems_configuration_get_idle_task(),
     NULL,
-    0
+    0,
+    per_cpu
   );
 }
 
diff --git a/cpukit/score/src/threadstart.c b/cpukit/score/src/threadstart.c
index d9ce62a..4e24f39 100644
--- a/cpukit/score/src/threadstart.c
+++ b/cpukit/score/src/threadstart.c
@@ -38,7 +38,8 @@ bool _Thread_Start(
   Thread_Start_types         the_prototype,
   void                      *entry_point,
   void                      *pointer_argument,
-  Thread_Entry_numeric_type  numeric_argument
+  Thread_Entry_numeric_type  numeric_argument,
+  Per_CPU_Control           *processor
 )
 {
   if ( _States_Is_dormant( the_thread->current_state ) ) {
@@ -51,7 +52,12 @@ bool _Thread_Start(
 
     _Thread_Load_environment( the_thread );
 
-    _Thread_Ready( the_thread );
+    if ( processor == NULL ) {
+      _Thread_Ready( the_thread );
+    } else {
+      the_thread->current_state = STATES_READY;
+      _Scheduler_Start_idle( the_thread, processor );
+    }
 
     _User_extensions_Thread_start( the_thread );
 
-- 
1.7.7




More information about the devel mailing list