[PATCH 2/3] posix: Validate affinity sets by the scheduler

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Oct 10 09:38:39 UTC 2017


Update #2514.
---
 cpukit/posix/src/pthreadcreate.c                      |  9 ++-------
 cpukit/score/src/schedulerpriorityaffinitysmp.c       | 19 ++++++++-----------
 testsuites/smptests/smppsxaffinity02/init.c           |  6 +++---
 .../smptests/smppsxaffinity02/smppsxaffinity02.scn    |  8 ++++----
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 41e2b67122..75205f7e0a 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -29,7 +29,6 @@
 #include <rtems/posix/pthreadimpl.h>
 #include <rtems/posix/pthreadattrimpl.h>
 #include <rtems/score/assert.h>
-#include <rtems/score/cpusetimpl.h>
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/apimutex.h>
 #include <rtems/score/stackimpl.h>
@@ -170,11 +169,9 @@ int pthread_create(
     return EINVAL;
   }
 
-#if defined(RTEMS_SMP)
-  status = _CPU_set_Is_valid(the_attr->affinityset, the_attr->affinitysetsize);
-  if ( !status )
+  if ( the_attr->affinityset == NULL ) {
     return EINVAL;
-#endif
+  }
 
   /*
    *  Currently all POSIX threads are floating point if the hardware
@@ -223,7 +220,6 @@ int pthread_create(
 
   the_thread->Life.state |= THREAD_LIFE_CHANGE_DEFERRED;
 
-#if defined(RTEMS_SMP)
   _ISR_lock_ISR_disable( &lock_context );
    status = _Scheduler_Set_affinity(
      the_thread,
@@ -236,7 +232,6 @@ int pthread_create(
      _RTEMS_Unlock_allocator();
      return EINVAL;
    }
-#endif
 
   /*
    *  finish initializing the per API structure
diff --git a/cpukit/score/src/schedulerpriorityaffinitysmp.c b/cpukit/score/src/schedulerpriorityaffinitysmp.c
index c35883f142..e8301226f3 100644
--- a/cpukit/score/src/schedulerpriorityaffinitysmp.c
+++ b/cpukit/score/src/schedulerpriorityaffinitysmp.c
@@ -23,9 +23,6 @@
 #include <rtems/score/schedulerpriorityimpl.h>
 #include <rtems/score/schedulersmpimpl.h>
 #include <rtems/score/schedulerprioritysmpimpl.h>
-#include <rtems/score/wkspace.h>
-#include <rtems/score/cpusetimpl.h>
-
 #include <rtems/score/priority.h>
 
 /*
@@ -606,27 +603,27 @@ bool _Scheduler_priority_affinity_SMP_Set_affinity(
   const Processor_mask    *affinity
 )
 {
+  Scheduler_Context                    *context;
   Scheduler_priority_affinity_SMP_Node *node;
   States_Control                        current_state;
+  Processor_mask                        my_affinity;
   cpu_set_t                             cpuset;
-  size_t                                cpusetsize;
 
-  cpusetsize = sizeof( cpuset );
-  _Processor_mask_To_cpu_set_t( affinity, cpusetsize, &cpuset );
-  /*
-   * Validate that the cpset meets basic requirements.
-   */
-  if ( !_CPU_set_Is_valid( &cpuset, cpusetsize ) ) {
+  context = _Scheduler_Get_context( scheduler );
+  _Processor_mask_And( &my_affinity, &context->Processors, affinity );
+
+  if ( _Processor_mask_Count( &my_affinity ) == 0 ) {
     return false;
   }
 
+  _Processor_mask_To_cpu_set_t( &my_affinity, sizeof( cpuset ), &cpuset );
   node = _Scheduler_priority_affinity_SMP_Node_downcast( node_base );
 
   /*
    * The old and new set are the same, there is no point in
    * doing anything.
    */
-  if ( CPU_EQUAL_S( cpusetsize, &cpuset, node->Affinity.set ) )
+  if ( CPU_EQUAL( &cpuset, node->Affinity.set ) )
     return true;
 
   current_state = thread->current_state;
diff --git a/testsuites/smptests/smppsxaffinity02/init.c b/testsuites/smptests/smppsxaffinity02/init.c
index eb38ea3c25..21a723d41b 100644
--- a/testsuites/smptests/smppsxaffinity02/init.c
+++ b/testsuites/smptests/smppsxaffinity02/init.c
@@ -45,11 +45,11 @@ void Validate_setaffinity_errors(void)
   int                 sc;
   cpu_set_t           cpuset;
 
-  /* Verify pthread_setaffinity_np checks that all cpu's exist. */
+  /* Verify pthread_setaffinity_np checks that more cpu's don't hurt. */
   CPU_FILL(&cpuset);
-  puts( "Init - pthread_setaffinity_np - Invalid cpu - EINVAL" );
+  puts( "Init - pthread_setaffinity_np - Lots of cpus - SUCCESS" );
   sc = pthread_setaffinity_np( Init_id, sizeof(cpu_set_t), &cpuset );
-  rtems_test_assert( sc == EINVAL );
+  rtems_test_assert( sc == 0 );
 
   /* Verify pthread_setaffinity_np checks that at least one cpu is set */
   CPU_ZERO(&cpuset);
diff --git a/testsuites/smptests/smppsxaffinity02/smppsxaffinity02.scn b/testsuites/smptests/smppsxaffinity02/smppsxaffinity02.scn
index 7f3d3f9597..52cb8ce71c 100644
--- a/testsuites/smptests/smppsxaffinity02/smppsxaffinity02.scn
+++ b/testsuites/smptests/smppsxaffinity02/smppsxaffinity02.scn
@@ -1,5 +1,5 @@
-*** SMP POSIX AFFINITY ATTRIBUTE TEST 2 ***
-Init - pthread_setaffinity_np - Invalid cpu - EINVAL
+*** BEGIN OF TEST SMPPSXAFFINITY 2 ***
+Init - pthread_setaffinity_np - Lots of cpu - SUCCESS
 Init - pthread_setaffinity_np - no cpu - EINVAL
 Init - pthread_setaffinity_np - Invalid thread - ESRCH
 Init - pthread_setaffinity_np - Invalid cpusetsize - EINVAL
@@ -11,7 +11,7 @@ Init - Set Init priority to high
 Init - Create Medium priority tasks
 Init - Verify Medium priority tasks
 Init - Create  Low priority tasks
-Init - Verify Medium priority tasks
+Init - Verify Low priority tasks
 Init - Change affinity on Low priority tasks
 Init - Validate affinity on Low priority tasks
-*** SMP POSIX AFFINITY ATTRIBUTE TEST 2 ***
+*** END OF TEST SMPPSXAFFINITY 2 ***
-- 
2.12.3




More information about the devel mailing list