[rtems commit] score: _Scheduler_Set_affinity()
Joel Sherrill
Joel.Sherrill at OARcorp.com
Mon Jun 2 08:33:25 UTC 2014
On Jun 2, 2014 3:08 AM, Sebastian Huber <sebh at rtems.org> wrote:
>
> Module: rtems
> Branch: master
> Commit: 25f5730fe515911e42591f66294baff0369d9883
> Changeset: http://git.rtems.org/rtems/commit/?id=25f5730fe515911e42591f66294baff0369d9883
>
> Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
> Date: Wed May 28 18:11:51 2014 +0200
>
> score: _Scheduler_Set_affinity()
>
> Do not change the scheduler with this function. Documentation. Coding
> style.
>
> ---
>
> cpukit/rtems/include/rtems/rtems/tasks.h | 11 +++++
> cpukit/score/include/rtems/score/schedulerimpl.h | 10 +----
> cpukit/score/src/schedulersetaffinity.c | 52 +++++++---------------
> doc/user/smp.t | 10 ++++-
> testsuites/smptests/smpscheduler02/init.c | 6 +-
> 5 files changed, 41 insertions(+), 48 deletions(-)
>
> diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h
> index 76653fd..e0fa27e 100644
> --- a/cpukit/rtems/include/rtems/rtems/tasks.h
> +++ b/cpukit/rtems/include/rtems/rtems/tasks.h
> @@ -521,6 +521,17 @@ rtems_status_code rtems_task_get_affinity(
> /**
> * @brief Sets the processor affinity set of a task.
> *
> + * This function will not change the scheduler of the task. The intersection
> + * of the processor affinity set and the set of processors owned by the
> + * scheduler of the task must be non-empty. It is not an error if the
> + * processor affinity set contains processors that are not part of the set of
> + * processors owned by the scheduler instance of the task. A task will simply
> + * not run under normal circumstances on these processors since the scheduler
> + * ignores them. Some locking protocols may temporarily use processors that
> + * are not included in the processor affinity set of the task. It is also not
> + * an error if the processor affinity set contains processors that are not part
> + * of the system.
> + *
> * @param[in] id Identifier of the task. Use @ref RTEMS_SELF to select the
> * executing task.
> * @param[in] cpusetsize Size of the specified affinity set buffer in
> diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
> index a434c8c..f1acf32 100644
> --- a/cpukit/score/include/rtems/score/schedulerimpl.h
> +++ b/cpukit/score/include/rtems/score/schedulerimpl.h
> @@ -418,7 +418,6 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
> 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;
> @@ -429,8 +428,7 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
> _Scheduler_Get_by_CPU_index( cpu_index );
>
> ok = ok
> - && ( ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
> - && scheduler == scheduler_of_cpu )
> + && ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
> || ( !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
> && scheduler != scheduler_of_cpu ) );
If we need kept the affinity of each thread in a common place like thread control or scheduler base node when SMP is enabled and the scheduler's set of managed CPUs in the base info for all schedulers when SMP is enabled, then you would always have CPU sets which could be simply Anded, Ored, etc.
This would simplify this logic from a loop to a simply logic expression.
> #else
> @@ -440,12 +438,6 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
> #endif
> }
>
> - for ( ; cpu_index < cpu_max ; ++cpu_index ) {
> - ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
> - }
> -
> - _Scheduler_Set( scheduler, the_thread );
> -
> return ok;
> }
>
> diff --git a/cpukit/score/src/schedulersetaffinity.c b/cpukit/score/src/schedulersetaffinity.c
> index a20888b..f7c9336 100644
> --- a/cpukit/score/src/schedulersetaffinity.c
> +++ b/cpukit/score/src/schedulersetaffinity.c
> @@ -26,45 +26,27 @@ bool _Scheduler_Set_affinity(
> const cpu_set_t *cpuset
> )
> {
> - bool ok;
> + const Scheduler_Control *scheduler = _Scheduler_Get( the_thread );
>
> - if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
> -#if defined(RTEMS_SMP)
> - uint32_t cpu_count = _SMP_Get_processor_count();
> - uint32_t cpu_index;
> -
> - ok = false;
> -
> - for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
> - if ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ) ) {
> - const Scheduler_Control *scheduler_of_cpu =
> - _Scheduler_Get_by_CPU_index( cpu_index );
> -
> - if ( scheduler_of_cpu != NULL ) {
> - ok = ( *scheduler_of_cpu->Operations.set_affinity )(
> - scheduler_of_cpu,
> - the_thread,
> - cpusetsize,
> - cpuset
> - );
> - }
> + if ( !_CPU_set_Is_large_enough( cpusetsize ) ) {
> + return false;
> + }
>
> - break;
> - }
> - }
> +#if defined(RTEMS_SMP)
> + return ( *scheduler->Operations.set_affinity )(
> + scheduler,
> + the_thread,
> + cpusetsize,
> + cpuset
> + );
> #else
> - ok = _Scheduler_default_Set_affinity_body(
> - _Scheduler_Get( the_thread ),
> - the_thread,
> - cpusetsize,
> - cpuset
> - );
> + return _Scheduler_default_Set_affinity_body(
> + scheduler,
> + the_thread,
> + cpusetsize,
> + cpuset
> + );
> #endif
> - } else {
> - ok = false;
> - }
> -
> - return ok;
> }
>
> #endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
> diff --git a/doc/user/smp.t b/doc/user/smp.t
> index a040b70..dd84c37 100644
> --- a/doc/user/smp.t
> +++ b/doc/user/smp.t
> @@ -622,4 +622,12 @@ cleared bit means the opposite.
>
> @subheading NOTES:
>
> -None.
> +This function will not change the scheduler of the task. The intersection of
> +the processor affinity set and the set of processors owned by the scheduler of
> +the task must be non-empty. It is not an error if the processor affinity set
> +contains processors that are not part of the set of processors owned by the
> +scheduler instance of the task. A task will simply not run under normal
> +circumstances on these processors since the scheduler ignores them. Some
> +locking protocols may temporarily use processors that are not included in the
> +processor affinity set of the task. It is also not an error if the processor
> +affinity set contains processors that are not part of the system.
> diff --git a/testsuites/smptests/smpscheduler02/init.c b/testsuites/smptests/smpscheduler02/init.c
> index 5bfff0e..9ae636c 100644
> --- a/testsuites/smptests/smpscheduler02/init.c
> +++ b/testsuites/smptests/smpscheduler02/init.c
> @@ -139,14 +139,14 @@ static void test(void)
> rtems_test_assert(CPU_EQUAL(&cpuset, &second_cpu));
>
> sc = rtems_task_set_affinity(task_id, sizeof(all_cpus), &all_cpus);
> - rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
> + rtems_test_assert(sc == RTEMS_SUCCESSFUL);
>
> sc = rtems_task_set_affinity(task_id, sizeof(first_cpu), &first_cpu);
> - rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> + rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
>
> sc = rtems_task_get_scheduler(task_id, &scheduler_id);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> - rtems_test_assert(scheduler_id == scheduler_a_id);
> + rtems_test_assert(scheduler_id == scheduler_b_id);
>
> sc = rtems_task_set_affinity(task_id, sizeof(second_cpu), &second_cpu);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
>
> _______________________________________________
> rtems-vc mailing list
> rtems-vc at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-vc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20140602/c0081f50/attachment.html>
More information about the devel
mailing list