diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-05-05 13:05:54 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-05-19 12:00:47 +0200 |
commit | 900d337f960cb7cc53f5c93c29a503e5ced2c31f (patch) | |
tree | 1d1f49724e5cfcef1974d5dc4251486b0fddd2ef /cpukit/posix/src/pthread.c | |
parent | score: Fine grained locking for mutexes (diff) | |
download | rtems-900d337f960cb7cc53f5c93c29a503e5ced2c31f.tar.bz2 |
score: Rework _Thread_Change_priority()
Move the writes to Thread_Control::current_priority and
Thread_Control::real_priority into _Thread_Change_priority() under the
protection of the thread lock. Add a filter function to
_Thread_Change_priority() to enable specialized variants.
Avoid race conditions during a thread priority restore with the new
Thread_Control::priority_restore_hint for an important average case
optimizations used by priority inheritance mutexes.
Update #2273.
Diffstat (limited to 'cpukit/posix/src/pthread.c')
-rw-r--r-- | cpukit/posix/src/pthread.c | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c index a3a73f117a..6395ec0ebd 100644 --- a/cpukit/posix/src/pthread.c +++ b/cpukit/posix/src/pthread.c @@ -83,6 +83,23 @@ pthread_attr_t _POSIX_Threads_Default_attributes = { #endif }; +static bool _POSIX_Threads_Sporadic_budget_TSR_filter( + Thread_Control *the_thread, + Priority_Control *new_priority, + void *arg +) +{ + the_thread->real_priority = *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 ); +} + /* * _POSIX_Threads_Sporadic_budget_TSR */ @@ -92,7 +109,6 @@ void _POSIX_Threads_Sporadic_budget_TSR( ) { uint32_t ticks; - uint32_t new_priority; Thread_Control *the_thread; POSIX_API_Control *api; @@ -105,27 +121,13 @@ void _POSIX_Threads_Sporadic_budget_TSR( the_thread->cpu_time_budget = ticks; - new_priority = _POSIX_Priority_To_core( api->schedparam.sched_priority ); - the_thread->real_priority = new_priority; - - /* - * If holding a resource, then do not change it. - */ - #if 0 - printk( "TSR %d %d %d\n", the_thread->resource_count, - the_thread->current_priority, new_priority ); - #endif - if ( !_Thread_Owns_resources( the_thread ) ) { - /* - * If this would make them less important, then do not change it. - */ - if ( the_thread->current_priority > new_priority ) { - _Thread_Change_priority( the_thread, new_priority, true ); - #if 0 - printk( "raise priority\n" ); - #endif - } - } + _Thread_Change_priority( + the_thread, + _POSIX_Priority_To_core( api->schedparam.sched_priority ), + NULL, + _POSIX_Threads_Sporadic_budget_TSR_filter, + true + ); /* ticks is guaranteed to be at least one */ ticks = _Timespec_To_ticks( &api->schedparam.sched_ss_repl_period ); @@ -133,6 +135,25 @@ void _POSIX_Threads_Sporadic_budget_TSR( _Watchdog_Insert_ticks( &api->Sporadic_timer, ticks ); } +static bool _POSIX_Threads_Sporadic_budget_callout_filter( + Thread_Control *the_thread, + Priority_Control *new_priority, + 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 */ @@ -141,7 +162,6 @@ void _POSIX_Threads_Sporadic_budget_callout( ) { POSIX_API_Control *api; - uint32_t new_priority; api = the_thread->API_Extensions[ THREAD_API_POSIX ]; @@ -151,29 +171,13 @@ void _POSIX_Threads_Sporadic_budget_callout( */ the_thread->cpu_time_budget = UINT32_MAX; - new_priority = _POSIX_Priority_To_core(api->schedparam.sched_ss_low_priority); - the_thread->real_priority = new_priority; - - /* - * If holding a resource, then do not change it. - */ - #if 0 - printk( "callout %d %d %d\n", the_thread->resource_count, - the_thread->current_priority, new_priority ); - #endif - if ( !_Thread_Owns_resources( the_thread ) ) { - /* - * 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. - */ - if ( the_thread->current_priority < new_priority ) { - _Thread_Change_priority( the_thread, new_priority, true ); - #if 0 - printk( "lower priority\n" ); - #endif - } - } + _Thread_Change_priority( + the_thread, + _POSIX_Priority_To_core( api->schedparam.sched_ss_low_priority ), + NULL, + _POSIX_Threads_Sporadic_budget_callout_filter, + true + ); } /* |