score: Task get/set affinity

Make rtems_task_get_affinity() and rtems_task_set_affinity() available
on non-SMP configurations.  Allow larger CPU sets.
This commit is contained in:
Sebastian Huber
2014-04-15 08:37:12 +02:00
parent 69aa33490b
commit 0712d172d0
15 changed files with 410 additions and 91 deletions
+2 -7
View File
@@ -92,6 +92,7 @@ librtems_a_SOURCES += src/rtemsobjectgetclassicname.c
librtems_a_SOURCES += src/tasks.c
librtems_a_SOURCES += src/taskcreate.c
librtems_a_SOURCES += src/taskdelete.c
librtems_a_SOURCES += src/taskgetaffinity.c
librtems_a_SOURCES += src/taskgetnote.c
librtems_a_SOURCES += src/taskident.c
librtems_a_SOURCES += src/taskinitusers.c
@@ -100,6 +101,7 @@ librtems_a_SOURCES += src/taskmode.c
librtems_a_SOURCES += src/taskrestart.c
librtems_a_SOURCES += src/taskresume.c
librtems_a_SOURCES += src/taskself.c
librtems_a_SOURCES += src/tasksetaffinity.c
librtems_a_SOURCES += src/tasksetnote.c
librtems_a_SOURCES += src/tasksetpriority.c
librtems_a_SOURCES += src/taskstart.c
@@ -274,12 +276,5 @@ librtems_a_SOURCES += src/signalmp.c
librtems_a_SOURCES += src/taskmp.c
endif
## SMP Files
if HAS_SMP
librtems_a_SOURCES += src/tasksetaffinity.c
librtems_a_SOURCES += src/taskgetaffinity.c
endif
include $(srcdir)/preinstall.am
include $(top_srcdir)/automake/local.am
+26 -24
View File
@@ -494,22 +494,23 @@ rtems_status_code rtems_task_variable_delete(
);
#endif
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
/**
* @brief RTEMS Get Task Affinity
* @brief Gets the processor affinity set of a task.
*
* This directive returns the cpuset for the
* given task. The cpuset size must be the
* same size as the task affinity set size.
* @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
* bytes. This value must be positive.
* @param[out] cpuset The current processor affinity set of the task. A set
* bit in the affinity set means that the task can execute on this processor
* and a cleared bit means the opposite.
*
* @param[in] id is the thread to extract
* @param[in] cpusetsize is the size of the cpuset
* @param[out] cpuset is the tasks affinity cpuset
*
* @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
* @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
* @retval RTEMS_INVALID_NUMBER if cpusetsize is incorrect
* @retval RTEMS_INVALID_ID if id not valid
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
* @retval RTEMS_INVALID_ID Invalid task identifier.
* @retval RTEMS_INVALID_NUMBER The affinity set buffer is too small for the
* current processor affinity set of the task.
*/
rtems_status_code rtems_task_get_affinity(
rtems_id id,
@@ -518,19 +519,20 @@ rtems_status_code rtems_task_get_affinity(
);
/**
* @brief RTEMS Set Task Affinity
* @brief Sets the processor affinity set of a task.
*
* This directive sets the given tasks
* affinity cpuset.
* @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
* bytes. This value must be positive.
* @param[in] cpuset The new processor affinity set for the task. A set bit in
* the affinity set means that the task can execute on this processor and a
* cleared bit means the opposite.
*
* @param[in] id is the thread to extract
* @param[in] cpusetsize is the size of the cpuset
* @param[in] cpuset is affinity set to assign to the task
*
* @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
* @retval RTEMS_INVALID_ADDRESS if cpuset is NULL
* @retval RTEMS_INVALID_NUMBER if cpuset or cpusetsize is incorrect
* @retval RTEMS_INVALID_ID if id not valid
* @retval RTEMS_SUCCESSFUL Successful operation.
* @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
* @retval RTEMS_INVALID_ID Invalid task identifier.
* @retval RTEMS_INVALID_NUMBER Invalid processor affinity set.
*/
rtems_status_code rtems_task_set_affinity(
rtems_id id,
+2
View File
@@ -195,6 +195,8 @@ libscore_a_SOURCES += src/objectallocate.c src/objectclose.c \
## SCHEDULER_C_FILES
libscore_a_SOURCES += src/log2table.c
libscore_a_SOURCES += src/scheduler.c
libscore_a_SOURCES += src/schedulergetaffinity.c
libscore_a_SOURCES += src/schedulersetaffinity.c
libscore_a_SOURCES += src/schedulerdefaultallocatefree.c
libscore_a_SOURCES += src/schedulerdefaultreleasejob.c
libscore_a_SOURCES += src/schedulerdefaultstartidle.c
@@ -20,6 +20,9 @@
#define _RTEMS_SCORE_CPUSETIMPL_H
#include <rtems/score/cpuset.h>
#include <rtems/score/smp.h>
#include <limits.h>
#ifdef __cplusplus
extern "C" {
@@ -58,6 +61,21 @@ void _CPU_set_Show_default( const char *description );
*/
const CPU_set_Control *_CPU_set_Default(void);
RTEMS_INLINE_ROUTINE size_t _CPU_set_Maximum_CPU_count(
size_t cpusetsize
)
{
return cpusetsize * CHAR_BIT;
}
RTEMS_INLINE_ROUTINE bool _CPU_set_Is_large_enough(
size_t cpusetsize
)
{
return _CPU_set_Maximum_CPU_count( cpusetsize )
>= _SMP_Get_processor_count();
}
#endif
/**
@@ -20,6 +20,7 @@
#define _RTEMS_SCORE_SCHEDULERIMPL_H
#include <rtems/score/scheduler.h>
#include <rtems/score/cpusetimpl.h>
#include <rtems/score/threadimpl.h>
#ifdef __cplusplus
@@ -257,49 +258,81 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Start_idle(
( *scheduler->Operations.start_idle )( scheduler, the_thread, cpu );
}
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__) && defined(RTEMS_SMP)
/**
* @brief Obtain the processor affinity for a thread.
*
* @param[in,out] thread The thread.
* @parma[out] cpuset The processor affinity for this thread
*/
RTEMS_INLINE_ROUTINE int _Scheduler_Get_affinity(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
cpu_set_t *cpuset
)
{
return ( *scheduler->Operations.get_affinity )(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
RTEMS_INLINE_ROUTINE void _Scheduler_Get_processor_set(
const Scheduler_Control *scheduler,
size_t cpusetsize,
cpu_set_t *cpuset
)
{
uint32_t cpu_count = _SMP_Get_processor_count();
uint32_t cpu_index;
(void) scheduler;
CPU_ZERO_S( cpusetsize, cpuset );
for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
CPU_SET_S( (int) cpu_index, cpusetsize, cpuset );
}
}
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(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
cpu_set_t *cpuset
);
RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
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;
(void) scheduler;
(void) the_thread;
for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
ok = ok && CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
}
/**
* @brief Set the processor affinity for a thread.
*
* @param[in,out] thread The thread.
* @parma[in] cpuset The processor affinity for this thread
*/
RTEMS_INLINE_ROUTINE int _Scheduler_Set_affinity(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
const cpu_set_t *cpuset
)
{
return ( *scheduler->Operations.set_affinity )(
scheduler,
the_thread,
cpusetsize,
cpuset
);
for ( ; cpu_index < cpu_max ; ++cpu_index ) {
ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
}
#endif
return ok;
}
bool _Scheduler_Set_affinity(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
const cpu_set_t *cpuset
);
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
RTEMS_INLINE_ROUTINE void _Scheduler_Update_heir(
Thread_Control *heir,
+6 -14
View File
@@ -20,7 +20,6 @@
#endif
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/cpusetimpl.h>
bool _Scheduler_default_Get_affinity(
const Scheduler_Control *scheduler,
@@ -29,17 +28,10 @@ bool _Scheduler_default_Get_affinity(
cpu_set_t *cpuset
)
{
const CPU_set_Control *ctl;
(void) scheduler;
(void) thread;
ctl = _CPU_set_Default();
if ( cpusetsize != ctl->setsize ) {
return false;
}
CPU_COPY( cpuset, ctl->set );
return true;
return _Scheduler_default_Get_affinity_body(
scheduler,
thread,
cpusetsize,
cpuset
);
}
@@ -20,7 +20,6 @@
#endif
#include <rtems/score/schedulerimpl.h>
#include <rtems/score/cpusetimpl.h>
bool _Scheduler_default_Set_affinity(
const Scheduler_Control *scheduler,
@@ -29,8 +28,10 @@ bool _Scheduler_default_Set_affinity(
const cpu_set_t *cpuset
)
{
(void) scheduler;
(void) thread;
return _CPU_set_Is_valid( cpuset, cpusetsize );
return _Scheduler_default_Set_affinity_body(
scheduler,
thread,
cpusetsize,
cpuset
);
}
+55
View File
@@ -0,0 +1,55 @@
/*
* 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
#include <rtems/score/schedulerimpl.h>
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
bool _Scheduler_Get_affinity(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
cpu_set_t *cpuset
)
{
bool ok;
if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
#if defined(RTEMS_SMP)
ok = ( *scheduler->Operations.get_affinity )(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#else
ok = _Scheduler_default_Get_affinity_body(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#endif
} else {
ok = false;
}
return ok;
}
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
+55
View File
@@ -0,0 +1,55 @@
/*
* 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
#include <rtems/score/schedulerimpl.h>
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
bool _Scheduler_Set_affinity(
const Scheduler_Control *scheduler,
Thread_Control *the_thread,
size_t cpusetsize,
const cpu_set_t *cpuset
)
{
bool ok;
if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
#if defined(RTEMS_SMP)
ok = ( *scheduler->Operations.set_affinity )(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#else
ok = _Scheduler_default_Set_affinity_body(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#endif
} else {
ok = false;
}
return ok;
}
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
+2 -1
View File
@@ -37,7 +37,8 @@ if HAS_SMP
else
SUBDIRS += sp29
endif
SUBDIRS += spprofiling01
SUBDIRS += spscheduler01
SUBDIRS += spprofiling01
SUBDIRS += spfatal28
SUBDIRS += spthreadlife01
SUBDIRS += spprofiling01
+1
View File
@@ -40,6 +40,7 @@ AM_CONDITIONAL(HAS_SMP,test "$rtems_cv_RTEMS_SMP" = "yes")
# Explicitly list all Makefiles here
AC_CONFIG_FILES([Makefile
spscheduler01/Makefile
spfatal28/Makefile
spthreadlife01/Makefile
spprofiling01/Makefile
@@ -0,0 +1,19 @@
rtems_tests_PROGRAMS = spscheduler01
spscheduler01_SOURCES = init.c
dist_rtems_tests_DATA = spscheduler01.scn spscheduler01.doc
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
include $(top_srcdir)/../automake/compile.am
include $(top_srcdir)/../automake/leaf.am
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
LINK_OBJS = $(spscheduler01_OBJECTS)
LINK_LIBS = $(spscheduler01_LDLIBS)
spscheduler01$(EXEEXT): $(spscheduler01_OBJECTS) $(spscheduler01_DEPENDENCIES)
@rm -f spscheduler01$(EXEEXT)
$(make-exe)
include $(top_srcdir)/../automake/local.am
+130
View File
@@ -0,0 +1,130 @@
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/libcsupport.h>
#include <limits.h>
#include "tmacros.h"
const char rtems_test_name[] = "SPSCHEDULER 1";
static rtems_id invalid_id = 1;
static void test_task_get_set_affinity(void)
{
#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
rtems_id self_id = rtems_task_self();
rtems_status_code sc;
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_task_get_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), NULL);
rtems_test_assert(sc == RTEMS_INVALID_ADDRESS);
sc = rtems_task_get_affinity(RTEMS_SELF, 0, &cpuset);
rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
sc = rtems_task_set_affinity(RTEMS_SELF, 0, &cpuset);
rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
sc = rtems_task_get_affinity(invalid_id, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_INVALID_ID);
sc = rtems_task_set_affinity(invalid_id, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_INVALID_ID);
sc = rtems_task_get_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
sc = rtems_task_set_affinity(RTEMS_SELF, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_get_affinity(self_id, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(CPU_EQUAL(&cpuset, &cpusetone));
sc = rtems_task_set_affinity(self_id, sizeof(cpuset), &cpuset);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
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_task_get_affinity(RTEMS_SELF, cpusetbigsize, cpusetbig);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(CPU_EQUAL_S(cpusetbigsize, cpusetbig, cpusetbigone));
sc = rtems_task_set_affinity(RTEMS_SELF, cpusetbigsize, cpusetbig);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
CPU_FREE(cpusetbig);
CPU_FREE(cpusetbigone);
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */
}
static void Init(rtems_task_argument arg)
{
rtems_resource_snapshot snapshot;
TEST_BEGIN();
rtems_resource_snapshot_take(&snapshot);
test_task_get_set_affinity();
rtems_test_assert(rtems_resource_snapshot_check(&snapshot));
TEST_END();
rtems_test_exit(0);
}
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
@@ -0,0 +1,13 @@
This file describes the directives and concepts tested by this test set.
test set name: spscheduler01
directives:
- rtems_task_get_affinity()
- rtems_task_set_affinity()
concepts:
- Ensure that the task set/get affinity functions work on non-SMP
configurations.
@@ -0,0 +1,2 @@
*** BEGIN OF TEST SPSCHEDULER 1 ***
*** END OF TEST SPSCHEDULER 1 ***