posix: Move affinity from thread to scheduler.

This commit is contained in:
Jennifer Averett
2014-03-19 15:21:15 -05:00
parent 7205189ce3
commit e045fb6c60
4 changed files with 28 additions and 21 deletions

View File

@@ -42,8 +42,7 @@ int pthread_attr_setaffinity_np(
if ( !attr ) if ( !attr )
return EFAULT; return EFAULT;
error = _CPU_set_Is_valid( cpuset, cpusetsize ); if (! _CPU_set_Is_valid( cpuset, cpusetsize ) )
if ( error != 0 )
return EINVAL; return EINVAL;
CPU_COPY( attr->affinityset, cpuset ); CPU_COPY( attr->affinityset, cpuset );

View File

@@ -32,6 +32,8 @@
#include <rtems/score/apimutex.h> #include <rtems/score/apimutex.h>
#include <rtems/score/stackimpl.h> #include <rtems/score/stackimpl.h>
#include <rtems/score/watchdogimpl.h> #include <rtems/score/watchdogimpl.h>
#include <rtems/score/schedulerimpl.h>
static inline size_t _POSIX_Threads_Ensure_minimum_stack ( static inline size_t _POSIX_Threads_Ensure_minimum_stack (
size_t size size_t size
@@ -139,8 +141,8 @@ int pthread_create(
#if defined(RTEMS_SMP) #if defined(RTEMS_SMP)
#if __RTEMS_HAVE_SYS_CPUSET_H__ #if __RTEMS_HAVE_SYS_CPUSET_H__
rc = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize ); status = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize );
if ( rc != 0 ) if (!status )
return EINVAL; return EINVAL;
#endif #endif
#endif #endif
@@ -191,8 +193,16 @@ int pthread_create(
#if defined(RTEMS_SMP) #if defined(RTEMS_SMP)
#if __RTEMS_HAVE_SYS_CPUSET_H__ #if __RTEMS_HAVE_SYS_CPUSET_H__
the_thread->affinity.setsize = the_attr->affinitysetsize; status = _Scheduler_Set_affinity(
*the_thread->affinity.set = *the_attr->affinityset; the_thread,
attr->affinitysetsize,
attr->affinityset
);
if ( !status ) {
_POSIX_Threads_Free( the_thread );
_RTEMS_Unlock_allocator();
return EINVAL;
}
#endif #endif
#endif #endif

View File

@@ -28,6 +28,7 @@
#include <rtems/posix/pthreadimpl.h> #include <rtems/posix/pthreadimpl.h>
#include <rtems/posix/priorityimpl.h> #include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h> #include <rtems/score/threadimpl.h>
#include <rtems/score/schedulerimpl.h>
int pthread_getaffinity_np( int pthread_getaffinity_np(
const pthread_t id, const pthread_t id,
@@ -37,7 +38,7 @@ int pthread_getaffinity_np(
{ {
Objects_Locations location; Objects_Locations location;
Thread_Control *the_thread; Thread_Control *the_thread;
int error; bool ok;
if ( !cpuset ) if ( !cpuset )
return EFAULT; return EFAULT;
@@ -46,14 +47,11 @@ int pthread_getaffinity_np(
switch ( location ) { switch ( location ) {
case OBJECTS_LOCAL: case OBJECTS_LOCAL:
error = 0; ok = _Scheduler_Get_affinity( the_thread, cpusetsize, cpuset );
if ( cpusetsize != the_thread->affinity.setsize )
error = EINVAL;
else
CPU_COPY( cpuset, the_thread->affinity.set );
_Objects_Put( &the_thread->Object ); _Objects_Put( &the_thread->Object );
return error; if (!ok)
return EINVAL;
return 0;
break; break;
#if defined(RTEMS_MULTIPROCESSING) #if defined(RTEMS_MULTIPROCESSING)

View File

@@ -28,6 +28,7 @@
#include <rtems/posix/priorityimpl.h> #include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h> #include <rtems/score/threadimpl.h>
#include <rtems/score/cpusetimpl.h> #include <rtems/score/cpusetimpl.h>
#include <rtems/score/schedulerimpl.h>
int pthread_setaffinity_np( int pthread_setaffinity_np(
pthread_t id, pthread_t id,
@@ -37,23 +38,22 @@ int pthread_setaffinity_np(
Objects_Locations location; Objects_Locations location;
POSIX_API_Control *api; POSIX_API_Control *api;
Thread_Control *the_thread; Thread_Control *the_thread;
int error; bool ok;
if ( !cpuset ) if ( !cpuset )
return EFAULT; return EFAULT;
error = _CPU_set_Is_valid( cpuset, cpusetsize );
if ( error != 0 )
return EINVAL;
the_thread = _Thread_Get( id, &location ); the_thread = _Thread_Get( id, &location );
switch ( location ) { switch ( location ) {
case OBJECTS_LOCAL: case OBJECTS_LOCAL:
api = the_thread->API_Extensions[ THREAD_API_POSIX ]; api = the_thread->API_Extensions[ THREAD_API_POSIX ];
CPU_COPY( the_thread->affinity.set, cpuset ); ok = _Scheduler_Set_affinity( the_thread, cpusetsize, cpuset );
CPU_COPY( api->Attributes.affinityset, cpuset ); if (ok)
CPU_COPY( api->Attributes.affinityset, cpuset );
_Objects_Put( &the_thread->Object ); _Objects_Put( &the_thread->Object );
if (!ok)
return EINVAL;
return 0; return 0;
break; break;