score: Update priority only if necessary

In _Thread_queue_Flush_critical(), update the priority of the thread
queue owner only if necessary.  The scheduler update priority operation
could be expensive.
This commit is contained in:
Sebastian Huber
2021-08-30 18:12:13 +02:00
parent ac9f115bdb
commit 25b0fddad9
3 changed files with 16 additions and 12 deletions

View File

@@ -366,8 +366,8 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Context_clear_priority_updates(
*
* @return The priority update count of @a queue_context.
*/
RTEMS_INLINE_ROUTINE size_t _Thread_queue_Context_save_priority_updates(
Thread_queue_Context *queue_context
RTEMS_INLINE_ROUTINE size_t _Thread_queue_Context_get_priority_updates(
const Thread_queue_Context *queue_context
)
{
return queue_context->Priority.update_count;

View File

@@ -212,7 +212,7 @@ void _Thread_Priority_perform_actions(
*/
the_thread = start_of_path;
update_count = _Thread_queue_Context_save_priority_updates( queue_context );
update_count = _Thread_queue_Context_get_priority_updates( queue_context );
while ( true ) {
Thread_queue_Queue *queue;

View File

@@ -71,15 +71,15 @@ size_t _Thread_queue_Flush_critical(
Thread_queue_Context *queue_context
)
{
size_t flushed;
Chain_Control unblock;
Thread_Control *owner;
Chain_Node *node;
Chain_Node *tail;
size_t flushed;
size_t priority_updates;
Chain_Control unblock;
Chain_Node *node;
Chain_Node *tail;
flushed = 0;
priority_updates = 0;
_Chain_Initialize_empty( &unblock );
owner = queue->owner;
while ( true ) {
Thread_queue_Heads *heads;
@@ -99,8 +99,7 @@ size_t _Thread_queue_Flush_critical(
/*
* We do not have enough space in the queue context to collect all priority
* updates, so clear it each time. We unconditionally do the priority
* update for the owner later if it exists.
* updates, so clear it each time and accumulate the priority updates.
*/
_Thread_queue_Context_clear_priority_updates( queue_context );
@@ -120,6 +119,8 @@ size_t _Thread_queue_Flush_critical(
);
}
priority_updates +=
_Thread_queue_Context_get_priority_updates( queue_context );
++flushed;
}
@@ -145,9 +146,12 @@ size_t _Thread_queue_Flush_critical(
node = next;
} while ( node != tail );
if ( owner != NULL ) {
if ( priority_updates != 0 ) {
Thread_Control *owner;
ISR_lock_Context lock_context;
owner = queue->owner;
_Assert( owner != NULL );
_Thread_State_acquire( owner, &lock_context );
_Scheduler_Update_priority( owner );
_Thread_State_release( owner, &lock_context );