diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-04-08 11:14:27 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-04-15 08:37:12 +0200 |
commit | 0712d172d0bce40f3a9190af511249256ddac5f1 (patch) | |
tree | edfe262b0e46134e3704641cac50ff9d147e9e2a /cpukit/score/include/rtems/score/schedulerimpl.h | |
parent | score: Simplify thread control initialization (diff) | |
download | rtems-0712d172d0bce40f3a9190af511249256ddac5f1.tar.bz2 |
score: Task get/set affinity
Make rtems_task_get_affinity() and rtems_task_set_affinity() available
on non-SMP configurations. Allow larger CPU sets.
Diffstat (limited to 'cpukit/score/include/rtems/score/schedulerimpl.h')
-rw-r--r-- | cpukit/score/include/rtems/score/schedulerimpl.h | 113 |
1 files changed, 73 insertions, 40 deletions
diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h index 5c787239d0..e088d26b88 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, |