--- cpukit/rtems/Makefile.am | 2 + cpukit/rtems/include/rtems/rtems/tasks.h | 36 +++++++++++++++++ cpukit/rtems/src/schedulerident.c | 46 ++++++++++++++++++++++ cpukit/rtems/src/scheduleridentbyindex.c | 41 +++++++++++++++++++ cpukit/score/include/rtems/score/objectimpl.h | 5 ++- cpukit/score/include/rtems/score/schedulerimpl.h | 10 +++++ testsuites/sptests/spscheduler01/init.c | 36 +++++++++++++++++ 7 files changed, 175 insertions(+), 1 deletions(-) create mode 100644 cpukit/rtems/src/schedulerident.c create mode 100644 cpukit/rtems/src/scheduleridentbyindex.c
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index 70a8855..3962fa9 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -116,6 +116,8 @@ librtems_a_SOURCES += src/taskvariableget.c librtems_a_SOURCES += src/taskvariable_invoke_dtor.c endif librtems_a_SOURCES += src/taskdata.c +librtems_a_SOURCES += src/schedulerident.c +librtems_a_SOURCES += src/scheduleridentbyindex.c ## RATEMON_C_FILES librtems_a_SOURCES += src/ratemon.c diff --git a/cpukit/rtems/include/rtems/rtems/tasks.h b/cpukit/rtems/include/rtems/rtems/tasks.h index 4da32c4..fb0869e 100644 --- a/cpukit/rtems/include/rtems/rtems/tasks.h +++ b/cpukit/rtems/include/rtems/rtems/tasks.h @@ -548,6 +548,42 @@ rtems_status_code rtems_task_set_affinity( */ rtems_id rtems_task_self(void); +/** + * @brief Identifies a scheduler by its name. + * + * The scheduler name is determined by the scheduler configuration. + * + * @param[in] name The scheduler name. + * @param[out] id The scheduler identifier associated with the name. + * + * @retval RTEMS_SUCCESSFUL Successful operation. + * @retval RTEMS_INVALID_ADDRESS The @a id parameter is @c NULL. + * @retval RTEMS_INVALID_NAME Invalid scheduler name. + */ +rtems_status_code rtems_scheduler_ident( + rtems_name name, + rtems_id *id +); + +/** + * @brief Identifies a scheduler by its index. + * + * The scheduler index is determined by the scheduler configuration. + * + * @param[in] scheduler_index The scheduler index. The scheduler index ranges + * from zero to the scheduler count minus one. This is in contrast to object + * indices, which start with one. + * @param[out] id The scheduler identifier associated with the scheduler index. + * + * @retval RTEMS_SUCCESSFUL Successful operation. + * @retval RTEMS_INVALID_ADDRESS The @a id parameter is @c NULL. + * @retval RTEMS_INVALID_NAME Invalid scheduler index. + */ +rtems_status_code rtems_scheduler_ident_by_index( + uint32_t scheduler_index, + rtems_id *id +); + /**@}*/ /** diff --git a/cpukit/rtems/src/schedulerident.c b/cpukit/rtems/src/schedulerident.c new file mode 100644 index 0000000..d9e913c --- /dev/null +++ b/cpukit/rtems/src/schedulerident.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rt...@embedded-brains.de> + * + * 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/rtems/tasks.h> +#include <rtems/score/schedulerimpl.h> + +rtems_status_code rtems_scheduler_ident( + rtems_name name, + rtems_id *id +) +{ + rtems_status_code sc; + + if ( id != NULL ) { + size_t n = _Scheduler_Count; + size_t i; + + sc = RTEMS_INVALID_NAME; + + for ( i = 0 ; i < n && sc == RTEMS_INVALID_NAME ; ++i ) { + if ( _Scheduler_Table[ i ].name == name ) { + *id = _Scheduler_Build_id( i ); + sc = RTEMS_SUCCESSFUL; + } + } + } else { + sc = RTEMS_INVALID_ADDRESS; + } + + return sc; +} diff --git a/cpukit/rtems/src/scheduleridentbyindex.c b/cpukit/rtems/src/scheduleridentbyindex.c new file mode 100644 index 0000000..66cd222 --- /dev/null +++ b/cpukit/rtems/src/scheduleridentbyindex.c @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * <rt...@embedded-brains.de> + * + * 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/rtems/tasks.h> +#include <rtems/score/schedulerimpl.h> + +rtems_status_code rtems_scheduler_ident_by_index( + uint32_t scheduler_index, + rtems_id *id +) +{ + rtems_status_code sc; + + if ( id != NULL ) { + if ( scheduler_index < _Scheduler_Count ) { + *id = _Scheduler_Build_id( scheduler_index ); + sc = RTEMS_SUCCESSFUL; + } else { + sc = RTEMS_INVALID_NAME; + } + } else { + sc = RTEMS_INVALID_ADDRESS; + } + + return sc; +} diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h index 383f0a7..e47c6a8 100644 --- a/cpukit/score/include/rtems/score/objectimpl.h +++ b/cpukit/score/include/rtems/score/objectimpl.h @@ -71,7 +71,10 @@ typedef enum { OBJECTS_RTEMS_PORTS = 7, OBJECTS_RTEMS_PERIODS = 8, OBJECTS_RTEMS_EXTENSIONS = 9, - OBJECTS_RTEMS_BARRIERS = 10 + OBJECTS_RTEMS_BARRIERS = 10, + + /* The schedulers are no real objects, but they have an object identifier */ + OBJECTS_RTEMS_SCHEDULERS = 31 } Objects_Classic_API; /** This macro is used to generically specify the last API index. */ diff --git a/cpukit/score/include/rtems/score/schedulerimpl.h b/cpukit/score/include/rtems/score/schedulerimpl.h index abad068..e94c048 100644 --- a/cpukit/score/include/rtems/score/schedulerimpl.h +++ b/cpukit/score/include/rtems/score/schedulerimpl.h @@ -441,6 +441,16 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Scheduler_Get( return &_Scheduler_Table[ 0 ]; } +RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index ) +{ + return _Objects_Build_id( + OBJECTS_CLASSIC_API, + OBJECTS_RTEMS_SCHEDULERS, + _Objects_Local_node, + scheduler_index + 1 + ); +} + /** @} */ #ifdef __cplusplus diff --git a/testsuites/sptests/spscheduler01/init.c b/testsuites/sptests/spscheduler01/init.c index f8c4bb2..4452f60 100644 --- a/testsuites/sptests/spscheduler01/init.c +++ b/testsuites/sptests/spscheduler01/init.c @@ -98,6 +98,39 @@ static void test_task_get_set_affinity(void) #endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */ } +static void test_scheduler_ident(void) +{ + rtems_status_code sc; + rtems_id expected_id = rtems_build_id(2, 31, 1, 1); + rtems_id scheduler_id; + rtems_name name = rtems_build_name('b', 'l', 'u', 'e'); + rtems_name invalid_name = rtems_build_name(' ', 'r', 'e', 'd'); + + sc = rtems_scheduler_ident(name, NULL); + rtems_test_assert(sc == RTEMS_INVALID_ADDRESS); + + sc = rtems_scheduler_ident_by_index(0, NULL); + rtems_test_assert(sc == RTEMS_INVALID_ADDRESS); + + sc = rtems_scheduler_ident(invalid_name, &scheduler_id); + rtems_test_assert(sc == RTEMS_INVALID_NAME); + + sc = rtems_scheduler_ident_by_index(1, &scheduler_id); + rtems_test_assert(sc == RTEMS_INVALID_NAME); + + scheduler_id = 0; + sc = rtems_scheduler_ident(name, &scheduler_id); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + + rtems_test_assert(scheduler_id == expected_id); + + scheduler_id = 0; + sc = rtems_scheduler_ident_by_index(0, &scheduler_id); + rtems_test_assert(sc == RTEMS_SUCCESSFUL); + + rtems_test_assert(scheduler_id == expected_id); +} + static void Init(rtems_task_argument arg) { rtems_resource_snapshot snapshot; @@ -107,6 +140,7 @@ static void Init(rtems_task_argument arg) rtems_resource_snapshot_take(&snapshot); test_task_get_set_affinity(); + test_scheduler_ident(); rtems_test_assert(rtems_resource_snapshot_check(&snapshot)); @@ -125,6 +159,8 @@ static void Init(rtems_task_argument arg) #define CONFIGURE_RTEMS_INIT_TASKS_TABLE +#define CONFIGURE_SCHEDULER_NAME rtems_build_name('b', 'l', 'u', 'e') + #define CONFIGURE_INIT #include <rtems/confdefs.h> -- 1.7.7 _______________________________________________ rtems-devel mailing list rtems-devel@rtems.org http://www.rtems.org/mailman/listinfo/rtems-devel