[rtems commit] posix: Constify default thread processor affinity

Sebastian Huber sebh at rtems.org
Tue Oct 10 05:44:21 UTC 2017


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Oct 10 07:13:37 2017 +0200

posix: Constify default thread processor affinity

Set default thread processor affinity to all processors of the
pre-allocated set.  This allows to constify the
_POSIX_Threads_Default_attributes.

Update #2514.

---

 cpukit/posix/include/rtems/posix/pthreadimpl.h        |  2 +-
 cpukit/posix/src/pthread.c                            | 19 ++-----------------
 testsuites/psxtests/psxgetattrnp01/init.c             |  7 +++++++
 testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn |  1 +
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 9e5314b..6b338f9 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -51,7 +51,7 @@ extern Thread_Information _POSIX_Threads_Information;
 /**
  * This variable contains the default POSIX Thread attributes.
  */
-extern pthread_attr_t _POSIX_Threads_Default_attributes;
+extern const pthread_attr_t _POSIX_Threads_Default_attributes;
 
 RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
   Thread_Control    *the_thread,
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index 1d791df..171d036 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -49,7 +49,7 @@ Thread_Information _POSIX_Threads_Information;
  *  NOTE: Be careful .. if the default attribute set changes,
  *        _POSIX_Threads_Initialize_user_threads will need to be examined.
  */
-pthread_attr_t _POSIX_Threads_Default_attributes = {
+const pthread_attr_t _POSIX_Threads_Default_attributes = {
   .is_initialized  = true,                       /* is_initialized */
   .stackaddr       = NULL,                       /* stackaddr */
   .stacksize       = 0,                          /* stacksize -- will be adjusted to minimum */
@@ -79,7 +79,7 @@ pthread_attr_t _POSIX_Threads_Default_attributes = {
     sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
   .affinityset             =
     &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
-  .affinitysetpreallocated = {{0x1}}
+  .affinitysetpreallocated = { { -1L } }
 };
 
 void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
@@ -243,21 +243,6 @@ User_extensions_Control _POSIX_Threads_User_extensions = {
  */
 static void _POSIX_Threads_Manager_initialization(void)
 {
-  #if defined(RTEMS_SMP)
-    const CPU_set_Control *affinity;
-    pthread_attr_t *attr;
-
-    /* Initialize default attribute. */
-    attr = &_POSIX_Threads_Default_attributes;
-
-    /*  Initialize the affinity to be the default cpu set for the system */
-    affinity = _CPU_set_Default();
-    _Assert( affinity->setsize == sizeof( attr->affinitysetpreallocated ) );
-    attr->affinityset             = &attr->affinitysetpreallocated;
-    attr->affinitysetsize         = affinity->setsize;
-    CPU_COPY( affinity->set, attr->affinityset );
-  #endif
-
   _Thread_Initialize_information(
     &_POSIX_Threads_Information, /* object information table */
     OBJECTS_POSIX_API,           /* object API */
diff --git a/testsuites/psxtests/psxgetattrnp01/init.c b/testsuites/psxtests/psxgetattrnp01/init.c
index 2b7d699..afde4a2 100644
--- a/testsuites/psxtests/psxgetattrnp01/init.c
+++ b/testsuites/psxtests/psxgetattrnp01/init.c
@@ -190,6 +190,7 @@ void *POSIX_Init(
   size_t              stacksize;
   size_t              guardsize;
   struct sched_param  param;
+  cpu_set_t           set;
 
   TEST_BEGIN();
 
@@ -211,6 +212,12 @@ void *POSIX_Init(
   sc = pthread_attr_init(&Thread_attr);
   rtems_test_assert(!sc);
 
+  puts("Init - pthread_attr_setaffinity_np");
+  CPU_ZERO( &set );
+  CPU_SET( 0, &set );
+  sc = pthread_attr_setaffinity_np( &Thread_attr, sizeof( set ), &set );
+  rtems_test_assert(!sc);
+
   puts("Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED");
   sc = pthread_attr_setinheritsched( &Thread_attr, PTHREAD_EXPLICIT_SCHED );
   rtems_test_assert(!sc);
diff --git a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
index ab09630..0ca49a5 100644
--- a/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
+++ b/testsuites/psxtests/psxgetattrnp01/psxgetattrnp01.scn
@@ -2,6 +2,7 @@
 Init - pthread_getattr_np - attr NULL - EINVAL
 Init - pthread_getattr_np - invalid id - ESRCH
 Init - pthread_attr_init
+Init - pthread_attr_setaffinity_np
 Init - pthread_attr_setinheritsched - PTHREAD_EXPLICIT_SCHED
 Init - pthread_attr_setschedpolicy to SCHED_RR
 Init - pthread_attr_setschedparam to minimum priority + 2




More information about the vc mailing list