forked from Imagelibrary/rtems
rtems: Add scheduler get processors
This commit is contained in:
@@ -116,6 +116,7 @@ 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/schedulergetprocessorset.c
|
||||
librtems_a_SOURCES += src/schedulerident.c
|
||||
|
||||
## RATEMON_C_FILES
|
||||
|
||||
@@ -565,6 +565,30 @@ rtems_status_code rtems_scheduler_ident(
|
||||
rtems_id *id
|
||||
);
|
||||
|
||||
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
|
||||
/**
|
||||
* @brief Gets the set of processors owned by the scheduler.
|
||||
*
|
||||
* @param[in] scheduler_id Identifier of the scheduler.
|
||||
* @param[in] cpusetsize Size of the specified processor set buffer in
|
||||
* bytes. This value must be positive.
|
||||
* @param[out] cpuset The processor set owned by the scheduler. A set bit in
|
||||
* the processor set means that this processor is owned by the scheduler and a
|
||||
* cleared bit means the opposite.
|
||||
*
|
||||
* @retval RTEMS_SUCCESSFUL Successful operation.
|
||||
* @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
|
||||
* @retval RTEMS_INVALID_ID Invalid scheduler identifier.
|
||||
* @retval RTEMS_INVALID_NUMBER The processor set buffer is too small for the
|
||||
* set of processors owned by the scheduler.
|
||||
*/
|
||||
rtems_status_code rtems_scheduler_get_processor_set(
|
||||
rtems_id scheduler_id,
|
||||
size_t cpusetsize,
|
||||
cpu_set_t *cpuset
|
||||
);
|
||||
#endif
|
||||
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
|
||||
54
cpukit/rtems/src/schedulergetprocessorset.c
Normal file
54
cpukit/rtems/src/schedulergetprocessorset.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2014 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@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
|
||||
|
||||
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
|
||||
|
||||
#include <rtems/rtems/tasks.h>
|
||||
#include <rtems/score/cpusetimpl.h>
|
||||
#include <rtems/score/schedulerimpl.h>
|
||||
|
||||
rtems_status_code rtems_scheduler_get_processor_set(
|
||||
rtems_id scheduler_id,
|
||||
size_t cpusetsize,
|
||||
cpu_set_t *cpuset
|
||||
)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
|
||||
if ( cpuset != NULL ) {
|
||||
const Scheduler_Control *scheduler;
|
||||
|
||||
if ( _Scheduler_Get_by_id( scheduler_id, &scheduler ) ) {
|
||||
if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
|
||||
_Scheduler_Get_processor_set( scheduler, cpusetsize, cpuset );
|
||||
|
||||
sc = RTEMS_SUCCESSFUL;
|
||||
} else {
|
||||
sc = RTEMS_INVALID_NUMBER;
|
||||
}
|
||||
} else {
|
||||
sc = RTEMS_INVALID_ID;
|
||||
}
|
||||
} else {
|
||||
sc = RTEMS_INVALID_ADDRESS;
|
||||
}
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
|
||||
@@ -461,6 +461,19 @@ RTEMS_INLINE_ROUTINE Objects_Id _Scheduler_Build_id( uint32_t scheduler_index )
|
||||
);
|
||||
}
|
||||
|
||||
RTEMS_INLINE_ROUTINE bool _Scheduler_Get_by_id(
|
||||
Objects_Id id,
|
||||
const Scheduler_Control **scheduler
|
||||
)
|
||||
{
|
||||
uint32_t minimum_id = _Scheduler_Build_id( 0 );
|
||||
uint32_t index = id - minimum_id;
|
||||
|
||||
*scheduler = &_Scheduler_Table[ index ];
|
||||
|
||||
return index < _Scheduler_Count;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -123,6 +123,58 @@ static void test_scheduler_ident(void)
|
||||
rtems_test_assert(scheduler_id == expected_id);
|
||||
}
|
||||
|
||||
static void test_scheduler_get_processors(void)
|
||||
{
|
||||
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
|
||||
rtems_status_code sc;
|
||||
rtems_name name = BLUE;
|
||||
rtems_id scheduler_id;
|
||||
cpu_set_t cpusetone;
|
||||
cpu_set_t cpuset;
|
||||
size_t big = 2 * CHAR_BIT * sizeof(cpu_set_t);
|
||||
size_t cpusetbigsize = CPU_ALLOC_SIZE(big);
|
||||
cpu_set_t *cpusetbigone;
|
||||
cpu_set_t *cpusetbig;
|
||||
|
||||
CPU_ZERO(&cpusetone);
|
||||
CPU_SET(0, &cpusetone);
|
||||
|
||||
sc = rtems_scheduler_ident(name, &scheduler_id);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
sc = rtems_scheduler_get_processor_set(scheduler_id, sizeof(cpuset), NULL);
|
||||
rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
|
||||
|
||||
sc = rtems_scheduler_get_processor_set(invalid_id, sizeof(cpuset), &cpuset);
|
||||
rtems_test_assert(sc == RTEMS_INVALID_ID);
|
||||
|
||||
sc = rtems_scheduler_get_processor_set(scheduler_id, 0, &cpuset);
|
||||
rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
|
||||
|
||||
sc = rtems_scheduler_get_processor_set(scheduler_id, sizeof(cpuset), &cpuset);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
|
||||
|
||||
cpusetbigone = CPU_ALLOC(big);
|
||||
rtems_test_assert(cpusetbigone != NULL);
|
||||
|
||||
cpusetbig = CPU_ALLOC(big);
|
||||
rtems_test_assert(cpusetbig != NULL);
|
||||
|
||||
CPU_ZERO_S(cpusetbigsize, cpusetbigone);
|
||||
CPU_SET_S(0, cpusetbigsize, cpusetbigone);
|
||||
|
||||
sc = rtems_scheduler_get_processor_set(scheduler_id, cpusetbigsize, cpusetbig);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));
|
||||
|
||||
CPU_FREE(cpusetbig);
|
||||
CPU_FREE(cpusetbigone);
|
||||
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
|
||||
}
|
||||
|
||||
static void Init(rtems_task_argument arg)
|
||||
{
|
||||
rtems_resource_snapshot snapshot;
|
||||
@@ -133,6 +185,7 @@ static void Init(rtems_task_argument arg)
|
||||
|
||||
test_task_get_set_affinity();
|
||||
test_scheduler_ident();
|
||||
test_scheduler_get_processors();
|
||||
|
||||
rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user