[PATCH 1/2] score: Fix _Scheduler_Set_affinity()
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Oct 27 07:04:53 UTC 2017
---
cpukit/score/src/scheduleredfsmp.c | 9 ++++-----
cpukit/score/src/schedulersetaffinity.c | 7 +++++++
testsuites/sptests/spscheduler01/init.c | 13 ++++++++++++-
3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/cpukit/score/src/scheduleredfsmp.c b/cpukit/score/src/scheduleredfsmp.c
index 3a1b1a934e..82255b0f95 100644
--- a/cpukit/score/src/scheduleredfsmp.c
+++ b/cpukit/score/src/scheduleredfsmp.c
@@ -753,19 +753,18 @@ bool _Scheduler_EDF_SMP_Set_affinity(
{
Scheduler_Context *context;
Processor_mask a;
- Processor_mask b;
+ uint32_t count;
uint32_t rqi;
context = _Scheduler_Get_context( scheduler );
_Processor_mask_And( &a, &context->Processors, affinity );
+ count = _Processor_mask_Count( &a );
- if ( _Processor_mask_Count( &a ) == 0 ) {
+ if ( count == 0 ) {
return false;
}
- _Processor_mask_And( &b, &_SMP_Online_processors, affinity );
-
- if ( _Processor_mask_Count( &b ) == _SMP_Processor_count ) {
+ if ( count == _SMP_Processor_count ) {
rqi = 0;
} else {
rqi = _Processor_mask_Find_last_set( &a );
diff --git a/cpukit/score/src/schedulersetaffinity.c b/cpukit/score/src/schedulersetaffinity.c
index 3d354800b2..00d1a8b207 100644
--- a/cpukit/score/src/schedulersetaffinity.c
+++ b/cpukit/score/src/schedulersetaffinity.c
@@ -36,6 +36,13 @@ bool _Scheduler_Set_affinity(
return false;
}
+ /*
+ * Reduce affinity set to the online processors to be in line with
+ * _Thread_Initialize() which sets the default affinity to the set of online
+ * processors.
+ */
+ _Processor_mask_And( &affinity, &_SMP_Online_processors, &affinity );
+
scheduler = _Thread_Scheduler_get_home( the_thread );
_Scheduler_Acquire_critical( scheduler, &lock_context );
diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c
index 9840a3ebc4..cbdc92ca25 100644
--- a/testsuites/sptests/spscheduler01/init.c
+++ b/testsuites/sptests/spscheduler01/init.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2016 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
@@ -41,6 +41,7 @@ static void test_task_get_set_affinity(void)
rtems_id task_id;
rtems_status_code sc;
cpu_set_t cpusetone;
+ cpu_set_t cpusetall;
cpu_set_t cpuset;
size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
@@ -50,6 +51,8 @@ static void test_task_get_set_affinity(void)
CPU_ZERO(&cpusetone);
CPU_SET(0, &cpusetone);
+ CPU_FILL(&cpusetall);
+
sc = rtems_task_create(
rtems_build_name('T', 'A', 'S', 'K'),
2,
@@ -97,6 +100,14 @@ static void test_task_get_set_affinity(void)
rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
+ sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpusetall), &cpusetall);
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ sc = rtems_task_get_affinity(task_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);
--
2.12.3
More information about the devel
mailing list