[PATCH 3/4] rtmes: Add scheduler get processors

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Apr 9 11:28:49 UTC 2014


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

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index 3962fa9..c840f24 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/schedulergetprocessors.c
 librtems_a_SOURCES += src/schedulerident.c
 librtems_a_SOURCES += src/scheduleridentbyindex.c
 
diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h
index fb0869e..59c5c83 100644
--- a/cpukit/rtems/include/rtems/rtems/tasks.h
+++ b/cpukit/rtems/include/rtems/rtems/tasks.h
@@ -584,6 +584,30 @@ rtems_status_code rtems_scheduler_ident_by_index(
   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_processors(
+  rtems_id   scheduler_id,
+  size_t     cpusetsize,
+  cpu_set_t *cpuset
+);
+#endif
+
 /**@}*/
 
 /**
diff --git a/cpukit/rtems/src/schedulergetprocessors.c b/cpukit/rtems/src/schedulergetprocessors.c
new file mode 100644
index 0000000..42c7ae2
--- /dev/null
+++ b/cpukit/rtems/src/schedulergetprocessors.c
@@ -0,0 +1,59 @@
+/*
+ * 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
+
+#include <rtems/rtems/tasks.h>
+#include <rtems/score/cpusetimpl.h>
+#include <rtems/score/schedulerimpl.h>
+
+rtems_status_code rtems_scheduler_get_processors(
+  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 ) ) {
+        uint32_t cpu_count = _SMP_Get_processor_count();
+        uint32_t cpu_index;
+
+        (void) scheduler;
+
+        CPU_ZERO_S( cpusetsize, cpuset );
+
+        for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
+          CPU_SET_S( (int) cpu_index, cpusetsize, cpuset );
+        }
+
+        sc = RTEMS_SUCCESSFUL;
+      } else {
+        sc = RTEMS_INVALID_NUMBER;
+      }
+    } else {
+      sc = RTEMS_INVALID_ID;
+    }
+  } else {
+    sc = RTEMS_INVALID_ADDRESS;
+  }
+
+  return sc;
+}
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index e94c048..8a8e779 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -451,6 +451,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 4452f60..ea50574 100644
--- a/testsuites/sptests/spscheduler01/init.c
+++ b/testsuites/sptests/spscheduler01/init.c
@@ -131,6 +131,57 @@ 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_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_by_index(0, &scheduler_id);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_scheduler_get_processors(scheduler_id, sizeof(cpuset), NULL);
+  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
+
+  sc = rtems_scheduler_get_processors(invalid_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_ID);
+
+  sc = rtems_scheduler_get_processors(scheduler_id, 0, &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
+
+  sc = rtems_scheduler_get_processors(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_processors(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;
@@ -141,6 +192,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