[PATCH 01/10] score: Add get/set affinity to Scheduler Framework.

Jennifer jennifer.averett at oarcorp.com
Mon Mar 24 18:39:32 UTC 2014


From: Jennifer Averett <jennifer.averett at oarcorp.com>

---
 cpukit/score/Makefile.am                           |  2 +
 cpukit/score/include/rtems/score/scheduler.h       | 58 ++++++++++++++++++++++
 cpukit/score/include/rtems/score/schedulerimpl.h   | 32 ++++++++++++
 .../score/include/rtems/score/schedulerpriority.h  | 11 +++-
 .../include/rtems/score/schedulerprioritysmp.h     |  6 ++-
 .../score/include/rtems/score/schedulersimplesmp.h |  4 +-
 cpukit/score/src/schedulerdefaultgetaffinity.c     | 41 +++++++++++++++
 cpukit/score/src/schedulerdefaultsetaffinity.c     | 32 ++++++++++++
 8 files changed, 182 insertions(+), 4 deletions(-)
 create mode 100644 cpukit/score/src/schedulerdefaultgetaffinity.c
 create mode 100644 cpukit/score/src/schedulerdefaultsetaffinity.c

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index aeee4b6..67cc802 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -131,6 +131,8 @@ libscore_a_SOURCES += src/schedulersmpstartidle.c
 libscore_a_SOURCES += src/smp.c
 libscore_a_SOURCES += src/cpuset.c
 libscore_a_SOURCES += src/cpusetprintsupport.c
+libscore_a_SOURCES += src/schedulerdefaultgetaffinity.c
+libscore_a_SOURCES += src/schedulerdefaultsetaffinity.c
 endif
 
 ## CORE_APIMUTEX_C_FILES
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
index ced3c00..a0e36f3 100644
--- a/cpukit/score/include/rtems/score/scheduler.h
+++ b/cpukit/score/include/rtems/score/scheduler.h
@@ -22,6 +22,9 @@
 #include <rtems/score/percpu.h>
 #include <rtems/score/chain.h>
 #include <rtems/score/priority.h>
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+  #include <sys/cpuset.h>
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -98,6 +101,24 @@ typedef struct {
    * @see _Scheduler_Start_idle().
    */
   void ( *start_idle )( Thread_Control *thread, Per_CPU_Control *processor );
+
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+  /**
+   * @brief Obtain the processor affinity for a thread.
+   *
+   * @see _Scheduler_Get_affinity().
+   */
+  int ( *get_affinity )( Thread_Control *thread, size_t cpusetsize, cpu_set_t *cpuset );
+
+  
+  /**
+   * @brief Set the processor affinity for a thread.
+   *
+   * @see _Scheduler_Set_affinity().
+   */
+  int ( *set_affinity )( Thread_Control *thread, size_t cpusetsize, cpu_set_t *cpuset );
+#endif
+
 } Scheduler_Operations;
 
 /**
@@ -184,6 +205,43 @@ void _Scheduler_default_Start_idle(
   Per_CPU_Control *processor
 );
 
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+
+  /**
+   * @brief Get affinity for the default scheduler.
+   *
+   * @param[in] thread The associated thread.
+   * @param[in] cpusetsize The size of the cpuset.
+   * @param[out] cpuset Affinity set containing all CPUs.
+   *
+   * @retval 0 Successfully got cpuset
+   * @retval -1 The cpusetsize is invalid for the system
+   */
+  int _Scheduler_default_Get_affinity(
+    Thread_Control *thread,
+    size_t          cpusetsize,
+    cpu_set_t      *cpuset
+  );
+
+  /** 
+   * @brief Set affinity for the default scheduler.
+   *
+   * @param[in] thread The associated thread.
+   * @param[in] cpusetsize The size of the cpuset.
+   * @param[in] cpuset Affinity new affinity set.
+   *
+   * @retval 0 Successful
+   *
+   *  This method always returns successful and does not save
+   *  the cpuset.
+   */
+  int _Scheduler_default_Set_affinity(
+    Thread_Control *thread,
+    size_t          cpusetsize,
+    cpu_set_t      *cpuset
+  );
+#endif
+
 /**@}*/
 
 #ifdef __cplusplus
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index 7fbaf54..021b50f 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -240,6 +240,38 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle(
   ( *_Scheduler.Operations.start_idle )( thread, processor );
 }
 
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+  /**
+   * @brief Obtain the processor affinity for a thread.
+   *
+   * @param[in,out] thread The idle thread for the processor.
+   * @parma[out] cpuset The processor affinity for this thread
+   */
+  RTEMS_INLINE_ROUTINE int _Scheduler_Get_affinity(
+    Thread_Control *thread,
+    size_t          cpusetsize,
+    cpu_set_t      *cpuset
+  )
+  {
+    return (*_Scheduler.Operations.get_affinity)( thread, cpusetsize, cpuset );
+  }
+
+  /**
+   * @brief Set the processor affinity for a thread.
+   *
+   * @param[in,out] thread The idle thread for the processor.
+   * @parma[in] cpuset The processor affinity for this thread
+   */
+  RTEMS_INLINE_ROUTINE int _Scheduler_Set_affinity(
+    Thread_Control *thread,
+    size_t          cpusetsize,
+    cpu_set_t      *cpuset
+  )
+  {
+    return (*_Scheduler.Operations.set_affinity)( thread, cpusetsize, cpuset );
+  }
+#endif
+
 RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir(
   Thread_Control *heir,
   bool force_dispatch
diff --git a/cpukit/score/include/rtems/score/schedulerpriority.h b/cpukit/score/include/rtems/score/schedulerpriority.h
index 605ab39..a9a46e9 100644
--- a/cpukit/score/include/rtems/score/schedulerpriority.h
+++ b/cpukit/score/include/rtems/score/schedulerpriority.h
@@ -34,6 +34,14 @@ extern "C" {
  */
 /**@{*/
 
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+  #define SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS \
+    _Scheduler_default_Get_affinity,     /* get affinity entry point */ \
+    _Scheduler_default_Set_affinity      /* set affinity entry point */
+#else
+  #define SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS
+#endif
+
 /**
  *  Entry points for the Deterministic Priority Based Scheduler.
  */
@@ -53,7 +61,8 @@ extern "C" {
     _Scheduler_priority_Priority_compare, /* compares two priorities */ \
     _Scheduler_default_Release_job,       /* new period of task */ \
     _Scheduler_default_Tick,              /* tick entry point */ \
-    _Scheduler_default_Start_idle         /* start idle entry point */ \
+    _Scheduler_default_Start_idle,        /* start idle entry point */ \
+    SCHEDULER_PRIORITY_ADDITIONAL_SMP_ENTRY_POINTS \
   }
 
 /**
diff --git a/cpukit/score/include/rtems/score/schedulerprioritysmp.h b/cpukit/score/include/rtems/score/schedulerprioritysmp.h
index b0e5fad..bee4232 100644
--- a/cpukit/score/include/rtems/score/schedulerprioritysmp.h
+++ b/cpukit/score/include/rtems/score/schedulerprioritysmp.h
@@ -48,7 +48,7 @@ extern "C" {
  */
 
 /**
- * @brief Entry points for the Simple SMP Scheduler.
+ * @brief Entry points for the Priority SMP Scheduler.
  */
 #define SCHEDULER_PRIORITY_SMP_ENTRY_POINTS \
   { \
@@ -66,7 +66,9 @@ extern "C" {
     _Scheduler_priority_Priority_compare, \
     _Scheduler_default_Release_job, \
     _Scheduler_default_Tick, \
-    _Scheduler_SMP_Start_idle \
+    _Scheduler_SMP_Start_idle, \
+    _Scheduler_default_Get_affinity, \
+    _Scheduler_default_Set_affinity \
   }
 
 void _Scheduler_priority_SMP_Initialize( void );
diff --git a/cpukit/score/include/rtems/score/schedulersimplesmp.h b/cpukit/score/include/rtems/score/schedulersimplesmp.h
index 1a69358..e8cd54b 100644
--- a/cpukit/score/include/rtems/score/schedulersimplesmp.h
+++ b/cpukit/score/include/rtems/score/schedulersimplesmp.h
@@ -68,7 +68,9 @@ extern "C" {
     _Scheduler_priority_Priority_compare, \
     _Scheduler_default_Release_job, \
     _Scheduler_default_Tick, \
-    _Scheduler_SMP_Start_idle \
+    _Scheduler_SMP_Start_idle, \
+    _Scheduler_default_Get_affinity, \
+    _Scheduler_default_Set_affinity \
   }
 
 void _Scheduler_simple_smp_Initialize( void );
diff --git a/cpukit/score/src/schedulerdefaultgetaffinity.c b/cpukit/score/src/schedulerdefaultgetaffinity.c
new file mode 100644
index 0000000..fde9b01
--- /dev/null
+++ b/cpukit/score/src/schedulerdefaultgetaffinity.c
@@ -0,0 +1,41 @@
+/**
+ * @file
+ *
+ * @brief Scheduler Default Get Affinity Operation
+ *
+ * @ingroup ScoreScheduler
+ */
+
+/*
+ *  COPYRIGHT (c) 2014.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/schedulerimpl.h>
+#include <rtems/score/cpusetimpl.h>
+
+int _Scheduler_default_Get_affinity(
+  Thread_Control *thread,
+  size_t          cpusetsize,
+  cpu_set_t      *cpuset
+)
+{
+  const CPU_set_Control *ctl;
+
+  ctl = _CPU_set_Default();
+  if ( cpusetsize == ctl->setsize ) {
+    return -1;
+  }
+
+  CPU_COPY( cpuset, ctl->set );
+  
+  return 0; 
+}
diff --git a/cpukit/score/src/schedulerdefaultsetaffinity.c b/cpukit/score/src/schedulerdefaultsetaffinity.c
new file mode 100644
index 0000000..9c1eef0
--- /dev/null
+++ b/cpukit/score/src/schedulerdefaultsetaffinity.c
@@ -0,0 +1,32 @@
+/**
+ * @file
+ *
+ * @brief Scheduler Default Set Affinity Operation
+ *
+ * @ingroup ScoreScheduler
+ */
+
+/*
+ *  COPYRIGHT (c) 2014.
+ *  On-Line Applications Research Corporation (OAR).
+ *
+ *  The license and distribution terms for this file may be
+ *  found in the file LICENSE in this distribution or at
+ *  http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems/score/schedulerimpl.h>
+#include <rtems/score/cpusetimpl.h>
+
+int _Scheduler_default_Set_affinity(
+  Thread_Control *thread,
+  size_t          cpusetsize,
+  cpu_set_t      *cpuset
+)
+{
+  return 0;
+}
-- 
1.8.1.4




More information about the devel mailing list