[PATCH v2 04/15] score: Move processor affinity to Thread_Control
Gedare Bloom
gedare at rtems.org
Sun Jul 9 11:51:47 UTC 2017
On Fri, Jul 7, 2017 at 9:54 AM, Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
> Update #3059.
> ---
> cpukit/score/Makefile.am | 1 -
> cpukit/score/include/rtems/score/processormask.h | 2 ++
> cpukit/score/include/rtems/score/scheduler.h | 27 ----------------
> cpukit/score/include/rtems/score/schedulerimpl.h | 14 --------
> .../rtems/score/schedulerpriorityaffinitysmp.h | 19 -----------
> cpukit/score/include/rtems/score/thread.h | 7 +++-
> cpukit/score/src/processormaskcopy.c | 2 ++
> cpukit/score/src/schedulerdefaultgetaffinity.c | 37 ----------------------
> cpukit/score/src/schedulergetaffinity.c | 30 ++++++------------
> cpukit/score/src/schedulerpriorityaffinitysmp.c | 23 --------------
> cpukit/score/src/threadinitialize.c | 1 +
> testsuites/smptests/smpaffinity01/init.c | 2 +-
> testsuites/smptests/smppsxaffinity02/init.c | 2 +-
> testsuites/smptests/smpscheduler02/init.c | 19 ++++++++---
> 14 files changed, 36 insertions(+), 150 deletions(-)
> delete mode 100644 cpukit/score/src/schedulerdefaultgetaffinity.c
>
> diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
> index 1ac7c1545c..d2dd80d6f0 100644
> --- a/cpukit/score/Makefile.am
> +++ b/cpukit/score/Makefile.am
> @@ -161,7 +161,6 @@ libscore_a_SOURCES += src/smpmulticastaction.c
> libscore_a_SOURCES += src/cpuset.c
> libscore_a_SOURCES += src/cpusetprintsupport.c
> libscore_a_SOURCES += src/schedulerdefaultaskforhelp.c
> -libscore_a_SOURCES += src/schedulerdefaultgetaffinity.c
> libscore_a_SOURCES += src/schedulerdefaultsetaffinity.c
> libscore_a_SOURCES += src/schedulersmp.c
> libscore_a_SOURCES += src/schedulersmpstartidle.c
> diff --git a/cpukit/score/include/rtems/score/processormask.h b/cpukit/score/include/rtems/score/processormask.h
> index b550aa42a9..ed79e63d6f 100644
> --- a/cpukit/score/include/rtems/score/processormask.h
> +++ b/cpukit/score/include/rtems/score/processormask.h
> @@ -252,6 +252,8 @@ RTEMS_INLINE_ROUTINE Processor_mask_Copy_status _Processor_mask_From_cpu_set_t(
> );
> }
>
> +extern const Processor_mask _Processor_mask_The_one_and_only;
> +
I would prefer _Processor_mask_Only_one, but it is a minor thing.
> /** @} */
>
> #ifdef __cplusplus
> diff --git a/cpukit/score/include/rtems/score/scheduler.h b/cpukit/score/include/rtems/score/scheduler.h
> index 1b9509ae4f..6e7bdcbd9a 100644
> --- a/cpukit/score/include/rtems/score/scheduler.h
> +++ b/cpukit/score/include/rtems/score/scheduler.h
> @@ -203,14 +203,6 @@ typedef struct {
> );
>
> #if defined(RTEMS_SMP)
> - /** @see _Scheduler_Get_affinity() */
> - bool ( *get_affinity )(
> - const Scheduler_Control *,
> - Thread_Control *,
> - size_t,
> - cpu_set_t *
> - );
> -
> /** @see _Scheduler_Set_affinity() */
> bool ( *set_affinity )(
> const Scheduler_Control *,
> @@ -514,24 +506,6 @@ void _Scheduler_default_Start_idle(
> );
>
> #if defined(RTEMS_SMP)
> - /**
> - * @brief Get affinity for the default scheduler.
> - *
> - * @param[in] scheduler The scheduler instance.
> - * @param[in] thread The associated thread.
> - * @param[in] cpusetsize The size of the cpuset.
> - * @param[out] cpuset Affinity set containing all CPUs.
> - *
> - * @retval 0 Successfully got cpuset
> - * @retval -1 The cpusetsize is invalid for the system
> - */
> - bool _Scheduler_default_Get_affinity(
> - const Scheduler_Control *scheduler,
> - Thread_Control *thread,
> - size_t cpusetsize,
> - cpu_set_t *cpuset
> - );
> -
> /**
> * @brief Set affinity for the default scheduler.
> *
> @@ -553,7 +527,6 @@ void _Scheduler_default_Start_idle(
> );
>
> #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY \
> - , _Scheduler_default_Get_affinity \
> , _Scheduler_default_Set_affinity
> #else
> #define SCHEDULER_OPERATION_DEFAULT_GET_SET_AFFINITY
> diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h
> index c7c8bf05a0..927c6e1762 100644
> --- a/cpukit/score/include/rtems/score/schedulerimpl.h
> +++ b/cpukit/score/include/rtems/score/schedulerimpl.h
> @@ -613,20 +613,6 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Get_processor_set(
> }
> }
>
> -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(
> Thread_Control *the_thread,
> size_t cpusetsize,
> diff --git a/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h b/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
> index 850c72bb40..fd4a33670f 100644
> --- a/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
> +++ b/cpukit/score/include/rtems/score/schedulerpriorityaffinitysmp.h
> @@ -68,7 +68,6 @@ extern "C" {
> _Scheduler_default_Cancel_job, \
> _Scheduler_default_Tick, \
> _Scheduler_SMP_Start_idle, \
> - _Scheduler_priority_affinity_SMP_Get_affinity, \
> _Scheduler_priority_affinity_SMP_Set_affinity \
> }
>
> @@ -102,24 +101,6 @@ void _Scheduler_priority_affinity_SMP_Unblock(
> Scheduler_Node *node
> );
>
> -/**
> - * @brief Get affinity for the priority affinity SMP scheduler.
> - *
> - * @param[in] scheduler The scheduler of the thread.
> - * @param[in] thread The associated thread.
> - * @param[in] cpusetsize The size of the cpuset.
> - * @param[in,out] cpuset The associated affinity set.
> - *
> - * @retval 0 Successfully got cpuset
> - * @retval -1 The cpusetsize is invalid for the system
> - */
> -bool _Scheduler_priority_affinity_SMP_Get_affinity(
> - const Scheduler_Control *scheduler,
> - Thread_Control *thread,
> - size_t cpusetsize,
> - cpu_set_t *cpuset
> -);
> -
> void _Scheduler_priority_affinity_SMP_Update_priority(
> const Scheduler_Control *scheduler,
> Thread_Control *the_thread,
> diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
> index 54b207f137..ecab766fee 100644
> --- a/cpukit/score/include/rtems/score/thread.h
> +++ b/cpukit/score/include/rtems/score/thread.h
> @@ -37,7 +37,7 @@
> #include <rtems/score/watchdog.h>
>
> #if defined(RTEMS_SMP)
> - #include <rtems/score/cpuset.h>
> +#include <rtems/score/processormask.h>
> #endif
>
> struct _pthread_cleanup_context;
> @@ -311,6 +311,11 @@ typedef struct {
> * This list is protected by the thread scheduler lock.
> */
> Scheduler_Node *requests;
> +
> + /**
> + * @brief The thread processor affinity set.
> + */
> + Processor_mask Affinity;
> #endif
>
> /**
> diff --git a/cpukit/score/src/processormaskcopy.c b/cpukit/score/src/processormaskcopy.c
> index bf8082d3c4..677c886e60 100644
> --- a/cpukit/score/src/processormaskcopy.c
> +++ b/cpukit/score/src/processormaskcopy.c
> @@ -26,6 +26,8 @@
>
> #include <rtems/score/processormask.h>
>
> +const Processor_mask _Processor_mask_The_one_and_only = { .__bits[ 0 ] = 1 };
> +
> Processor_mask_Copy_status _Processor_mask_Copy(
> long *dst,
> size_t dst_size,
> diff --git a/cpukit/score/src/schedulerdefaultgetaffinity.c b/cpukit/score/src/schedulerdefaultgetaffinity.c
> deleted file mode 100644
> index 56a4ee4fad..0000000000
> --- a/cpukit/score/src/schedulerdefaultgetaffinity.c
> +++ /dev/null
> @@ -1,37 +0,0 @@
> -/**
> - * @file
> - *
> - * @brief Scheduler Default Get Affinity Operation
> - *
> - * @ingroup ScoreScheduler
> - */
> -
> -/*
> - * COPYRIGHT (c) 2014.
> - * On-Line Applications Research Corporation (OAR).
> - *
> - * The license and distribution terms for this file may be
> - * found in the file LICENSE in this distribution or at
> - * http://www.rtems.org/license/LICENSE.
> - */
> -
> -#if HAVE_CONFIG_H
> - #include "config.h"
> -#endif
> -
> -#include <rtems/score/schedulerimpl.h>
> -
> -bool _Scheduler_default_Get_affinity(
> - const Scheduler_Control *scheduler,
> - Thread_Control *thread,
> - size_t cpusetsize,
> - cpu_set_t *cpuset
> -)
> -{
> - return _Scheduler_default_Get_affinity_body(
> - scheduler,
> - thread,
> - cpusetsize,
> - cpuset
> - );
> -}
> diff --git a/cpukit/score/src/schedulergetaffinity.c b/cpukit/score/src/schedulergetaffinity.c
> index 37e10de958..8425a7fcf6 100644
> --- a/cpukit/score/src/schedulergetaffinity.c
> +++ b/cpukit/score/src/schedulergetaffinity.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
> + * Copyright (c) 2014, 2017 embedded brains GmbH. All rights reserved.
> *
> * embedded brains GmbH
> * Dornierstr. 4
> @@ -24,33 +24,21 @@ bool _Scheduler_Get_affinity(
> cpu_set_t *cpuset
> )
> {
> - const Scheduler_Control *scheduler;
> - ISR_lock_Context lock_context;
> - bool ok;
> -
> - if ( !_CPU_set_Is_large_enough( cpusetsize ) ) {
> - return false;
> - }
> + const Scheduler_Control *scheduler;
> + ISR_lock_Context lock_context;
> + Processor_mask *affinity;
> + Processor_mask_Copy_status status;
>
> scheduler = _Thread_Scheduler_get_home( the_thread );
> _Scheduler_Acquire_critical( scheduler, &lock_context );
>
> #if defined(RTEMS_SMP)
> - ok = ( *scheduler->Operations.get_affinity )(
> - scheduler,
> - the_thread,
> - cpusetsize,
> - cpuset
> - );
> + affinity = &the_thread->Scheduler.Affinity;
> #else
> - ok = _Scheduler_default_Get_affinity_body(
> - scheduler,
> - the_thread,
> - cpusetsize,
> - cpuset
> - );
> + affinity = &_Processor_mask_The_one_and_only;
> #endif
> + status = _Processor_mask_To_cpu_set_t( affinity, cpusetsize, cpuset );
>
> _Scheduler_Release_critical( scheduler, &lock_context );
> - return ok;
> + return status == PROCESSOR_MASK_COPY_LOSSLESS;
> }
> diff --git a/cpukit/score/src/schedulerpriorityaffinitysmp.c b/cpukit/score/src/schedulerpriorityaffinitysmp.c
> index 1fa5dbf920..4533dec9d7 100644
> --- a/cpukit/score/src/schedulerpriorityaffinitysmp.c
> +++ b/cpukit/score/src/schedulerpriorityaffinitysmp.c
> @@ -611,29 +611,6 @@ Thread_Control *_Scheduler_priority_affinity_SMP_Remove_processor(
> );
> }
>
> -/*
> - * This is the public scheduler specific Change Priority operation.
> - */
> -bool _Scheduler_priority_affinity_SMP_Get_affinity(
> - const Scheduler_Control *scheduler,
> - Thread_Control *thread,
> - size_t cpusetsize,
> - cpu_set_t *cpuset
> -)
> -{
> - Scheduler_priority_affinity_SMP_Node *node =
> - _Scheduler_priority_affinity_SMP_Thread_get_node(thread);
> -
> - (void) scheduler;
> -
> - if ( node->Affinity.setsize != cpusetsize ) {
> - return false;
> - }
> -
> - CPU_COPY( node->Affinity.set, cpuset );
> - return true;
> -}
> -
> bool _Scheduler_priority_affinity_SMP_Set_affinity(
> const Scheduler_Control *scheduler,
> Thread_Control *thread,
> diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
> index c34113db3d..803ee7b646 100644
> --- a/cpukit/score/src/threadinitialize.c
> +++ b/cpukit/score/src/threadinitialize.c
> @@ -248,6 +248,7 @@ bool _Thread_Initialize(
> RTEMS_STATIC_ASSERT( THREAD_SCHEDULER_BLOCKED == 0, Scheduler_state );
> the_thread->Scheduler.home = scheduler;
> _ISR_lock_Initialize( &the_thread->Scheduler.Lock, "Thread Scheduler" );
> + _Processor_mask_Assign( &the_thread->Scheduler.Affinity, &_SMP_Online_processors );
> _ISR_lock_Initialize( &the_thread->Wait.Lock.Default, "Thread Wait Default" );
> _Thread_queue_Gate_open( &the_thread->Wait.Lock.Tranquilizer );
> _RBTree_Initialize_node( &the_thread->Wait.Link.Registry_node );
> diff --git a/testsuites/smptests/smpaffinity01/init.c b/testsuites/smptests/smpaffinity01/init.c
> index cf95fc54d1..be68e1bbfd 100644
> --- a/testsuites/smptests/smpaffinity01/init.c
> +++ b/testsuites/smptests/smpaffinity01/init.c
> @@ -84,7 +84,7 @@ void Validate_getaffinity_errors(void)
> puts(
> "Init - rtems_task_get_affinity - Invalid cpusetsize - RTEMS_INVALID_NUMBER"
> );
> - sc = rtems_task_get_affinity( Init_id, sizeof(cpu_set_t) * 2, &cpuset );
> + sc = rtems_task_get_affinity( Init_id, 1, &cpuset );
> rtems_test_assert( sc == RTEMS_INVALID_NUMBER );
>
> /* Verify rtems_task_get_affinity validates cpuset */
> diff --git a/testsuites/smptests/smppsxaffinity02/init.c b/testsuites/smptests/smppsxaffinity02/init.c
> index 462462f275..5f8abac0a0 100644
> --- a/testsuites/smptests/smppsxaffinity02/init.c
> +++ b/testsuites/smptests/smppsxaffinity02/init.c
> @@ -89,7 +89,7 @@ void Validate_getaffinity_errors(void)
>
> /* Verify pthread_getaffinity_np validates cpusetsize */
> puts( "Init - pthread_getaffinity_np - Invalid cpusetsize - EINVAL" );
> - sc = pthread_getaffinity_np( Init_id, sizeof(cpu_set_t) * 2, &cpuset );
> + sc = pthread_getaffinity_np( Init_id, 1, &cpuset );
> rtems_test_assert( sc == EINVAL );
>
> /* Verify pthread_getaffinity_np validates cpuset */
> diff --git a/testsuites/smptests/smpscheduler02/init.c b/testsuites/smptests/smpscheduler02/init.c
> index 43558579ab..db7d863991 100644
> --- a/testsuites/smptests/smpscheduler02/init.c
> +++ b/testsuites/smptests/smpscheduler02/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
> @@ -207,8 +207,14 @@ static void test(void)
> cpu_set_t first_cpu;
> cpu_set_t second_cpu;
> cpu_set_t all_cpus;
> + cpu_set_t online_cpus;
> uint32_t cpu_count;
>
> + cpu_count = rtems_get_processor_count();
> + rtems_test_assert(cpu_count == 1 || cpu_count == 2);
> +
> + rtems_test_assert(rtems_get_current_processor() == 0);
> +
> main_task_id = rtems_task_self();
>
> CPU_ZERO(&first_cpu);
> @@ -221,9 +227,12 @@ static void test(void)
> CPU_SET(0, &all_cpus);
> CPU_SET(1, &all_cpus);
>
> - cpu_count = rtems_get_processor_count();
> + CPU_ZERO(&online_cpus);
> + CPU_SET(0, &online_cpus);
>
> - rtems_test_assert(rtems_get_current_processor() == 0);
> + if (cpu_count > 1) {
> + CPU_SET(1, &online_cpus);
> + }
>
> sc = rtems_scheduler_ident(SCHED_A, &scheduler_a_id);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> @@ -304,7 +313,7 @@ static void test(void)
> CPU_ZERO(&cpuset);
> sc = rtems_task_get_affinity(task_id, sizeof(cpuset), &cpuset);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> - rtems_test_assert(CPU_EQUAL(&cpuset, &first_cpu));
> + rtems_test_assert(CPU_EQUAL(&cpuset, &online_cpus));
>
> rtems_test_assert(sched_get_priority_min(SCHED_RR) == 1);
> rtems_test_assert(sched_get_priority_max(SCHED_RR) == 254);
> @@ -326,7 +335,7 @@ static void test(void)
> CPU_ZERO(&cpuset);
> sc = rtems_task_get_affinity(task_id, sizeof(cpuset), &cpuset);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> - rtems_test_assert(CPU_EQUAL(&cpuset, &second_cpu));
> + rtems_test_assert(CPU_EQUAL(&cpuset, &online_cpus));
>
> sc = rtems_task_set_affinity(task_id, sizeof(all_cpus), &all_cpus);
> rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> --
> 2.12.3
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
More information about the devel
mailing list