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.
This commit is contained in:
Gedare Bloom
2017-12-21 11:49:30 -05:00
parent 776caaed01
commit 78b867e26d
27 changed files with 87 additions and 77 deletions

View File

@@ -52,7 +52,7 @@ ER chg_pri(
_ITRON_return_errorno( E_PAR );
new_priority = _ITRON_Task_Priority_to_Core( tskpri );
the_thread->real_priority = new_priority;
the_thread->Priority_node.real_priority = new_priority;
/*
* The priority should not be changed until later if priority
@@ -60,7 +60,7 @@ ER chg_pri(
*/
if ( the_thread->resource_count == 0 ||
the_thread->current_priority > new_priority )
the_thread->Priority_node.current_priority > new_priority )
_Thread_Change_priority( the_thread, new_priority, false );
break;

View File

@@ -74,7 +74,7 @@ ER ref_tsk(
pk_rtsk->exinf = NULL; /* extended information */
pk_rtsk->tskpri =
_ITRON_Task_Core_to_Priority(the_thread->current_priority);
_ITRON_Task_Core_to_Priority(the_thread->Priority_node.current_priority);
/*
* Mask in the tskstat information

View File

@@ -43,7 +43,7 @@ ER rot_rdq(
* Yield of processor will rotate the queue for this processor.
*/
priority = _ITRON_Task_Core_to_Priority(_Thread_Executing->current_priority);
priority = _ITRON_Task_Core_to_Priority(_Thread_Executing->Priority_node.current_priority);
if ( priority == tskpri )
_Thread_Yield_processor();
else {

View File

@@ -531,8 +531,8 @@ rtems_capture_record (rtems_capture_task_t* task,
*/
if ((events & RTEMS_CAPTURE_RECORD_EVENTS) ||
((task->tcb->real_priority >= capture_ceiling) &&
(task->tcb->real_priority <= capture_floor) &&
((task->tcb->Priority_node.real_priority >= capture_ceiling) &&
(task->tcb->Priority_node.real_priority <= capture_floor) &&
((capture_flags & RTEMS_CAPTURE_GLOBAL_WATCH) ||
(control && (control->flags & RTEMS_CAPTURE_WATCH)))))
{
@@ -545,8 +545,8 @@ rtems_capture_record (rtems_capture_task_t* task,
capture_count++;
capture_in->task = task;
capture_in->events = (events |
(task->tcb->real_priority) |
(task->tcb->current_priority << 8));
(task->tcb->Priority_node.real_priority) |
(task->tcb->Priority_node.current_priority << 8));
if ((events & RTEMS_CAPTURE_RECORD_EVENTS) == 0)
task->flags |= RTEMS_CAPTURE_TRACED;

View File

@@ -711,7 +711,7 @@ static inline rtems_task_priority
rtems_capture_task_real_priority (rtems_capture_task_t* task)
{
if (rtems_capture_task_valid (task))
return task->tcb->real_priority;
return task->tcb->Priority_node.real_priority;
return 0;
}
@@ -726,7 +726,7 @@ static inline rtems_task_priority
rtems_capture_task_curr_priority (rtems_capture_task_t* task)
{
if (rtems_capture_task_valid (task))
return task->tcb->current_priority;
return task->tcb->Priority_node.current_priority;
return 0;
}

View File

@@ -29,7 +29,7 @@ rtems_monitor_task_canonical(
canonical_task->argument = rtems_thread->Start.numeric_argument;
canonical_task->stack = rtems_thread->Start.Initial_stack.area;
canonical_task->stack_size = rtems_thread->Start.Initial_stack.size;
canonical_task->priority = rtems_thread->current_priority;
canonical_task->priority = rtems_thread->Priority_node.current_priority;
canonical_task->state = rtems_thread->current_state;
canonical_task->wait_id = rtems_thread->Wait.id;
canonical_task->events = api->pending_events;

View File

@@ -214,7 +214,7 @@ int killinfo(
printk("\n 0x%08x/0x%08x %d/%d 0x%08x 1",
the_thread->Object.id,
((interested) ? interested->Object.id : 0),
the_thread->current_priority, interested_priority,
the_thread->Priority_node.current_priority, interested_priority,
the_thread->current_state
);
#endif
@@ -223,7 +223,7 @@ int killinfo(
* If this thread is of lower priority than the interested thread,
* go on to the next thread.
*/
if ( the_thread->current_priority > interested_priority )
if ( the_thread->Priority_node.current_priority > interested_priority )
continue;
DEBUG_STEP("2");
@@ -250,9 +250,9 @@ int killinfo(
* so we never have to worry about deferencing a NULL
* interested thread.
*/
if ( the_thread->current_priority < interested_priority ) {
if ( the_thread->Priority_node.current_priority < interested_priority ) {
interested = the_thread;
interested_priority = the_thread->current_priority;
interested_priority = the_thread->Priority_node.current_priority;
continue;
}
DEBUG_STEP("4");
@@ -270,7 +270,7 @@ int killinfo(
DEBUG_STEP("5");
if ( _States_Is_ready( the_thread->current_state ) ) {
interested = the_thread;
interested_priority = the_thread->current_priority;
interested_priority = the_thread->Priority_node.current_priority;
continue;
}
@@ -281,7 +281,7 @@ int killinfo(
if ( _States_Is_interruptible_by_signal(the_thread->current_state) ) {
DEBUG_STEP("8");
interested = the_thread;
interested_priority = the_thread->current_priority;
interested_priority = the_thread->Priority_node.current_priority;
continue;
}
}

View File

@@ -84,20 +84,20 @@ 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;
the_thread->Priority_node.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 );
the_thread->Priority_node.current_priority, new_priority );
#endif
if ( the_thread->resource_count == 0 ) {
/*
* If this would make them less important, then do not change it.
*/
if ( the_thread->current_priority > new_priority ) {
if ( the_thread->Priority_node.current_priority > new_priority ) {
_Thread_Change_priority( the_thread, new_priority, true );
#if 0
printk( "raise priority\n" );
@@ -130,14 +130,14 @@ void _POSIX_Threads_Sporadic_budget_callout(
the_thread->cpu_time_budget = 0xFFFFFFFF; /* XXX should be based on MAX_U32 */
new_priority = _POSIX_Priority_To_core(api->schedparam.sched_ss_low_priority);
the_thread->real_priority = new_priority;
the_thread->Priority_node.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 );
the_thread->Priority_node.current_priority, new_priority );
#endif
if ( the_thread->resource_count == 0 ) {
/*
@@ -145,7 +145,7 @@ void _POSIX_Threads_Sporadic_budget_callout(
* to logically lower than sched_ss_low_priority, then we do not want to
* change it.
*/
if ( the_thread->current_priority < new_priority ) {
if ( the_thread->Priority_node.current_priority < new_priority ) {
_Thread_Change_priority( the_thread, new_priority, true );
#if 0
printk( "lower priority\n" );
@@ -181,7 +181,7 @@ bool _POSIX_Threads_Create_extension(
api->schedpolicy = _POSIX_Threads_Default_attributes.schedpolicy;
api->schedparam = _POSIX_Threads_Default_attributes.schedparam;
api->schedparam.sched_priority =
_POSIX_Priority_From_core( created->current_priority );
_POSIX_Priority_From_core( created->Priority_node.current_priority );
/*
* POSIX 1003.1 1996, 18.2.2.2

View File

@@ -46,7 +46,7 @@ int pthread_getschedparam(
if ( param ) {
*param = api->schedparam;
param->sched_priority =
_POSIX_Priority_From_core( the_thread->current_priority );
_POSIX_Priority_From_core( the_thread->Priority_node.current_priority );
}
_Thread_Enable_dispatch();
return 0;

View File

@@ -76,12 +76,12 @@ int pthread_setschedparam(
case SCHED_RR:
the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
the_thread->real_priority =
the_thread->Priority_node.real_priority =
_POSIX_Priority_To_core( api->schedparam.sched_priority );
_Thread_Change_priority(
the_thread,
the_thread->real_priority,
the_thread->Priority_node.real_priority,
true
);
break;

View File

@@ -72,11 +72,11 @@ rtems_status_code rtems_task_set_priority(
case OBJECTS_LOCAL:
/* XXX need helper to "convert" from core priority */
*old_priority = the_thread->current_priority;
*old_priority = the_thread->Priority_node.current_priority;
if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
the_thread->real_priority = new_priority;
the_thread->Priority_node.real_priority = new_priority;
if ( the_thread->resource_count == 0 ||
the_thread->current_priority > new_priority )
the_thread->Priority_node.current_priority > new_priority )
_Thread_Change_priority( the_thread, new_priority, false );
}
_Thread_Enable_dispatch();

View File

@@ -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. */

View File

@@ -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;

View File

@@ -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++;

View File

@@ -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
);
}

View File

@@ -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,

View File

@@ -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);

View File

@@ -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 );

View File

@@ -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;
}
}

View File

@@ -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 );

View File

@@ -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 );

View File

@@ -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

View File

@@ -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 );
}
}

View File

@@ -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;
}
}

View File

@@ -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 );

View File

@@ -39,7 +39,7 @@ const char *CallerName(void)
static char buffer[32];
#if defined(TEST_PRINT_TASK_ID)
sprintf( buffer, "0x%08x -- %d",
rtems_task_self(), _Thread_Executing->current_priority );
rtems_task_self(), _Thread_Executing->Priority_node.current_priority );
#else
volatile union {
uint32_t u;
@@ -53,7 +53,7 @@ const char *CallerName(void)
#endif
sprintf( buffer, "%c%c%c%c -- %" PRIdPriority_Control,
TempName.c[0], TempName.c[1], TempName.c[2], TempName.c[3],
_Thread_Executing->current_priority
_Thread_Executing->Priority_node.current_priority
);
#endif
return buffer;

View File

@@ -81,7 +81,8 @@ const char *CallerName(void)
static char buffer[32];
#if defined(TEST_PRINT_TASK_ID)
sprintf( buffer, "0x%08x -- %d",
rtems_task_self(), _Thread_Executing->current_priority );
rtems_task_self(), _Thread_Executing->Priority_node.current_priority
);
#else
volatile union {
uint32_t u;
@@ -95,7 +96,7 @@ const char *CallerName(void)
#endif
sprintf( buffer, "%c%c%c%c -- %" PRIdPriority_Control,
TempName.c[0], TempName.c[1], TempName.c[2], TempName.c[3],
_Thread_Executing->current_priority
_Thread_Executing->Priority_node.current_priority
);
#endif
return buffer;
@@ -247,7 +248,7 @@ void AccessLocalHw(void)
uint32_t LeaveCnt; /* : */
/* Store information about the current situation */
EnterPrio = _Thread_Executing->current_priority;
EnterPrio = _Thread_Executing->Priority_node.current_priority;
EnterCnt = _Thread_Executing->resource_count;
@@ -266,14 +267,14 @@ void AccessLocalHw(void)
directive_failed( Sts, "rtems_semaphore_obtain(LocalHwAccess_R...)" );
/* Store information about the current situation */
AccessPrio = _Thread_Executing->current_priority;
AccessPrio = _Thread_Executing->Priority_node.current_priority;
AccessCnt = _Thread_Executing->resource_count;
Sts = rtems_semaphore_release(LocalHwAccess_R);
directive_failed( Sts, "rtems_semaphore_release(LocalHwAccess_R)" );
/* Store information about the current situation */
LeavePrio = _Thread_Executing->current_priority;
LeavePrio = _Thread_Executing->Priority_node.current_priority;
LeaveCnt = _Thread_Executing->resource_count;
#if defined(TEST_PRINT_STATISTICS)
@@ -308,7 +309,7 @@ void AccessRemoteHw(void)
uint32_t LeaveCnt; /* : */
/* Store information about the current situation */
EnterPrio = _Thread_Executing->current_priority;
EnterPrio = _Thread_Executing->Priority_node.current_priority;
EnterCnt = _Thread_Executing->resource_count;
@@ -326,14 +327,14 @@ void AccessRemoteHw(void)
AccessLocalHw();
/* Store information about the current situation */
AccessPrio = _Thread_Executing->current_priority;
AccessPrio = _Thread_Executing->Priority_node.current_priority;
AccessCnt = _Thread_Executing->resource_count;
Sts = rtems_semaphore_release(RemoteHwAccess_R);
directive_failed( Sts, "rtems_semaphore_release(RemoreHwAccess_R" );
/* Store information about the current situation */
LeavePrio = _Thread_Executing->current_priority;
LeavePrio = _Thread_Executing->Priority_node.current_priority;
LeaveCnt = _Thread_Executing->resource_count;
#if defined(TEST_PRINT_STATISTICS)