score: _Scheduler_Set_affinity()

Do not change the scheduler with this function.  Documentation.  Coding
style.
This commit is contained in:
Sebastian Huber
2014-05-28 18:11:51 +02:00
parent a92c4882bb
commit 25f5730fe5
5 changed files with 42 additions and 49 deletions

View File

@@ -521,6 +521,17 @@ rtems_status_code rtems_task_get_affinity(
/**
* @brief Sets the processor affinity set of a task.
*
* This function will not change the scheduler of the task. The intersection
* of the processor affinity set and the set of processors owned by the
* scheduler of the task must be non-empty. It is not an error if the
* processor affinity set contains processors that are not part of the set of
* processors owned by the scheduler instance of the task. A task will simply
* not run under normal circumstances on these processors since the scheduler
* ignores them. Some locking protocols may temporarily use processors that
* are not included in the processor affinity set of the task. It is also not
* an error if the processor affinity set contains processors that are not part
* of the system.
*
* @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

View File

@@ -418,7 +418,6 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
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;
@@ -429,8 +428,7 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
_Scheduler_Get_by_CPU_index( cpu_index );
ok = ok
&& ( ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
&& scheduler == scheduler_of_cpu )
&& ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
|| ( !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset )
&& scheduler != scheduler_of_cpu ) );
#else
@@ -440,12 +438,6 @@ RTEMS_INLINE_ROUTINE bool _Scheduler_default_Set_affinity_body(
#endif
}
for ( ; cpu_index < cpu_max ; ++cpu_index ) {
ok = ok && !CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset );
}
_Scheduler_Set( scheduler, the_thread );
return ok;
}

View File

@@ -26,45 +26,27 @@ bool _Scheduler_Set_affinity(
const cpu_set_t *cpuset
)
{
bool ok;
const Scheduler_Control *scheduler = _Scheduler_Get( the_thread );
if ( _CPU_set_Is_large_enough( cpusetsize ) ) {
#if defined(RTEMS_SMP)
uint32_t cpu_count = _SMP_Get_processor_count();
uint32_t cpu_index;
ok = false;
for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) {
if ( CPU_ISSET_S( (int) cpu_index, cpusetsize, cpuset ) ) {
const Scheduler_Control *scheduler_of_cpu =
_Scheduler_Get_by_CPU_index( cpu_index );
if ( scheduler_of_cpu != NULL ) {
ok = ( *scheduler_of_cpu->Operations.set_affinity )(
scheduler_of_cpu,
the_thread,
cpusetsize,
cpuset
);
}
break;
}
}
#else
ok = _Scheduler_default_Set_affinity_body(
_Scheduler_Get( the_thread ),
the_thread,
cpusetsize,
cpuset
);
#endif
} else {
ok = false;
if ( !_CPU_set_Is_large_enough( cpusetsize ) ) {
return false;
}
return ok;
#if defined(RTEMS_SMP)
return ( *scheduler->Operations.set_affinity )(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#else
return _Scheduler_default_Set_affinity_body(
scheduler,
the_thread,
cpusetsize,
cpuset
);
#endif
}
#endif /* defined(__RTEMS_HAVE_SYS_CPUSET_H__) */

View File

@@ -622,4 +622,12 @@ cleared bit means the opposite.
@subheading NOTES:
None.
This function will not change the scheduler of the task. The intersection of
the processor affinity set and the set of processors owned by the scheduler of
the task must be non-empty. It is not an error if the processor affinity set
contains processors that are not part of the set of processors owned by the
scheduler instance of the task. A task will simply not run under normal
circumstances on these processors since the scheduler ignores them. Some
locking protocols may temporarily use processors that are not included in the
processor affinity set of the task. It is also not an error if the processor
affinity set contains processors that are not part of the system.

View File

@@ -139,14 +139,14 @@ static void test(void)
rtems_test_assert(CPU_EQUAL(&cpuset, &second_cpu));
sc = rtems_task_set_affinity(task_id, sizeof(all_cpus), &all_cpus);
rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
sc = rtems_task_set_affinity(task_id, sizeof(first_cpu), &first_cpu);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(sc == RTEMS_INVALID_NUMBER);
sc = rtems_task_get_scheduler(task_id, &scheduler_id);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
rtems_test_assert(scheduler_id == scheduler_a_id);
rtems_test_assert(scheduler_id == scheduler_b_id);
sc = rtems_task_set_affinity(task_id, sizeof(second_cpu), &second_cpu);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);