summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-06 10:07:38 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-09 14:52:58 +0200
commitaf9115f35cfb3d0adeb3e105fd608883596f2637 (patch)
treed6638dc66e87ad1736f7675f79e7e6d116e5c463 /cpukit/posix
parent65012bfebbc03088f0740b086abb26d2ff6ebd8b (diff)
downloadrtems-af9115f35cfb3d0adeb3e105fd608883596f2637.tar.bz2
posix: Simplify POSIX_API_Control
Return stack area via pthread_getattr_np(). Simplify * pthread_attr_setaffinity_np(), and * pthread_attr_getaffinity_np() and let the scheduler do the more sophisticated error checks. Make * pthread_setaffinity_np(), * pthread_getaffinity_np(), * pthread_attr_setaffinity_np(), and * pthread_attr_getaffinity_np() available in all configurations. Update #2514. Close #3145. Close #3168.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/Makefile.am12
-rw-r--r--cpukit/posix/include/rtems/posix/pthreadimpl.h4
-rw-r--r--cpukit/posix/include/rtems/posix/threadsup.h10
-rw-r--r--cpukit/posix/preinstall.am2
-rw-r--r--cpukit/posix/src/pthread.c13
-rw-r--r--cpukit/posix/src/pthreadattrcompare.c5
-rw-r--r--cpukit/posix/src/pthreadattrgetaffinitynp.c14
-rw-r--r--cpukit/posix/src/pthreadattrsetaffinitynp.c16
-rw-r--r--cpukit/posix/src/pthreadcreate.c5
-rw-r--r--cpukit/posix/src/pthreadgetaffinitynp.c2
-rw-r--r--cpukit/posix/src/pthreadgetattrnp.c31
-rw-r--r--cpukit/posix/src/pthreadgetschedparam.c4
-rw-r--r--cpukit/posix/src/pthreadsetaffinitynp.c9
-rw-r--r--cpukit/posix/src/pthreadsetschedparam.c4
14 files changed, 73 insertions, 58 deletions
diff --git a/cpukit/posix/Makefile.am b/cpukit/posix/Makefile.am
index a4ce099752..627030bcb4 100644
--- a/cpukit/posix/Makefile.am
+++ b/cpukit/posix/Makefile.am
@@ -89,6 +89,11 @@ libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
src/mutextrylock.c src/mutexunlock.c
+## PTHREAD_AFFINITY_C_FILES
+libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
+ src/pthreadattrgetaffinitynp.c src/pthreadgetaffinitynp.c \
+ src/pthreadsetaffinitynp.c
+
if HAS_PTHREADS
libposix_a_SOURCES += src/pthreadatfork.c
@@ -148,13 +153,6 @@ libposix_a_SOURCES += src/pthreadsetschedprio.c
## RTEMS specific support methods
libposix_a_SOURCES += src/pthreadattrcompare.c
-if HAS_SMP
-## PTHREAD_AFFINITY_C_FILES
-libposix_a_SOURCES += src/pthreadattrsetaffinitynp.c \
- src/pthreadattrgetaffinitynp.c src/pthreadgetaffinitynp.c \
- src/pthreadsetaffinitynp.c
-endif
-
## PSIGNAL_C_FILES
libposix_a_SOURCES += src/psignal.c src/alarm.c src/kill.c src/killinfo.c \
src/kill_r.c src/pause.c src/psignalclearprocesssignals.c \
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 90a60b6c4d..290fbad02e 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -59,12 +59,12 @@ RTEMS_INLINE_ROUTINE void _POSIX_Threads_Sporadic_timer_insert(
)
{
the_thread->cpu_time_budget =
- _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_init_budget );
+ _Timespec_To_ticks( &api->schedparam.sched_ss_init_budget );
_Watchdog_Per_CPU_insert_relative(
&api->Sporadic.Timer,
_Per_CPU_Get(),
- _Timespec_To_ticks( &api->Attributes.schedparam.sched_ss_repl_period )
+ _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period )
);
}
diff --git a/cpukit/posix/include/rtems/posix/threadsup.h b/cpukit/posix/include/rtems/posix/threadsup.h
index 3bb2210d97..cc250f7464 100644
--- a/cpukit/posix/include/rtems/posix/threadsup.h
+++ b/cpukit/posix/include/rtems/posix/threadsup.h
@@ -43,8 +43,14 @@ typedef struct {
/** Back pointer to thread of this POSIX API control. */
Thread_Control *thread;
- /** This is the POSIX threads attribute set. */
- pthread_attr_t Attributes;
+ /** Created with explicit or inherited scheduler. */
+ bool created_with_explicit_scheduler;
+
+ /** The scheduler policy. */
+ int schedpolicy;
+
+ /** The scheduler parameters */
+ struct sched_param schedparam;
/**
* @brief Control block for the sporadic server scheduling policy.
diff --git a/cpukit/posix/preinstall.am b/cpukit/posix/preinstall.am
index c3ce5e5aa9..157be567c2 100644
--- a/cpukit/posix/preinstall.am
+++ b/cpukit/posix/preinstall.am
@@ -140,5 +140,3 @@ $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h: include/rtems/posix/timerimpl.h $(PR
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/timerimpl.h
endif
-if HAS_PTHREADS
-endif
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index edbfa13121..1d791df7eb 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -75,9 +75,11 @@ pthread_attr_t _POSIX_Threads_Default_attributes = {
.cputime_clock_allowed = 1, /* cputime_clock_allowed */
#endif
.detachstate = PTHREAD_CREATE_JOINABLE, /* detachstate */
- .affinitysetsize = 0,
- .affinityset = NULL,
- .affinitysetpreallocated = {{0x0}}
+ .affinitysetsize =
+ sizeof( _POSIX_Threads_Default_attributes.affinitysetpreallocated ),
+ .affinityset =
+ &_POSIX_Threads_Default_attributes.affinitysetpreallocated,
+ .affinitysetpreallocated = {{0x1}}
};
void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
@@ -166,8 +168,7 @@ static bool _POSIX_Threads_Create_extension(
/* XXX check all fields are touched */
api->thread = created;
- _POSIX_Threads_Initialize_attributes( &api->Attributes );
- api->Attributes.schedparam.sched_priority = _POSIX_Priority_From_core(
+ api->schedparam.sched_priority = _POSIX_Priority_From_core(
_Thread_Scheduler_get_home( created ),
_Thread_Get_priority( created )
);
@@ -203,7 +204,7 @@ static void _POSIX_Threads_Terminate_extension( Thread_Control *executing )
_Thread_State_acquire( executing, &lock_context );
- if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
+ if ( api->schedpolicy == SCHED_SPORADIC ) {
_Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer );
}
diff --git a/cpukit/posix/src/pthreadattrcompare.c b/cpukit/posix/src/pthreadattrcompare.c
index 6a3b625be1..26ab28db33 100644
--- a/cpukit/posix/src/pthreadattrcompare.c
+++ b/cpukit/posix/src/pthreadattrcompare.c
@@ -32,7 +32,10 @@ int rtems_pthread_attribute_compare(
if ( attr1->is_initialized != attr2->is_initialized )
return 1;
- if ( attr1->stackaddr != attr2->stackaddr )
+ if (
+ attr1->stackaddr != NULL &&
+ attr2->stackaddr != NULL &&
+ attr1->stackaddr != attr2->stackaddr )
return 1;
if ( attr1->stacksize != attr2->stacksize )
diff --git a/cpukit/posix/src/pthreadattrgetaffinitynp.c b/cpukit/posix/src/pthreadattrgetaffinitynp.c
index 6ed50507be..b281b11e5f 100644
--- a/cpukit/posix/src/pthreadattrgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadattrgetaffinitynp.c
@@ -24,23 +24,19 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
-#include <rtems/score/threadimpl.h>
-
int pthread_attr_getaffinity_np(
const pthread_attr_t *attr,
size_t cpusetsize,
cpu_set_t *cpuset
)
{
- if ( !cpuset )
- return EFAULT;
- if ( !attr )
- return EFAULT;
+ if ( attr == NULL || !attr->is_initialized ) {
+ return EINVAL;
+ }
- if ( cpusetsize != attr->affinitysetsize)
+ if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
return EINVAL;
+ }
CPU_COPY( attr->affinityset, cpuset );
return 0;
diff --git a/cpukit/posix/src/pthreadattrsetaffinitynp.c b/cpukit/posix/src/pthreadattrsetaffinitynp.c
index e5462ec5c4..0e3c828c38 100644
--- a/cpukit/posix/src/pthreadattrsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadattrsetaffinitynp.c
@@ -24,27 +24,21 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
-#include <rtems/score/threadimpl.h>
-#include <rtems/score/cpusetimpl.h>
-
int pthread_attr_setaffinity_np(
pthread_attr_t *attr,
size_t cpusetsize,
const cpu_set_t *cpuset
)
{
- if ( !cpuset )
- return EFAULT;
- if ( !attr )
- return EFAULT;
+ if ( attr == NULL || !attr->is_initialized ) {
+ return EINVAL;
+ }
- if (! _CPU_set_Is_valid( cpuset, cpusetsize ) )
+ if ( cpuset == NULL || cpusetsize != attr->affinitysetsize ) {
return EINVAL;
+ }
CPU_COPY( cpuset, attr->affinityset );
-
return 0;
}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 5c5ea5f4de..ebb96bf8a4 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -242,7 +242,10 @@ int pthread_create(
*/
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- _POSIX_Threads_Copy_attributes( &api->Attributes, the_attr );
+ api->created_with_explicit_scheduler =
+ ( the_attr->inheritsched == PTHREAD_EXPLICIT_SCHED );
+ api->schedpolicy = the_attr->schedpolicy;
+ api->schedparam = the_attr->schedparam;
_Priority_Node_initialize( &api->Sporadic.Low_priority, core_low_prio );
_Priority_Node_set_inactive( &api->Sporadic.Low_priority );
diff --git a/cpukit/posix/src/pthreadgetaffinitynp.c b/cpukit/posix/src/pthreadgetaffinitynp.c
index b843f931d4..dab6b63aa0 100644
--- a/cpukit/posix/src/pthreadgetaffinitynp.c
+++ b/cpukit/posix/src/pthreadgetaffinitynp.c
@@ -25,8 +25,6 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/schedulerimpl.h>
diff --git a/cpukit/posix/src/pthreadgetattrnp.c b/cpukit/posix/src/pthreadgetattrnp.c
index 63de97be4b..d815fc8c53 100644
--- a/cpukit/posix/src/pthreadgetattrnp.c
+++ b/cpukit/posix/src/pthreadgetattrnp.c
@@ -21,8 +21,10 @@
#define _GNU_SOURCE
#include <pthread.h>
#include <errno.h>
+#include <string.h>
#include <rtems/posix/pthreadimpl.h>
+#include <rtems/score/schedulerimpl.h>
#include <rtems/score/threadimpl.h>
int pthread_getattr_np(
@@ -33,11 +35,14 @@ int pthread_getattr_np(
Thread_Control *the_thread;
ISR_lock_Context lock_context;
POSIX_API_Control *api;
+ bool ok;
if ( attr == NULL ) {
return EINVAL;
}
+ attr = memset( attr, 0, sizeof( *attr ) );
+
the_thread = _Thread_Get( thread, &lock_context );
if ( the_thread == NULL ) {
@@ -47,7 +52,21 @@ int pthread_getattr_np(
_Thread_State_acquire_critical( the_thread, &lock_context );
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- _POSIX_Threads_Copy_attributes( attr, &api->Attributes);
+
+ attr->is_initialized = true;
+ attr->stackaddr = the_thread->Start.Initial_stack.area;
+ attr->stacksize = the_thread->Start.Initial_stack.size;
+ attr->contentionscope = PTHREAD_SCOPE_PROCESS;
+
+ if ( api->created_with_explicit_scheduler ) {
+ attr->inheritsched = PTHREAD_EXPLICIT_SCHED;
+ } else {
+ attr->inheritsched = PTHREAD_INHERIT_SCHED;
+ }
+
+ attr->schedpolicy = api->schedpolicy;
+ attr->schedparam = api->schedparam;
+ attr->cputime_clock_allowed = 1;
if ( _Thread_Is_joinable( the_thread ) ) {
attr->detachstate = PTHREAD_CREATE_JOINABLE;
@@ -55,6 +74,14 @@ int pthread_getattr_np(
attr->detachstate = PTHREAD_CREATE_DETACHED;
}
+ attr->affinityset = &attr->affinitysetpreallocated;
+ attr->affinitysetsize = sizeof( attr->affinitysetpreallocated );
+ ok = _Scheduler_Get_affinity(
+ the_thread,
+ attr->affinitysetsize,
+ attr->affinityset
+ );
+
_Thread_State_release( the_thread, &lock_context );
- return 0;
+ return ok ? 0 : EINVAL;
}
diff --git a/cpukit/posix/src/pthreadgetschedparam.c b/cpukit/posix/src/pthreadgetschedparam.c
index b809db95dc..f172caecd4 100644
--- a/cpukit/posix/src/pthreadgetschedparam.c
+++ b/cpukit/posix/src/pthreadgetschedparam.c
@@ -56,8 +56,8 @@ int pthread_getschedparam(
_Thread_Wait_acquire_critical( the_thread, &queue_context );
- *policy = api->Attributes.schedpolicy;
- *param = api->Attributes.schedparam;
+ *policy = api->schedpolicy;
+ *param = api->schedparam;
scheduler = _Thread_Scheduler_get_home( the_thread );
priority = the_thread->Real_priority.priority;
diff --git a/cpukit/posix/src/pthreadsetaffinitynp.c b/cpukit/posix/src/pthreadsetaffinitynp.c
index 4ce51ec9ea..c504de5cd7 100644
--- a/cpukit/posix/src/pthreadsetaffinitynp.c
+++ b/cpukit/posix/src/pthreadsetaffinitynp.c
@@ -24,8 +24,6 @@
#include <pthread.h>
#include <errno.h>
-#include <rtems/posix/pthreadimpl.h>
-#include <rtems/posix/priorityimpl.h>
#include <rtems/score/threadimpl.h>
#include <rtems/score/cpusetimpl.h>
#include <rtems/score/schedulerimpl.h>
@@ -60,13 +58,6 @@ int pthread_setaffinity_np(
cpuset
);
- if ( ok ) {
- POSIX_API_Control *api;
-
- api = the_thread->API_Extensions[ THREAD_API_POSIX ];
- CPU_COPY( cpuset, api->Attributes.affinityset );
- }
-
_Thread_State_release( the_thread, &lock_context );
_Thread_Dispatch_enable( cpu_self );
return ok ? 0 : EINVAL;
diff --git a/cpukit/posix/src/pthreadsetschedparam.c b/cpukit/posix/src/pthreadsetschedparam.c
index 4da2ebf2a8..5d33f1d095 100644
--- a/cpukit/posix/src/pthreadsetschedparam.c
+++ b/cpukit/posix/src/pthreadsetschedparam.c
@@ -94,8 +94,8 @@ static int _POSIX_Set_sched_param(
);
}
- api->Attributes.schedpolicy = policy;
- api->Attributes.schedparam = *param;
+ api->schedpolicy = policy;
+ api->schedparam = *param;
the_thread->budget_algorithm = budget_algorithm;
the_thread->budget_callout = budget_callout;