From 78b867e26dac3266763f275c1f438da912f33a6e Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Thu, 21 Dec 2017 11:49:30 -0500 Subject: score: replace current and real priority with priority node Encapsulate the current_priority and real_priority fields of the thread control block with a Thread_Priority_node struct. Propagate modifications throughout the tree where the two fields are directly accessed. Updates #3359. --- cpukit/score/include/rtems/score/thread.h | 25 +++++++++++++++++-------- cpukit/score/inline/rtems/score/coremutex.inl | 4 ++-- cpukit/score/src/coremutex.c | 4 ++-- cpukit/score/src/coremutexseize.c | 4 ++-- cpukit/score/src/coremutexsurrender.c | 12 ++++++------ cpukit/score/src/mpci.c | 2 +- cpukit/score/src/threadchangepriority.c | 4 ++-- cpukit/score/src/threadclearstate.c | 4 ++-- cpukit/score/src/threadinitialize.c | 2 +- cpukit/score/src/threadmp.c | 2 +- cpukit/score/src/threadqenqueuepriority.c | 10 +++++----- cpukit/score/src/threadreset.c | 4 ++-- cpukit/score/src/threadresume.c | 4 ++-- cpukit/score/src/threadsetpriority.c | 2 +- 14 files changed, 46 insertions(+), 37 deletions(-) (limited to 'cpukit/score') diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h index 214f8ce1f5..b0b40f713c 100644 --- a/cpukit/score/include/rtems/score/thread.h +++ b/cpukit/score/include/rtems/score/thread.h @@ -276,6 +276,17 @@ typedef struct { Thread_queue_Control *queue; } Thread_Wait_information; +/** + * @brief Encapsulates base and inherited priority. + */ +typedef struct Thread_Priority_node { + Chain_Node Node; + /** current priority = min(real_priority, min(Inherited_priorities)) */ + Priority_Control current_priority; + /** base priority irrespective of inheritance/ceiling */ + Priority_Control real_priority; +} Thread_Priority_node; + /** * The following defines the control block used to manage * each thread proxy. @@ -288,10 +299,9 @@ typedef struct { Objects_Control Object; /** This field is the current execution state of this proxy. */ States_Control current_state; - /** This field is the current priority state of this proxy. */ - Priority_Control current_priority; - /** This field is the base priority of this proxy. */ - Priority_Control real_priority; + /** This field encapsulates the base and current (inherited) priority + * of this proxy. */ + Thread_Priority_node Priority_node; /** This field is the number of mutexes currently held by this proxy. */ uint32_t resource_count; @@ -338,10 +348,9 @@ struct Thread_Control_struct { Objects_Control Object; /** This field is the current execution state of this thread. */ States_Control current_state; - /** This field is the current priority state of this thread. */ - Priority_Control current_priority; - /** This field is the base priority of this thread. */ - Priority_Control real_priority; + /** This field encapsulates the base and current (inherited) priority + * of this thread. */ + Thread_Priority_node Priority_node; /** This field is the number of mutexes currently held by this thread. */ uint32_t resource_count; /** This field is the blocking information for this thread. */ diff --git a/cpukit/score/inline/rtems/score/coremutex.inl b/cpukit/score/inline/rtems/score/coremutex.inl index 9f6d749b81..eb22e1d662 100644 --- a/cpukit/score/inline/rtems/score/coremutex.inl +++ b/cpukit/score/inline/rtems/score/coremutex.inl @@ -146,7 +146,7 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body( #ifdef __RTEMS_STRICT_ORDER_MUTEX__ _Chain_Prepend_unprotected( &executing->lock_mutex, &the_mutex->queue.lock_queue ); - the_mutex->queue.priority_before = executing->current_priority; + the_mutex->queue.priority_before = executing->Priority_node.current_priority; #endif executing->resource_count++; @@ -165,7 +165,7 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body( Priority_Control current; ceiling = the_mutex->Attributes.priority_ceiling; - current = executing->current_priority; + current = executing->Priority_node.current_priority; if ( current == ceiling ) { _ISR_Enable( *level_p ); return 0; diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c index 261e18e80f..6540afd8af 100644 --- a/cpukit/score/src/coremutex.c +++ b/cpukit/score/src/coremutex.c @@ -71,12 +71,12 @@ CORE_mutex_Status _CORE_mutex_Initialize( Priority_Control ceiling = the_mutex->Attributes.priority_ceiling; if ( is_priority_ceiling && - _Thread_Executing->current_priority < ceiling ) + _Thread_Executing->Priority_node.current_priority < ceiling ) return CORE_MUTEX_STATUS_CEILING_VIOLATED; #ifdef __RTEMS_STRICT_ORDER_MUTEX__ _Chain_Prepend_unprotected( &_Thread_Executing->lock_mutex, &the_mutex->queue.lock_queue ); - the_mutex->queue.priority_before = _Thread_Executing->current_priority; + the_mutex->queue.priority_before = _Thread_Executing->Priority_node.current_priority; #endif _Thread_Executing->resource_count++; diff --git a/cpukit/score/src/coremutexseize.c b/cpukit/score/src/coremutexseize.c index db6d513cb4..c19d868cf0 100644 --- a/cpukit/score/src/coremutexseize.c +++ b/cpukit/score/src/coremutexseize.c @@ -61,10 +61,10 @@ void _CORE_mutex_Seize_interrupt_blocking( executing = _Thread_Executing; if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) { - if ( the_mutex->holder->current_priority > executing->current_priority ) { + if ( the_mutex->holder->Priority_node.current_priority > executing->Priority_node.current_priority ) { _Thread_Change_priority( the_mutex->holder, - executing->current_priority, + executing->Priority_node.current_priority, false ); } diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c index 4d215bb2d1..2ed2afebb7 100644 --- a/cpukit/score/src/coremutexsurrender.c +++ b/cpukit/score/src/coremutexsurrender.c @@ -135,12 +135,12 @@ CORE_mutex_Status _CORE_mutex_Surrender( if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) || _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) { #ifdef __RTEMS_STRICT_ORDER_MUTEX__ - if(the_mutex->queue.priority_before != holder->current_priority) + if(the_mutex->queue.priority_before != holder->Priority_node.current_priority) _Thread_Change_priority(holder,the_mutex->queue.priority_before,true); #endif if ( holder->resource_count == 0 && - holder->real_priority != holder->current_priority ) { - _Thread_Change_priority( holder, holder->real_priority, true ); + holder->Priority_node.real_priority != holder->Priority_node.current_priority ) { + _Thread_Change_priority( holder, holder->Priority_node.real_priority, true ); } } @@ -174,18 +174,18 @@ CORE_mutex_Status _CORE_mutex_Surrender( case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: #ifdef __RTEMS_STRICT_ORDER_MUTEX__ _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue); - the_mutex->queue.priority_before = the_thread->current_priority; + the_mutex->queue.priority_before = the_thread->Priority_node.current_priority; #endif the_thread->resource_count++; break; case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: #ifdef __RTEMS_STRICT_ORDER_MUTEX__ _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue); - the_mutex->queue.priority_before = the_thread->current_priority; + the_mutex->queue.priority_before = the_thread->Priority_node.current_priority; #endif the_thread->resource_count++; if (the_mutex->Attributes.priority_ceiling < - the_thread->current_priority){ + the_thread->Priority_node.current_priority){ _Thread_Change_priority( the_thread, the_mutex->Attributes.priority_ceiling, diff --git a/cpukit/score/src/mpci.c b/cpukit/score/src/mpci.c index d8f68ebc89..140263de67 100644 --- a/cpukit/score/src/mpci.c +++ b/cpukit/score/src/mpci.c @@ -254,7 +254,7 @@ uint32_t _MPCI_Send_request_packet ( ) { the_packet->source_tid = _Thread_Executing->Object.id; - the_packet->source_priority = _Thread_Executing->current_priority; + the_packet->source_priority = _Thread_Executing->Priority_node.current_priority; the_packet->to_convert = ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t); diff --git a/cpukit/score/src/threadchangepriority.c b/cpukit/score/src/threadchangepriority.c index b3b3eeb615..d109dd9ec6 100644 --- a/cpukit/score/src/threadchangepriority.c +++ b/cpukit/score/src/threadchangepriority.c @@ -68,7 +68,7 @@ void _Thread_Change_priority( /* if ( prepend_it && _Thread_Is_executing( the_thread ) && - new_priority >= the_thread->current_priority ) + new_priority >= the_thread->Priority_node.current_priority ) prepend_it = true; */ @@ -88,7 +88,7 @@ void _Thread_Change_priority( * Do not bother recomputing all the priority related information if * we are not REALLY changing priority. */ - if ( the_thread->current_priority != new_priority ) + if ( the_thread->Priority_node.current_priority != new_priority ) _Thread_Set_priority( the_thread, new_priority ); _ISR_Disable( level ); diff --git a/cpukit/score/src/threadclearstate.c b/cpukit/score/src/threadclearstate.c index 617f271668..f10582452b 100644 --- a/cpukit/score/src/threadclearstate.c +++ b/cpukit/score/src/threadclearstate.c @@ -84,10 +84,10 @@ void _Thread_Clear_state( * Even if the thread isn't preemptible, if the new heir is * a pseudo-ISR system task, we need to do a context switch. */ - if ( the_thread->current_priority < _Thread_Heir->current_priority ) { + if ( the_thread->Priority_node.current_priority < _Thread_Heir->Priority_node.current_priority ) { _Thread_Heir = the_thread; if ( _Thread_Executing->is_preemptible || - the_thread->current_priority == 0 ) + the_thread->Priority_node.current_priority == 0 ) _Context_Switch_necessary = true; } } diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c index 91522fbe27..a02c72958b 100644 --- a/cpukit/score/src/threadinitialize.c +++ b/cpukit/score/src/threadinitialize.c @@ -192,7 +192,7 @@ bool _Thread_Initialize( #if defined(RTEMS_ITRON_API) the_thread->suspend_count = 0; #endif - the_thread->real_priority = priority; + the_thread->Priority_node.real_priority = priority; the_thread->Start.initial_priority = priority; _Thread_Set_priority( the_thread, priority ); diff --git a/cpukit/score/src/threadmp.c b/cpukit/score/src/threadmp.c index 2b4137f103..0427b1ef0a 100644 --- a/cpukit/score/src/threadmp.c +++ b/cpukit/score/src/threadmp.c @@ -78,7 +78,7 @@ Thread_Control *_Thread_MP_Allocate_proxy ( the_proxy->Object.id = _MPCI_Receive_server_tcb->receive_packet->source_tid; - the_proxy->current_priority = + the_proxy->Priority_node.current_priority = _MPCI_Receive_server_tcb->receive_packet->source_priority; the_proxy->current_state = _States_Set( STATES_DORMANT, the_state ); diff --git a/cpukit/score/src/threadqenqueuepriority.c b/cpukit/score/src/threadqenqueuepriority.c index f2652ea4b0..caf65ff222 100644 --- a/cpukit/score/src/threadqenqueuepriority.c +++ b/cpukit/score/src/threadqenqueuepriority.c @@ -69,7 +69,7 @@ Thread_blocking_operation_States _Thread_queue_Enqueue_priority ( _Chain_Initialize_empty( &the_thread->Wait.Block2n ); - priority = the_thread->current_priority; + priority = the_thread->Priority_node.current_priority; header_index = _Thread_queue_Header_number( priority ); header = &the_thread_queue->Queues.Priority[ header_index ]; block_state = the_thread_queue->state; @@ -82,7 +82,7 @@ restart_forward_search: _ISR_Disable( level ); search_thread = (Thread_Control *) header->first; while ( !_Chain_Is_tail( header, (Chain_Node *)search_thread ) ) { - search_priority = search_thread->current_priority; + search_priority = search_thread->Priority_node.current_priority; if ( priority <= search_priority ) break; @@ -90,7 +90,7 @@ restart_forward_search: search_thread = (Thread_Control *) search_thread->Object.Node.next; if ( _Chain_Is_tail( header, (Chain_Node *)search_thread ) ) break; - search_priority = search_thread->current_priority; + search_priority = search_thread->Priority_node.current_priority; if ( priority <= search_priority ) break; #endif @@ -130,14 +130,14 @@ restart_reverse_search: _ISR_Disable( level ); search_thread = (Thread_Control *) header->last; while ( !_Chain_Is_head( header, (Chain_Node *)search_thread ) ) { - search_priority = search_thread->current_priority; + search_priority = search_thread->Priority_node.current_priority; if ( priority >= search_priority ) break; #if ( CPU_UNROLL_ENQUEUE_PRIORITY == TRUE ) search_thread = (Thread_Control *) search_thread->Object.Node.previous; if ( _Chain_Is_head( header, (Chain_Node *)search_thread ) ) break; - search_priority = search_thread->current_priority; + search_priority = search_thread->Priority_node.current_priority; if ( priority >= search_priority ) break; #endif diff --git a/cpukit/score/src/threadreset.c b/cpukit/score/src/threadreset.c index a99aa45e17..fd55ca320f 100644 --- a/cpukit/score/src/threadreset.c +++ b/cpukit/score/src/threadreset.c @@ -63,8 +63,8 @@ void _Thread_Reset( (void) _Watchdog_Remove( &the_thread->Timer ); } - if ( the_thread->current_priority != the_thread->Start.initial_priority ) { - the_thread->real_priority = the_thread->Start.initial_priority; + if ( the_thread->Priority_node.current_priority != the_thread->Start.initial_priority ) { + the_thread->Priority_node.real_priority = the_thread->Start.initial_priority; _Thread_Set_priority( the_thread, the_thread->Start.initial_priority ); } } diff --git a/cpukit/score/src/threadresume.c b/cpukit/score/src/threadresume.c index cea8849537..4466b9621f 100644 --- a/cpukit/score/src/threadresume.c +++ b/cpukit/score/src/threadresume.c @@ -87,10 +87,10 @@ void _Thread_Resume( _ISR_Flash( level ); - if ( the_thread->current_priority < _Thread_Heir->current_priority ) { + if ( the_thread->Priority_node.current_priority < _Thread_Heir->Priority_node.current_priority ) { _Thread_Heir = the_thread; if ( _Thread_Executing->is_preemptible || - the_thread->current_priority == 0 ) + the_thread->Priority_node.current_priority == 0 ) _Context_Switch_necessary = true; } } diff --git a/cpukit/score/src/threadsetpriority.c b/cpukit/score/src/threadsetpriority.c index a4837ca493..2460910a82 100644 --- a/cpukit/score/src/threadsetpriority.c +++ b/cpukit/score/src/threadsetpriority.c @@ -48,7 +48,7 @@ void _Thread_Set_priority( Priority_Control new_priority ) { - the_thread->current_priority = new_priority; + the_thread->Priority_node.current_priority = new_priority; the_thread->ready = &_Thread_Ready_chain[ new_priority ]; _Priority_Initialize_information( &the_thread->Priority_map, new_priority ); -- cgit v1.2.3