[PATCH 7/9] rtems: Add scheduler get processors

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Apr 14 13:11:32 UTC 2014


---
 cpukit/rtems/Makefile.am                         |    1 +
 cpukit/rtems/include/rtems/rtems/tasks.h         |   24 ++++++++++
 cpukit/rtems/src/schedulergetprocessorset.c      |   54 ++++++++++++++++++++++
 cpukit/score/include/rtems/score/schedulerimpl.h |   13 +++++
 testsuites/sptests/spscheduler01/init.c          |   53 +++++++++++++++++++++
 5 files changed, 145 insertions(+), 0 deletions(-)
 create mode 100644 cpukit/rtems/src/schedulergetprocessorset.c

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index 57b15ca..ff3e605 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -116,6 +116,7 @@ librtems_a_SOURCES += src/taskvariableget.c
 librtems_a_SOURCES += src/taskvariable_invoke_dtor.c
 endif
 librtems_a_SOURCES += src/taskdata.c
+librtems_a_SOURCES += src/schedulergetprocessorset.c
 librtems_a_SOURCES += src/schedulerident.c
 
 ## RATEMON_C_FILES
diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h
index 5816e7d..21c0166 100644
--- a/cpukit/rtems/include/rtems/rtems/tasks.h
+++ b/cpukit/rtems/include/rtems/rtems/tasks.h
@@ -565,6 +565,30 @@ rtems_status_code rtems_scheduler_ident(
   rtems_id   *id
 );
 
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+/**
+ * @brief Gets the set of processors owned by the scheduler.
+ *
+ * @param[in] scheduler_id Identifier of the scheduler.
+ * @param[in] cpusetsize Size of the specified processor set buffer in
+ * bytes.  This value must be positive.
+ * @param[out] cpuset The processor set owned by the scheduler.  A set bit in
+ * the processor set means that this processor is owned by the scheduler and a
+ * cleared bit means the opposite.
+ *
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
+ * @retval RTEMS_INVALID_ID Invalid scheduler identifier.
+ * @retval RTEMS_INVALID_NUMBER The processor set buffer is too small for the
+ * set of processors owned by the scheduler.
+ */
+rtems_status_code rtems_scheduler_get_processor_set(
+  rtems_id   scheduler_id,
+  size_t     cpusetsize,
+  cpu_set_t *cpuset
+);
+#endif
+
 /**@}*/
 
 /**
diff --git a/cpukit/rtems/src/schedulergetprocessorset.c b/cpukit/rtems/src/schedulergetprocessorset.c
new file mode 100644
index 0000000..e459b17
--- /dev/null
+++ b/cpukit/rtems/src/schedulergetprocessorset.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * 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
+
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/cpusetimpl.h>
+#include <rtems/score/schedulerimpl.h>
+
+rtems_status_code rtems_scheduler_get_processor_set(
+  rtems_id   scheduler_id,
+  size_t     cpusetsize,
+  cpu_set_t *cpuset
+)
+{
+  rtems_status_code sc;
+
+  if ( cpuset != NULL ) {
+    const Scheduler_Control *scheduler;
+
+    if ( _Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
+      if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
+        _Scheduler_Get_processor_set( scheduler, cpusetsize, cpuset );
+
+        sc = RTEMS_SUCCESSFUL;
+      } else {
+        sc = RTEMS_INVALID_NUMBER;
+      }
+    } else {
+      sc = RTEMS_INVALID_ID;
+    }
+  } else {
+    sc = RTEMS_INVALID_ADDRESS;
+  }
+
+  return sc;
+}
+
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index 01be515..2b8782f 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -461,6 +461,19 @@ RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index )
   );
 }
 
+RTEMS_INLINE_ROUTINE bool _Scheduler_Get_by_id(
+  Objects_Id                id,
+  const Scheduler_Control **scheduler
+)
+{
+  uint32_t minimum_id = _Scheduler_Build_id( 0 );
+  uint32_t index = id - minimum_id;
+
+  *scheduler = &_Scheduler_Table[ index ];
+
+  return index < _Scheduler_Count;
+}
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c
index 1b1be3c..c068f9e 100644
--- a/testsuites/sptests/spscheduler01/init.c
+++ b/testsuites/sptests/spscheduler01/init.c
@@ -123,6 +123,58 @@ static void test_scheduler_ident(void)
   rtems_test_assert(scheduler_id == expected_id);
 }
 
+static void test_scheduler_get_processors(void)
+{
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+  rtems_status_code sc;
+  rtems_name name = BLUE;
+  rtems_id scheduler_id;
+  cpu_set_t cpusetone;
+  cpu_set_t cpuset;
+  size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
+  size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
+  cpu_set_t *cpusetbigone;
+  cpu_set_t *cpusetbig;
+
+  CPU_ZERO(&cpusetone);
+  CPU_SET(0, &cpusetone);
+
+  sc = rtems_scheduler_ident(name, &scheduler_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_scheduler_get_processor_set(scheduler_id, sizeof(cpuset), NULL);
+  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
+
+  sc = rtems_scheduler_get_processor_set(invalid_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_ID);
+
+  sc = rtems_scheduler_get_processor_set(scheduler_id, 0, &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
+
+  sc = rtems_scheduler_get_processor_set(scheduler_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
+
+  cpusetbigone = CPU_ALLOC(big);
+  rtems_test_assert(cpusetbigone != NULL);
+
+  cpusetbig = CPU_ALLOC(big);
+  rtems_test_assert(cpusetbig != NULL);
+
+  CPU_ZERO_S(cpusetbigsize, cpusetbigone);
+  CPU_SET_S(0, cpusetbigsize, cpusetbigone);
+
+  sc = rtems_scheduler_get_processor_set(scheduler_id, cpusetbigsize, cpusetbig);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));
+
+  CPU_FREE(cpusetbig);
+  CPU_FREE(cpusetbigone);
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
+}
+
 static void Init(rtems_task_argument arg)
 {
   rtems_resource_snapshot snapshot;
@@ -133,6 +185,7 @@ static void Init(rtems_task_argument arg)
 
   test_task_get_set_affinity();
   test_scheduler_ident();
+  test_scheduler_get_processors();
 
   rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
 
-- 
1.7.7




More information about the devel mailing list