summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/pthread.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-15 06:59:57 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-06-22 14:00:28 +0200
commiteec08efc9048111f47f42142c30a92683bf6756c (patch)
treecad083e49ab757b47487f8489ed48c9204b65c38 /cpukit/posix/src/pthread.c
parentposix: Delete POSIX_API_Control::schedparam (diff)
downloadrtems-eec08efc9048111f47f42142c30a92683bf6756c.tar.bz2
posix: Rework sporadic server scheduling policy
Instead of lowering the priority in case the initial budget is consumed raise the priority for each new period. Restore the normal priority once the initial budget is consumed. This makes it later easier to combine the high priority phase with temporary priority boosts (e.g. via priority ceiling and inheritance). Use the thread lock to protect the POSIX thread attributes instead of the thread state lock. This makes it easier to change the thread priority and keep the POSIX attributes consistent. Fixes a false positive use of uninitialized variable warning.
Diffstat (limited to 'cpukit/posix/src/pthread.c')
-rw-r--r--cpukit/posix/src/pthread.c105
1 files changed, 43 insertions, 62 deletions
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c
index ead24cf4f7..ca7efa9c7d 100644
--- a/cpukit/posix/src/pthread.c
+++ b/cpukit/posix/src/pthread.c
@@ -81,83 +81,57 @@ pthread_attr_t _POSIX_Threads_Default_attributes = {
#endif
};
-static bool _POSIX_Threads_Sporadic_budget_TSR_filter(
+static bool _POSIX_Threads_Sporadic_timer_filter(
Thread_Control *the_thread,
- Priority_Control *new_priority,
+ Priority_Control *new_priority_p,
void *arg
)
{
- the_thread->real_priority = *new_priority;
+ POSIX_API_Control *api;
+ Priority_Control current_priority;
+ Priority_Control new_priority;
- /*
- * If holding a resource, then do not change it.
- *
- * If this would make them less important, then do not change it.
- */
- return !_Thread_Owns_resources( the_thread ) &&
- _Thread_Priority_less_than( the_thread->current_priority, *new_priority );
-}
+ api = arg;
-/*
- * _POSIX_Threads_Sporadic_budget_TSR
- */
-void _POSIX_Threads_Sporadic_budget_TSR( Watchdog_Control *watchdog )
-{
- POSIX_API_Control *api;
- Thread_Control *the_thread;
- ISR_lock_Context lock_context;
- Priority_Control new_priority;
+ new_priority = api->Sporadic.high_priority;
+ *new_priority_p = new_priority;
- api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic_timer );
- the_thread = api->thread;
+ current_priority = the_thread->current_priority;
+ the_thread->real_priority = new_priority;
- _Thread_State_acquire( the_thread, &lock_context );
-
- _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
+ _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer );
_POSIX_Threads_Sporadic_timer_insert( the_thread, api );
- new_priority = _POSIX_Priority_To_core(
- api->Attributes.schedparam.sched_priority
- );
+ return _Thread_Priority_less_than( current_priority, new_priority )
+ || !_Thread_Owns_resources( the_thread );
+}
+
+static void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog )
+{
+ POSIX_API_Control *api;
+ Thread_Control *the_thread;
- _Thread_State_release( the_thread, &lock_context );
+ api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer );
+ the_thread = api->thread;
_Thread_Change_priority(
the_thread,
- new_priority,
- NULL,
- _POSIX_Threads_Sporadic_budget_TSR_filter,
+ 0,
+ api,
+ _POSIX_Threads_Sporadic_timer_filter,
true
);
}
static bool _POSIX_Threads_Sporadic_budget_callout_filter(
Thread_Control *the_thread,
- Priority_Control *new_priority,
+ Priority_Control *new_priority_p,
void *arg
)
{
- the_thread->real_priority = *new_priority;
-
- /*
- * If holding a resource, then do not change it.
- *
- * Make sure we are actually lowering it. If they have lowered it
- * to logically lower than sched_ss_low_priority, then we do not want to
- * change it.
- */
- return !_Thread_Owns_resources( the_thread ) &&
- _Thread_Priority_less_than( *new_priority, the_thread->current_priority );
-}
-
-/*
- * _POSIX_Threads_Sporadic_budget_callout
- */
-void _POSIX_Threads_Sporadic_budget_callout(
- Thread_Control *the_thread
-)
-{
POSIX_API_Control *api;
+ Priority_Control current_priority;
+ Priority_Control new_priority;
api = the_thread->API_Extensions[ THREAD_API_POSIX ];
@@ -167,11 +141,21 @@ void _POSIX_Threads_Sporadic_budget_callout(
*/
the_thread->cpu_time_budget = UINT32_MAX;
+ new_priority = api->Sporadic.low_priority;
+ *new_priority_p = new_priority;
+
+ current_priority = the_thread->current_priority;
+ the_thread->real_priority = new_priority;
+
+ return _Thread_Priority_less_than( current_priority, new_priority )
+ || !_Thread_Owns_resources( the_thread );
+}
+
+void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread )
+{
_Thread_Change_priority(
the_thread,
- _POSIX_Priority_To_core(
- api->Attributes.schedparam.sched_ss_low_priority
- ),
+ 0,
NULL,
_POSIX_Threads_Sporadic_budget_callout_filter,
true
@@ -217,11 +201,8 @@ static bool _POSIX_Threads_Create_extension(
api->signals_unblocked = executing_api->signals_unblocked;
}
- _Watchdog_Preinitialize( &api->Sporadic_timer, _Per_CPU_Get_by_index( 0 ) );
- _Watchdog_Initialize(
- &api->Sporadic_timer,
- _POSIX_Threads_Sporadic_budget_TSR
- );
+ _Watchdog_Preinitialize( &api->Sporadic.Timer, _Per_CPU_Get_by_index( 0 ) );
+ _Watchdog_Initialize( &api->Sporadic.Timer, _POSIX_Threads_Sporadic_timer );
return true;
}
@@ -236,7 +217,7 @@ static void _POSIX_Threads_Terminate_extension( Thread_Control *executing )
_Thread_State_acquire( executing, &lock_context );
if ( api->Attributes.schedpolicy == SCHED_SPORADIC ) {
- _Watchdog_Per_CPU_remove_relative( &api->Sporadic_timer );
+ _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer );
}
_Thread_State_release( executing, &lock_context );