[PATCH 4/9] score: Task get/set affinity

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


Make rtems_task_get_affinity() and rtems_task_set_affinity() available
on non-SMP configurations.  Allow larger CPU sets.
---
 cpukit/rtems/Makefile.am                           |    9 +-
 cpukit/rtems/include/rtems/rtems/tasks.h           |   50 ++++----
 cpukit/score/Makefile.am                           |    2 +
 cpukit/score/include/rtems/score/cpusetimpl.h      |   18 +++
 cpukit/score/include/rtems/score/schedulerimpl.h   |  113 +++++++++++------
 cpukit/score/src/schedulerdefaultgetaffinity.c     |   20 +--
 cpukit/score/src/schedulerdefaultsetaffinity.c     |   11 +-
 cpukit/score/src/schedulergetaffinity.c            |   55 ++++++++
 cpukit/score/src/schedulersetaffinity.c            |   55 ++++++++
 testsuites/sptests/Makefile.am                     |    3 +-
 testsuites/sptests/configure.ac                    |    1 +
 testsuites/sptests/spscheduler01/Makefile.am       |   19 +++
 testsuites/sptests/spscheduler01/init.c            |  130 ++++++++++++++++++++
 testsuites/sptests/spscheduler01/spscheduler01.doc |   13 ++
 testsuites/sptests/spscheduler01/spscheduler01.scn |    2 +
 15 files changed, 410 insertions(+), 91 deletions(-)
 create mode 100644 cpukit/score/src/schedulergetaffinity.c
 create mode 100644 cpukit/score/src/schedulersetaffinity.c
 create mode 100644 testsuites/sptests/spscheduler01/Makefile.am
 create mode 100644 testsuites/sptests/spscheduler01/init.c
 create mode 100644 testsuites/sptests/spscheduler01/spscheduler01.doc
 create mode 100644 testsuites/sptests/spscheduler01/spscheduler01.scn

diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index a279ed7..b6a19c4 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -92,6 +92,7 @@ librtems_a_SOURCES += src/rtemsobjectgetclassicname.c
 librtems_a_SOURCES += src/tasks.c
 librtems_a_SOURCES += src/taskcreate.c
 librtems_a_SOURCES += src/taskdelete.c
+librtems_a_SOURCES += src/taskgetaffinity.c
 librtems_a_SOURCES += src/taskgetnote.c
 librtems_a_SOURCES += src/taskident.c
 librtems_a_SOURCES += src/taskinitusers.c
@@ -100,6 +101,7 @@ librtems_a_SOURCES += src/taskmode.c
 librtems_a_SOURCES += src/taskrestart.c
 librtems_a_SOURCES += src/taskresume.c
 librtems_a_SOURCES += src/taskself.c
+librtems_a_SOURCES += src/tasksetaffinity.c
 librtems_a_SOURCES += src/tasksetnote.c
 librtems_a_SOURCES += src/tasksetpriority.c
 librtems_a_SOURCES += src/taskstart.c
@@ -274,12 +276,5 @@ librtems_a_SOURCES += src/signalmp.c
 librtems_a_SOURCES += src/taskmp.c
 endif
 
-## SMP Files
-if HAS_SMP
-librtems_a_SOURCES += src/tasksetaffinity.c
-librtems_a_SOURCES += src/taskgetaffinity.c
-endif
-
-
 include $(srcdir)/preinstall.am
 include $(top_srcdir)/automake/local.am
diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h
index 56dd12d..87128be 100644
--- a/cpukit/rtems/include/rtems/rtems/tasks.h
+++ b/cpukit/rtems/include/rtems/rtems/tasks.h
@@ -494,22 +494,23 @@ rtems_status_code rtems_task_variable_delete(
 );
 #endif
 
-#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
 /**
- *  @brief RTEMS Get Task Affinity
+ * @brief Gets the processor affinity set of a task.
  *
- *  This directive returns the cpuset for the
- *  given task.  The cpuset size must be the
- *  same size as the task affinity set size.
+ * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
+ * executing task.
+ * @param[in] cpusetsize Size of the specified affinity set buffer in
+ * bytes.  This value must be positive.
+ * @param[out] cpuset The current processor affinity set of the task.  A set
+ * bit in the affinity set means that the task can execute on this processor
+ * and a cleared bit means the opposite.
  *
- * @param[in] id is the thread to extract
- * @param[in] cpusetsize is the size of the cpuset
- * @param[out] cpuset is the tasks affinity cpuset
- *
- * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
- * @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
- * @retval RTEMS_INVALID_NUMBER if cpusetsize is incorrect
- * @retval RTEMS_INVALID_ID if id not valid
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
+ * @retval RTEMS_INVALID_ID Invalid task identifier.
+ * @retval RTEMS_INVALID_NUMBER The affinity set buffer is too small for the
+ * current processor affinity set of the task.
  */
 rtems_status_code rtems_task_get_affinity(
   rtems_id             id,
@@ -518,19 +519,20 @@ rtems_status_code rtems_task_get_affinity(
 );
 
 /**
- *  @brief RTEMS Set Task Affinity
+ * @brief Sets the processor affinity set of a task.
  *
- *  This directive sets the given tasks
- *  affinity cpuset.
+ * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
+ * executing task.
+ * @param[in] cpusetsize Size of the specified affinity set buffer in
+ * bytes.  This value must be positive.
+ * @param[in] cpuset The new processor affinity set for the task.  A set bit in
+ * the affinity set means that the task can execute on this processor and a
+ * cleared bit means the opposite.
  *
- * @param[in] id is the thread to extract
- * @param[in] cpusetsize is the size of the cpuset
- * @param[in] cpuset is affinity set to assign to the task
- *
- * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
- * @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
- * @retval RTEMS_INVALID_NUMBER if cpuset or cpusetsize is incorrect
- * @retval RTEMS_INVALID_ID if id not valid
+ * @retval RTEMS_SUCCESSFUL Successful operation.
+ * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
+ * @retval RTEMS_INVALID_ID Invalid task identifier.
+ * @retval RTEMS_INVALID_NUMBER Invalid processor affinity set.
  */
 rtems_status_code rtems_task_set_affinity(
   rtems_id             id,
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 4cd89d7..ae92550 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -195,6 +195,8 @@ libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \
 ## SCHEDULER_C_FILES
 libscore_a_SOURCES += src/log2table.c
 libscore_a_SOURCES += src/scheduler.c
+libscore_a_SOURCES += src/schedulergetaffinity.c
+libscore_a_SOURCES += src/schedulersetaffinity.c
 libscore_a_SOURCES += src/schedulerdefaultallocatefree.c
 libscore_a_SOURCES += src/schedulerdefaultreleasejob.c
 libscore_a_SOURCES += src/schedulerdefaultstartidle.c
diff --git a/cpukit/score/include/rtems/score/cpusetimpl.h b/cpukit/score/include/rtems/score/cpusetimpl.h
index 06fe3f5..8ae2408 100644
--- a/cpukit/score/include/rtems/score/cpusetimpl.h
+++ b/cpukit/score/include/rtems/score/cpusetimpl.h
@@ -20,6 +20,9 @@
 #define _RTEMS_SCORE_CPUSETIMPL_H
 
 #include <rtems/score/cpuset.h>
+#include <rtems/score/smp.h>
+
+#include <limits.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -58,6 +61,21 @@ void _CPU_set_Show_default( const char *description );
  */
 const CPU_set_Control *_CPU_set_Default(void);
 
+RTEMS_INLINE_ROUTINE size_t _CPU_set_Maximum_CPU_count(
+  size_t cpusetsize
+)
+{
+  return cpusetsize * CHAR_BIT;
+}
+
+RTEMS_INLINE_ROUTINE bool _CPU_set_Is_large_enough(
+  size_t cpusetsize
+)
+{
+  return _CPU_set_Maximum_CPU_count( cpusetsize )
+    >= _SMP_Get_processor_count();
+}
+
 #endif
 
 /**
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
index 5c78723..e088d26 100644
--- a/cpukit/score/include/rtems/score/schedulerimpl.h
+++ b/cpukit/score/include/rtems/score/schedulerimpl.h
@@ -20,6 +20,7 @@
 #define _RTEMS_SCORE_SCHEDULERIMPL_H
 
 #include <rtems/score/scheduler.h>
+#include <rtems/score/cpusetimpl.h>
 #include <rtems/score/threadimpl.h>
 
 #ifdef __cplusplus
@@ -257,49 +258,81 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle(
   ( *scheduler->Operations.start_idle )( scheduler, the_thread, cpu );
 }
 
-#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(
-    const Scheduler_Control *scheduler,
-    Thread_Control          *the_thread,
-    size_t                   cpusetsize,
-    cpu_set_t               *cpuset
-  )
-  {
-    return ( *scheduler->Operations.get_affinity )(
-      scheduler,
-      the_thread,
-      cpusetsize,
-      cpuset
-    );
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+
+RTEMS_INLINE_ROUTINE void _Scheduler_Get_processor_set(
+  const Scheduler_Control *scheduler,
+  size_t                   cpusetsize,
+  cpu_set_t               *cpuset
+)
+{
+  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 );
+  }
+}
+
+RTEMS_INLINE_ROUTINE bool _Scheduler_default_Get_affinity_body(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  cpu_set_t               *cpuset
+)
+{
+  (void) the_thread;
+
+  _Scheduler_Get_processor_set( scheduler, cpusetsize, cpuset );
+
+  return true;
+}
+
+bool _Scheduler_Get_affinity(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  cpu_set_t               *cpuset
+);
+
+RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  const cpu_set_t         *cpuset
+)
+{
+  size_t   cpu_max   = _CPU_set_Maximum_CPU_count( cpusetsize );
+  uint32_t cpu_count = _SMP_Get_processor_count();
+  uint32_t cpu_index;
+  bool     ok = true;
+
+  (void) scheduler;
+  (void) the_thread;
+
+  for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
+    ok = ok && CPU_ISSET_S( (int) cpu_index, 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(
-    const Scheduler_Control *scheduler,
-    Thread_Control          *the_thread,
-    size_t                   cpusetsize,
-    const cpu_set_t         *cpuset
-  )
-  {
-    return ( *scheduler->Operations.set_affinity )(
-      scheduler,
-      the_thread,
-      cpusetsize,
-      cpuset
-    );
+  for ( ; cpu_index < cpu_max ; ++cpu_index ) {
+    ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
   }
-#endif
+
+  return ok;
+}
+
+bool _Scheduler_Set_affinity(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  const cpu_set_t         *cpuset
+);
+
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
 
 RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir(
   Thread_Control *heir,
diff --git a/cpukit/score/src/schedulerdefaultgetaffinity.c b/cpukit/score/src/schedulerdefaultgetaffinity.c
index 367fc25..56a4ee4 100644
--- a/cpukit/score/src/schedulerdefaultgetaffinity.c
+++ b/cpukit/score/src/schedulerdefaultgetaffinity.c
@@ -20,7 +20,6 @@
 #endif
 
 #include <rtems/score/schedulerimpl.h>
-#include <rtems/score/cpusetimpl.h>
 
 bool _Scheduler_default_Get_affinity(
   const Scheduler_Control *scheduler,
@@ -29,17 +28,10 @@ bool _Scheduler_default_Get_affinity(
   cpu_set_t               *cpuset
 )
 {
-  const CPU_set_Control *ctl;
-
-  (void) scheduler;
-  (void) thread;
-
-  ctl = _CPU_set_Default();
-  if ( cpusetsize != ctl->setsize ) {
-    return false;
-  }
-
-  CPU_COPY( cpuset, ctl->set );
-
-  return true;
+  return _Scheduler_default_Get_affinity_body(
+    scheduler,
+    thread,
+    cpusetsize,
+    cpuset
+  );
 }
diff --git a/cpukit/score/src/schedulerdefaultsetaffinity.c b/cpukit/score/src/schedulerdefaultsetaffinity.c
index 33be12b..e53f8b8 100644
--- a/cpukit/score/src/schedulerdefaultsetaffinity.c
+++ b/cpukit/score/src/schedulerdefaultsetaffinity.c
@@ -20,7 +20,6 @@
 #endif
 
 #include <rtems/score/schedulerimpl.h>
-#include <rtems/score/cpusetimpl.h>
 
 bool _Scheduler_default_Set_affinity(
   const Scheduler_Control *scheduler,
@@ -29,8 +28,10 @@ bool _Scheduler_default_Set_affinity(
   const cpu_set_t         *cpuset
 )
 {
-  (void) scheduler;
-  (void) thread;
-
-  return _CPU_set_Is_valid( cpuset, cpusetsize );
+  return _Scheduler_default_Set_affinity_body(
+    scheduler,
+    thread,
+    cpusetsize,
+    cpuset
+  );
 }
diff --git a/cpukit/score/src/schedulergetaffinity.c b/cpukit/score/src/schedulergetaffinity.c
new file mode 100644
index 0000000..d9e62b5
--- /dev/null
+++ b/cpukit/score/src/schedulergetaffinity.c
@@ -0,0 +1,55 @@
+/*
+ * 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/score/schedulerimpl.h>
+
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+
+bool _Scheduler_Get_affinity(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  cpu_set_t               *cpuset
+)
+{
+  bool ok;
+
+  if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
+#if defined(RTEMS_SMP)
+    ok = ( *scheduler->Operations.get_affinity )(
+      scheduler,
+      the_thread,
+      cpusetsize,
+      cpuset
+    );
+#else
+    ok = _Scheduler_default_Get_affinity_body(
+      scheduler,
+      the_thread,
+      cpusetsize,
+      cpuset
+    );
+#endif
+  } else {
+    ok = false;
+  }
+
+  return ok;
+}
+
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
diff --git a/cpukit/score/src/schedulersetaffinity.c b/cpukit/score/src/schedulersetaffinity.c
new file mode 100644
index 0000000..2416a19
--- /dev/null
+++ b/cpukit/score/src/schedulersetaffinity.c
@@ -0,0 +1,55 @@
+/*
+ * 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/score/schedulerimpl.h>
+
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+
+bool _Scheduler_Set_affinity(
+  const Scheduler_Control *scheduler,
+  Thread_Control          *the_thread,
+  size_t                   cpusetsize,
+  const cpu_set_t         *cpuset
+)
+{
+  bool ok;
+
+  if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
+#if defined(RTEMS_SMP)
+    ok = ( *scheduler->Operations.set_affinity )(
+      scheduler,
+      the_thread,
+      cpusetsize,
+      cpuset
+    );
+#else
+    ok = _Scheduler_default_Set_affinity_body(
+      scheduler,
+      the_thread,
+      cpusetsize,
+      cpuset
+    );
+#endif
+  } else {
+    ok = false;
+  }
+
+  return ok;
+}
+
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index 1d530e2..0477e26 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -37,7 +37,8 @@ if HAS_SMP
 else
 SUBDIRS += sp29
 endif
- SUBDIRS += spprofiling01
+SUBDIRS += spscheduler01
+SUBDIRS += spprofiling01
 SUBDIRS += spfatal28
 SUBDIRS += spthreadlife01
 SUBDIRS += spprofiling01
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index 30d2787..6be14e4 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -40,6 +40,7 @@ AM_CONDITIONAL(HAS_SMP,test "$rtems_cv_RTEMS_SMP" = "yes")
 
 # Explicitly list all Makefiles here
 AC_CONFIG_FILES([Makefile
+spscheduler01/Makefile
 spfatal28/Makefile
 spthreadlife01/Makefile
 spprofiling01/Makefile
diff --git a/testsuites/sptests/spscheduler01/Makefile.am b/testsuites/sptests/spscheduler01/Makefile.am
new file mode 100644
index 0000000..f108426
--- /dev/null
+++ b/testsuites/sptests/spscheduler01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = spscheduler01
+spscheduler01_SOURCES = init.c
+
+dist_rtems_tests_DATA = spscheduler01.scn spscheduler01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(spscheduler01_OBJECTS)
+LINK_LIBS = $(spscheduler01_LDLIBS)
+
+spscheduler01$(EXEEXT): $(spscheduler01_OBJECTS) $(spscheduler01_DEPENDENCIES)
+	@rm -f spscheduler01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c
new file mode 100644
index 0000000..f8c4bb2
--- /dev/null
+++ b/testsuites/sptests/spscheduler01/init.c
@@ -0,0 +1,130 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/libcsupport.h>
+
+#include <limits.h>
+
+#include "tmacros.h"
+
+const char rtems_test_name[] = "SPSCHEDULER 1";
+
+static rtems_id invalid_id = 1;
+
+static void test_task_get_set_affinity(void)
+{
+#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
+  rtems_id self_id = rtems_task_self();
+  rtems_status_code sc;
+  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_task_get_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
+  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
+
+  sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
+  rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
+
+  sc = rtems_task_get_affinity(RTEMS_SELF, 0, &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
+
+  sc = rtems_task_set_affinity(RTEMS_SELF, 0, &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
+
+  sc = rtems_task_get_affinity(invalid_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_ID);
+
+  sc = rtems_task_set_affinity(invalid_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_INVALID_ID);
+
+  sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
+
+  sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  sc = rtems_task_get_affinity(self_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
+
+  sc = rtems_task_set_affinity(self_id, sizeof(cpuset), &cpuset);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  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_task_get_affinity(RTEMS_SELF, cpusetbigsize, cpusetbig);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));
+
+  sc = rtems_task_set_affinity(RTEMS_SELF, cpusetbigsize, cpusetbig);
+  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+  CPU_FREE(cpusetbig);
+  CPU_FREE(cpusetbigone);
+#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
+}
+
+static void Init(rtems_task_argument arg)
+{
+  rtems_resource_snapshot snapshot;
+
+  TEST_BEGIN();
+
+  rtems_resource_snapshot_take(&snapshot);
+
+  test_task_get_set_affinity();
+
+  rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
+
+  TEST_END();
+  rtems_test_exit(0);
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/sptests/spscheduler01/spscheduler01.doc b/testsuites/sptests/spscheduler01/spscheduler01.doc
new file mode 100644
index 0000000..00ac13e
--- /dev/null
+++ b/testsuites/sptests/spscheduler01/spscheduler01.doc
@@ -0,0 +1,13 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: spscheduler01
+
+directives:
+
+  - rtems_task_get_affinity()
+  - rtems_task_set_affinity()
+
+concepts:
+
+  - Ensure that the task set/get affinity functions work on non-SMP
+    configurations.
diff --git a/testsuites/sptests/spscheduler01/spscheduler01.scn b/testsuites/sptests/spscheduler01/spscheduler01.scn
new file mode 100644
index 0000000..8c73372
--- /dev/null
+++ b/testsuites/sptests/spscheduler01/spscheduler01.scn
@@ -0,0 +1,2 @@
+*** BEGIN OF TEST SPSCHEDULER 1 ***
+*** END OF TEST SPSCHEDULER 1 ***
-- 
1.7.7




More information about the devel mailing list