[rtems commit] posix: Move affinity from thread to scheduler.
Jennifer Averett
jennifer at rtems.org
Thu Apr 3 16:13:11 UTC 2014
Module: rtems
Branch: master
Commit: e045fb6c60a495aafd2ced0fd756862a66e98ce3
Changeset: http://git.rtems.org/rtems/commit/?id=e045fb6c60a495aafd2ced0fd756862a66e98ce3
Author: Jennifer Averett <jennifer.averett at oarcorp.com>
Date: Wed Mar 19 15:21:15 2014 -0500
posix: Move affinity from thread to scheduler.
---
cpukit/posix/src/pthreadattrsetaffinitynp.c | 3 +--
cpukit/posix/src/pthreadcreate.c | 18 ++++++++++++++----
cpukit/posix/src/pthreadgetaffinitynp.c | 14 ++++++--------
cpukit/posix/src/pthreadsetaffinitynp.c | 14 +++++++-------
4 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/cpukit/posix/src/pthreadattrsetaffinitynp.c b/cpukit/posix/src/pthreadattrsetaffinitynp.c
index 66811f1..b880e5a 100644
--- a/cpukit/posix/src/pthreadattrsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadattrsetaffinitynp.c
@@ -42,8 +42,7 @@ int pthread_attr_setaffinity_np(
if ( !attr )
return EFAULT;
- error = _CPU_set_Is_valid( cpuset, cpusetsize );
- if ( error != 0 )
+ if (! _CPU_set_Is_valid( cpuset, cpusetsize ) )
return EINVAL;
CPU_COPY( attr->affinityset, cpuset );
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 8d03133..8db6948 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -32,6 +32,8 @@
#include <rtems/score/apimutex.h>
#include <rtems/score/stackimpl.h>
#include <rtems/score/watchdogimpl.h>
+#include <rtems/score/schedulerimpl.h>
+
static inline size_t _POSIX_Threads_Ensure_minimum_stack (
size_t size
@@ -139,8 +141,8 @@ int pthread_create(
#if defined(RTEMS_SMP)
#if __RTEMS_HAVE_SYS_CPUSET_H__
- rc = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize );
- if ( rc != 0 )
+ status = _CPU_set_Is_valid( the_attr->affinityset, the_attr->affinitysetsize );
+ if (!status )
return EINVAL;
#endif
#endif
@@ -191,8 +193,16 @@ int pthread_create(
#if defined(RTEMS_SMP)
#if __RTEMS_HAVE_SYS_CPUSET_H__
- the_thread->affinity.setsize = the_attr->affinitysetsize;
- *the_thread->affinity.set = *the_attr->affinityset;
+ status = _Scheduler_Set_affinity(
+ the_thread,
+ attr->affinitysetsize,
+ attr->affinityset
+ );
+ if ( !status ) {
+ _POSIX_Threads_Free( the_thread );
+ _RTEMS_Unlock_allocator();
+ return EINVAL;
+ }
#endif
#endif
diff --git a/cpukit/posix/src/pthreadgetaffinitynp.c b/cpukit/posix/src/pthreadgetaffinitynp.c
index 082e41a..497236f 100644
--- a/cpukit/posix/src/pthreadgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadgetaffinitynp.c
@@ -28,6 +28,7 @@
#include <rtems/posix/pthreadimpl.h>
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
+#include <rtems/score/schedulerimpl.h>
int pthread_getaffinity_np(
const pthread_t id,
@@ -37,7 +38,7 @@ int pthread_getaffinity_np(
{
Objects_Locations location;
Thread_Control *the_thread;
- int error;
+ bool ok;
if ( !cpuset )
return EFAULT;
@@ -46,14 +47,11 @@ int pthread_getaffinity_np(
switch ( location ) {
case OBJECTS_LOCAL:
- error = 0;
- if ( cpusetsize != the_thread->affinity.setsize )
- error = EINVAL;
- else
- CPU_COPY( cpuset, the_thread->affinity.set );
-
+ ok = _Scheduler_Get_affinity( the_thread, cpusetsize, cpuset );
_Objects_Put( &the_thread->Object );
- return error;
+ if (!ok)
+ return EINVAL;
+ return 0;
break;
#if defined(RTEMS_MULTIPROCESSING)
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c
index fc2194d..d150b40 100644
--- a/cpukit/posix/src/pthreadsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadsetaffinitynp.c
@@ -28,6 +28,7 @@
#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/cpusetimpl.h>
+#include <rtems/score/schedulerimpl.h>
int pthread_setaffinity_np(
pthread_t id,
@@ -37,23 +38,22 @@ int pthread_setaffinity_np(
Objects_Locations location;
POSIX_API_Control *api;
Thread_Control *the_thread;
- int error;
+ bool ok;
if ( !cpuset )
return EFAULT;
- error = _CPU_set_Is_valid( cpuset, cpusetsize );
- if ( error != 0 )
- return EINVAL;
-
the_thread = _Thread_Get( id, &location );
switch ( location ) {
case OBJECTS_LOCAL:
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- CPU_COPY( the_thread->affinity.set, cpuset );
- CPU_COPY( api->Attributes.affinityset, cpuset );
+ ok = _Scheduler_Set_affinity( the_thread, cpusetsize, cpuset );
+ if (ok)
+ CPU_COPY( api->Attributes.affinityset, cpuset );
_Objects_Put( &the_thread->Object );
+ if (!ok)
+ return EINVAL;
return 0;
break;
More information about the vc
mailing list