diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-06-22 17:09:23 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-09-21 08:59:26 +0200 |
commit | 300f6a481aaf9e6d29811faca71bf7104a01492c (patch) | |
tree | ba8f18cedb93e3781a2f17aa989c5c805dd18d6a /cpukit/rtems | |
parent | classic networking: do not reference BSP_irq_enabled_at_i8259s which is no mo... (diff) | |
download | rtems-300f6a481aaf9e6d29811faca71bf7104a01492c.tar.bz2 |
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.
Diffstat (limited to 'cpukit/rtems')
-rw-r--r-- | cpukit/rtems/include/rtems/rtems/ratemon.h | 6 | ||||
-rw-r--r-- | cpukit/rtems/src/ratemoncancel.c | 12 | ||||
-rw-r--r-- | cpukit/rtems/src/ratemoncreate.c | 2 | ||||
-rw-r--r-- | cpukit/rtems/src/ratemonperiod.c | 15 | ||||
-rw-r--r-- | cpukit/rtems/src/semsetpriority.c | 18 | ||||
-rw-r--r-- | cpukit/rtems/src/tasksetpriority.c | 95 |
6 files changed, 78 insertions, 70 deletions
diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h index a2df13f025..50b847840f 100644 --- a/cpukit/rtems/include/rtems/rtems/ratemon.h +++ b/cpukit/rtems/include/rtems/rtems/ratemon.h @@ -206,6 +206,12 @@ typedef struct { rtems_rate_monotonic_period_states state; /** + * @brief A priority node for use by the scheduler job release and cancel + * operations. + */ + Priority_Node Priority; + + /** * This field contains the length of the next period to be * executed. */ diff --git a/cpukit/rtems/src/ratemoncancel.c b/cpukit/rtems/src/ratemoncancel.c index b4e899d296..cb95f54408 100644 --- a/cpukit/rtems/src/ratemoncancel.c +++ b/cpukit/rtems/src/ratemoncancel.c @@ -27,18 +27,22 @@ void _Rate_monotonic_Cancel( ISR_lock_Context *lock_context ) { - Per_CPU_Control *cpu_self; - Thread_Control *update_priority; + Per_CPU_Control *cpu_self; + Thread_queue_Context queue_context; _Rate_monotonic_Acquire_critical( the_period, lock_context ); _Watchdog_Per_CPU_remove_relative( &the_period->Timer ); the_period->state = RATE_MONOTONIC_INACTIVE; - update_priority = _Scheduler_Cancel_job( the_period->owner ); + _Scheduler_Cancel_job( + the_period->owner, + &the_period->Priority, + &queue_context + ); cpu_self = _Thread_Dispatch_disable_critical( lock_context ); _Rate_monotonic_Release( the_period, lock_context ); - _Thread_Update_priority( update_priority ); + _Thread_Priority_update( &queue_context ); _Thread_Dispatch_enable( cpu_self ); } diff --git a/cpukit/rtems/src/ratemoncreate.c b/cpukit/rtems/src/ratemoncreate.c index a86c6a1eeb..12327295ac 100644 --- a/cpukit/rtems/src/ratemoncreate.c +++ b/cpukit/rtems/src/ratemoncreate.c @@ -63,6 +63,8 @@ rtems_status_code rtems_rate_monotonic_create( } _ISR_lock_Initialize( &the_period->Lock, "Rate Monotonic Period" ); + _Priority_Node_initialize( &the_period->Priority, 0 ); + _Priority_Node_set_inactive( &the_period->Priority ); the_period->owner = _Thread_Get_executing(); the_period->state = RATE_MONOTONIC_INACTIVE; diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c index 75a80d8088..77bd996819 100644 --- a/cpukit/rtems/src/ratemonperiod.c +++ b/cpukit/rtems/src/ratemonperiod.c @@ -70,9 +70,9 @@ static void _Rate_monotonic_Release_job( ISR_lock_Context *lock_context ) { - Per_CPU_Control *cpu_self; - Thread_Control *update_priority; - uint64_t deadline; + Per_CPU_Control *cpu_self; + Thread_queue_Context queue_context; + uint64_t deadline; cpu_self = _Thread_Dispatch_disable_critical( lock_context ); @@ -81,10 +81,15 @@ static void _Rate_monotonic_Release_job( cpu_self, next_length ); - update_priority = _Scheduler_Release_job( owner, deadline ); + _Scheduler_Release_job( + owner, + &the_period->Priority, + deadline, + &queue_context + ); _Rate_monotonic_Release( the_period, lock_context ); - _Thread_Update_priority( update_priority ); + _Thread_Priority_update( &queue_context ); _Thread_Dispatch_enable( cpu_self ); } diff --git a/cpukit/rtems/src/semsetpriority.c b/cpukit/rtems/src/semsetpriority.c index f992d99522..37dea5da80 100644 --- a/cpukit/rtems/src/semsetpriority.c +++ b/cpukit/rtems/src/semsetpriority.c @@ -42,16 +42,18 @@ static rtems_status_code _Semaphore_Set_priority( Thread_queue_Context *queue_context ) { - rtems_status_code sc; - bool valid; - Priority_Control core_priority; - Priority_Control old_priority; + rtems_status_code sc; + bool valid; + Priority_Control core_priority; + Priority_Control old_priority; + Per_CPU_Control *cpu_self; core_priority = _RTEMS_Priority_To_core( scheduler, new_priority, &valid ); if ( new_priority != RTEMS_CURRENT_PRIORITY && !valid ) { return RTEMS_INVALID_PRIORITY; } + _Thread_queue_Context_clear_priority_updates( queue_context ); _Thread_queue_Acquire_critical( &the_semaphore->Core_control.Wait_queue, queue_context @@ -71,7 +73,8 @@ static rtems_status_code _Semaphore_Set_priority( if ( sc == RTEMS_SUCCESSFUL && new_priority != RTEMS_CURRENT_PRIORITY ) { _CORE_ceiling_mutex_Set_priority( &the_semaphore->Core_control.Mutex, - core_priority + core_priority, + queue_context ); } @@ -106,10 +109,15 @@ static rtems_status_code _Semaphore_Set_priority( break; } + cpu_self = _Thread_Dispatch_disable_critical( + &queue_context->Lock_context.Lock_context + ); _Thread_queue_Release( &the_semaphore->Core_control.Wait_queue, queue_context ); + _Thread_Priority_update( queue_context ); + _Thread_Dispatch_enable( cpu_self ); *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority ); return sc; diff --git a/cpukit/rtems/src/tasksetpriority.c b/cpukit/rtems/src/tasksetpriority.c index 9779c973a1..6b8ab4e976 100644 --- a/cpukit/rtems/src/tasksetpriority.c +++ b/cpukit/rtems/src/tasksetpriority.c @@ -22,50 +22,43 @@ #include <rtems/score/schedulerimpl.h> #include <rtems/score/threadimpl.h> -typedef struct { - const Scheduler_Control *scheduler; - rtems_task_priority new_priority; - Priority_Control old_priority; - rtems_status_code status; -} RTEMS_tasks_Set_priority_context; - -static bool _RTEMS_tasks_Set_priority_filter( - Thread_Control *the_thread, - Priority_Control *new_priority_p, - void *arg +static rtems_status_code _RTEMS_tasks_Set_priority( + Thread_Control *the_thread, + const Scheduler_Control *scheduler, + Priority_Control new_priority, + Thread_queue_Context *queue_context ) { - RTEMS_tasks_Set_priority_context *context; - const Scheduler_Control *scheduler; - bool valid; - Priority_Control current_priority; - Priority_Control new_priority; + Priority_Control core_new_priority; + bool valid; + Per_CPU_Control *cpu_self; - context = arg; - scheduler = _Scheduler_Get_own( the_thread ); - current_priority = _Thread_Get_priority( the_thread ); - - context->scheduler = scheduler; - context->old_priority = current_priority; - - new_priority = _RTEMS_Priority_To_core( + core_new_priority = _RTEMS_Priority_To_core( scheduler, - context->new_priority, + new_priority, &valid ); - *new_priority_p = new_priority; - if ( !valid ) { - context->status = RTEMS_INVALID_PRIORITY; - return false; + _Thread_Wait_release( the_thread, queue_context ); + return RTEMS_INVALID_PRIORITY; } - the_thread->real_priority = new_priority; - context->status = STATUS_SUCCESSFUL; - - return _Thread_Priority_less_than( current_priority, new_priority ) - || !_Thread_Owns_resources( the_thread ); + _Thread_queue_Context_clear_priority_updates( queue_context ); + _Thread_Priority_change( + the_thread, + &the_thread->Real_priority, + core_new_priority, + false, + queue_context + ); + cpu_self = _Thread_Dispatch_disable_critical( + &queue_context->Lock_context.Lock_context + ); + _Thread_Wait_release( the_thread, queue_context ); + _Thread_Priority_update( queue_context ); + _Thread_Dispatch_enable( cpu_self ); + return RTEMS_SUCCESSFUL; } rtems_status_code rtems_task_set_priority( @@ -75,7 +68,7 @@ rtems_status_code rtems_task_set_priority( ) { Thread_Control *the_thread; - ISR_lock_Context lock_context; + Thread_queue_Context queue_context; const Scheduler_Control *scheduler; Priority_Control old_priority; rtems_status_code status; @@ -84,7 +77,8 @@ rtems_status_code rtems_task_set_priority( return RTEMS_INVALID_ADDRESS; } - the_thread = _Thread_Get( id, &lock_context ); + _Thread_queue_Context_initialize( &queue_context ); + the_thread = _Thread_Get( id, &queue_context.Lock_context.Lock_context ); if ( the_thread == NULL ) { #if defined(RTEMS_MULTIPROCESSING) @@ -94,31 +88,20 @@ rtems_status_code rtems_task_set_priority( #endif } - if ( new_priority != RTEMS_CURRENT_PRIORITY ) { - RTEMS_tasks_Set_priority_context context; - Per_CPU_Control *cpu_self; + _Thread_Wait_acquire_critical( the_thread, &queue_context ); - cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); - _ISR_lock_ISR_enable( &lock_context ); + scheduler = _Scheduler_Get_own( the_thread ); + old_priority = _Thread_Get_priority( the_thread ); - context.new_priority = new_priority; - _Thread_Change_priority( + if ( new_priority != RTEMS_CURRENT_PRIORITY ) { + status = _RTEMS_tasks_Set_priority( the_thread, - 0, - &context, - _RTEMS_tasks_Set_priority_filter, - false + scheduler, + new_priority, + &queue_context ); - - _Thread_Dispatch_enable( cpu_self ); - scheduler = context.scheduler; - old_priority = context.old_priority; - status = context.status; } else { - _Thread_State_acquire_critical( the_thread, &lock_context ); - scheduler = _Scheduler_Get_own( the_thread ); - old_priority = _Thread_Get_priority( the_thread ); - _Thread_State_release( the_thread, &lock_context ); + _Thread_Wait_release( the_thread, &queue_context ); status = RTEMS_SUCCESSFUL; } |