From 300f6a481aaf9e6d29811faca71bf7104a01492c Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 22 Jun 2016 17:09:23 +0200 Subject: score: Rework thread priority management Add priority nodes which contribute to the overall thread priority. The actual priority of a thread is now an aggregation of priority nodes. The thread priority aggregation for the home scheduler instance of a thread consists of at least one priority node, which is normally the real priority of the thread. The locking protocols (e.g. priority ceiling and priority inheritance), rate-monotonic period objects and the POSIX sporadic server add, change and remove priority nodes. A thread changes its priority now immediately, e.g. priority changes are not deferred until the thread releases its last resource. Replace the _Thread_Change_priority() function with * _Thread_Priority_perform_actions(), * _Thread_Priority_add(), * _Thread_Priority_remove(), * _Thread_Priority_change(), and * _Thread_Priority_update(). Update #2412. Update #2556. --- cpukit/posix/src/pthread.c | 103 +++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 59 deletions(-) (limited to 'cpukit/posix/src/pthread.c') diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c index a1394a5dee..9cd730b59f 100644 --- a/cpukit/posix/src/pthread.c +++ b/cpukit/posix/src/pthread.c @@ -82,85 +82,70 @@ pthread_attr_t _POSIX_Threads_Default_attributes = { #endif }; -static bool _POSIX_Threads_Sporadic_timer_filter( - Thread_Control *the_thread, - Priority_Control *new_priority_p, - void *arg -) +void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ) { - POSIX_API_Control *api; - Priority_Control current_priority; - Priority_Control new_priority; + POSIX_API_Control *api; + Thread_Control *the_thread; + Thread_queue_Context queue_context; - api = arg; - - 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 = _Thread_Get_priority( the_thread ); - the_thread->real_priority = new_priority; + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire( the_thread, &queue_context ); + + if ( _Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { + _Thread_Priority_add( + the_thread, + &the_thread->Real_priority, + &queue_context + ); + _Thread_Priority_remove( + the_thread, + &api->Sporadic.Low_priority, + &queue_context + ); + _Priority_Node_set_inactive( &api->Sporadic.Low_priority ); + } _Watchdog_Per_CPU_remove_relative( &api->Sporadic.Timer ); _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); - 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; - - api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer ); - the_thread = api->thread; - - _Thread_Change_priority( - the_thread, - 0, - api, - _POSIX_Threads_Sporadic_timer_filter, - true - ); + _Thread_Wait_release( the_thread, &queue_context ); + _Thread_Priority_update( &queue_context ); } -static bool _POSIX_Threads_Sporadic_budget_callout_filter( - Thread_Control *the_thread, - Priority_Control *new_priority_p, - void *arg -) +void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread ) { - POSIX_API_Control *api; - Priority_Control current_priority; - Priority_Control new_priority; + POSIX_API_Control *api; + Thread_queue_Context queue_context; api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire( the_thread, &queue_context ); + /* * This will prevent the thread from consuming its entire "budget" * while at low priority. */ the_thread->cpu_time_budget = UINT32_MAX; - new_priority = api->Sporadic.low_priority; - *new_priority_p = new_priority; - - current_priority = _Thread_Get_priority( the_thread ); - the_thread->real_priority = new_priority; - - return _Thread_Priority_less_than( current_priority, new_priority ) - || !_Thread_Owns_resources( the_thread ); -} + if ( !_Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { + _Thread_Priority_add( + the_thread, + &api->Sporadic.Low_priority, + &queue_context + ); + _Thread_Priority_remove( + the_thread, + &the_thread->Real_priority, + &queue_context + ); + } -void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread ) -{ - _Thread_Change_priority( - the_thread, - 0, - NULL, - _POSIX_Threads_Sporadic_budget_callout_filter, - true - ); + _Thread_Wait_release( the_thread, &queue_context ); + _Thread_Priority_update( &queue_context ); } /* -- cgit v1.2.3