From a3ad4afba883e56447aa40f92c1ad08d835d2564 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 10 Oct 2017 11:22:21 +0200 Subject: posix: Validate affinity sets by the scheduler 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 #include #include -#include #include #include #include @@ -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 #include #include -#include -#include - #include /* @@ -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..3790149b31 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 cpus - 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 *** -- cgit v1.2.3