From ecabd3849625e690e3c5e218285251baf2a54645 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 11 Jul 2017 09:51:43 +0200 Subject: rtems: Add rtems_scheduler_ident_by_processor_set Update #3070. --- cpukit/rtems/Makefile.am | 1 + cpukit/rtems/include/rtems/rtems/tasks.h | 25 +++++++++++ cpukit/rtems/src/scheduleridentbyprocessorset.c | 60 +++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 cpukit/rtems/src/scheduleridentbyprocessorset.c (limited to 'cpukit/rtems') diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index e9ad2deb5d..da6e302e2e 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -109,6 +109,7 @@ librtems_a_SOURCES += src/scheduleraddprocessor.c librtems_a_SOURCES += src/schedulergetprocessorset.c librtems_a_SOURCES += src/schedulerident.c librtems_a_SOURCES += src/scheduleridentbyprocessor.c +librtems_a_SOURCES += src/scheduleridentbyprocessorset.c librtems_a_SOURCES += src/schedulerremoveprocessor.c ## RATEMON_C_FILES diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h index e68c78989d..585f4c449c 100644 --- a/cpukit/rtems/include/rtems/rtems/tasks.h +++ b/cpukit/rtems/include/rtems/rtems/tasks.h @@ -576,6 +576,31 @@ rtems_status_code rtems_scheduler_ident_by_processor( rtems_id *id ); +/** + * @brief Identifies a scheduler by a processor set. + * + * The scheduler is selected according to the highest numbered online processor + * in the specified processor set. + * + * @param[in] cpusetsize Size of the specified processor set buffer in + * bytes. This value must be positive. + * @param[out] cpuset The processor set to identify the scheduler. + * @param[out] id The scheduler identifier associated with the processor set. + * + * @retval RTEMS_SUCCESSFUL Successful operation. + * @retval RTEMS_INVALID_ADDRESS The @a id parameter is @c NULL. + * @retval RTEMS_INVALID_SIZE Invalid processor set size. + * @retval RTEMS_INVALID_NAME The processor set contains no online processor. + * @retval RTEMS_INCORRECT_STATE The processor set is valid, however, the + * highest numbered online processor in the specified processor set is not + * owned by a scheduler. + */ +rtems_status_code rtems_scheduler_ident_by_processor_set( + size_t cpusetsize, + const cpu_set_t *cpuset, + rtems_id *id +); + /** * @brief Gets the set of processors owned by the specified scheduler instance. * diff --git a/cpukit/rtems/src/scheduleridentbyprocessorset.c b/cpukit/rtems/src/scheduleridentbyprocessorset.c new file mode 100644 index 0000000000..4988ed0fb8 --- /dev/null +++ b/cpukit/rtems/src/scheduleridentbyprocessorset.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2017 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include + +rtems_status_code rtems_scheduler_ident_by_processor_set( + size_t cpusetsize, + const cpu_set_t *cpuset, + rtems_id *id +) +{ + Processor_mask set; + Processor_mask_Copy_status status; + uint32_t cpu_index; + const Scheduler_Control *scheduler; + + if ( id == NULL ) { + return RTEMS_INVALID_ADDRESS; + } + + status = _Processor_mask_From_cpu_set_t( &set, cpusetsize, cpuset ); + if ( status == PROCESSOR_MASK_COPY_INVALID_SIZE ) { + return RTEMS_INVALID_SIZE; + } + + _Processor_mask_And( &set, &set, _SMP_Get_online_processors() ); + cpu_index = _Processor_mask_Find_last_set( &set ); + if ( cpu_index == 0 ) { + return RTEMS_INVALID_NAME; + } + + scheduler = _Scheduler_Get_by_CPU( _Per_CPU_Get_by_index( cpu_index - 1) ); +#if defined(RTEMS_SMP) + if ( scheduler == NULL ) { + return RTEMS_INCORRECT_STATE; + } +#else + _Assert( scheduler != NULL ); +#endif + + *id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) ); + return RTEMS_SUCCESSFUL; +} -- cgit v1.2.3