[rtems commit] score: score: Add get/set affinity to Scheduler Framework.

Jennifer Averett jennifer at rtems.org
Thu Apr 3 16:13:11 UTC 2014


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

Author:    Jennifer Averett <jennifer.averett at oarcorp.com>
Date:      Thu Mar  6 08:37:21 2014 -0600

score: score: Add get/set affinity to Scheduler Framework.

---

 cpukit/score/Makefile.am                           |    2 +
 cpukit/score/include/rtems/score/cpusetimpl.h      |    2 +-
 cpukit/score/include/rtems/score/scheduler.h       |   61 ++++++++++++++++++++
 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/cpuset.c                          |   12 ++--
 cpukit/score/src/schedulerdefaultgetaffinity.c     |   41 +++++++++++++
 cpukit/score/src/schedulerdefaultsetaffinity.c     |   32 ++++++++++
 10 files changed, 192 insertions(+), 11 deletions(-)

diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 6c9e682..a09ddc3 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -130,6 +130,8 @@ libscore_a_SOURCES += src/schedulersimplesmp.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/cpusetimpl.h b/cpukit/score/include/rtems/score/cpusetimpl.h
index a611354..06fe3f5 100644
--- a/cpukit/score/include/rtems/score/cpusetimpl.h
+++ b/cpukit/score/include/rtems/score/cpusetimpl.h
@@ -34,7 +34,7 @@ extern "C" {
  * the system correct size, that at least one
  * valid cpu is set and that no invalid cpus are set.
  */
-int _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize );
+bool _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize );
 
 /**
  * _CPU_set_Show
diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
index 01d0c3a..7aeb560 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,27 @@ 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().
+   */
+  bool ( *get_affinity )( Thread_Control *thread, size_t cpusetsize, cpu_set_t *cpuset );
+  
+  /**
+   * @brief Set the processor affinity for a thread.
+   *
+   * @see _Scheduler_Set_affinity().
+   */
+  bool ( *set_affinity )(
+    Thread_Control  *thread,
+    size_t           cpusetsize,
+    const cpu_set_t *cpuset
+  );
+#endif
+
 } Scheduler_Operations;
 
 /**
@@ -190,6 +214,43 @@ void _Scheduler_default_Start_idle(
  */
 extern const bool _Scheduler_FIXME_thread_priority_queues_are_broken;
 
+#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
+   */
+  bool _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.
+   */
+  bool _Scheduler_default_Set_affinity(
+    Thread_Control  *thread,
+    size_t           cpusetsize,
+    const 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 a031715..72f239f 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 thread.
+   * @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 thread.
+   * @parma[in] cpuset The processor affinity for this thread
+   */
+  RTEMS_INLINE_ROUTINE int _Scheduler_Set_affinity(
+    Thread_Control   *thread,
+    size_t            cpusetsize,
+    const 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 40e784b..0bc4552 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 \
   }
 
 typedef struct {
diff --git a/cpukit/score/include/rtems/score/schedulerprioritysmp.h b/cpukit/score/include/rtems/score/schedulerprioritysmp.h
index f30b706..409d9fe 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_priority_SMP_Start_idle \
+    _Scheduler_priority_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 01ebf03..000a975 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_simple_smp_Start_idle \
+    _Scheduler_simple_smp_Start_idle, \
+    _Scheduler_default_Get_affinity, \
+    _Scheduler_default_Set_affinity \
   }
 
 void _Scheduler_simple_smp_Initialize( void );
diff --git a/cpukit/score/src/cpuset.c b/cpukit/score/src/cpuset.c
index 110f51c..7addb0d 100644
--- a/cpukit/score/src/cpuset.c
+++ b/cpukit/score/src/cpuset.c
@@ -57,27 +57,27 @@ void _CPU_set_Handler_initialization()
  * the system correct size, that at least one
  * valid cpu is set and that no invalid cpus are set.
  */
-int _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize )
+bool _CPU_set_Is_valid( const cpu_set_t *cpuset, size_t setsize )
 {
   cpu_set_t             temp;
 
   if ( !cpuset )
-    return -1;
+    false;
 
   if (setsize != cpuset_default.setsize )
-    return -1;
+    return false;
 
   /* Validate at least 1 valid cpu is set in cpuset */
   CPU_AND_S( cpuset_default.setsize, &temp, cpuset, cpuset_default.set );
 
   if ( CPU_COUNT_S( setsize, &temp ) == 0 )
-    return -1;
+    return false;
 
   /* Validate that no invalid cpu's are set in cpuset */
   if ( !CPU_EQUAL_S( setsize, &temp, cpuset ) )
-    return -1;
+    return false;
 
-  return 0;
+  return true;
 }
 
 /**
diff --git a/cpukit/score/src/schedulerdefaultgetaffinity.c b/cpukit/score/src/schedulerdefaultgetaffinity.c
new file mode 100644
index 0000000..44305d5
--- /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>
+
+bool _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 false;
+  }
+
+  CPU_COPY( cpuset, ctl->set );
+  
+  return true; 
+}
diff --git a/cpukit/score/src/schedulerdefaultsetaffinity.c b/cpukit/score/src/schedulerdefaultsetaffinity.c
new file mode 100644
index 0000000..ac731f0
--- /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>
+
+bool _Scheduler_default_Set_affinity(
+  Thread_Control  *thread,
+  size_t           cpusetsize,
+  const cpu_set_t *cpuset
+)
+{
+  return _CPU_set_Is_valid( cpuset, cpusetsize );
+}




More information about the vc mailing list