From 25b0fddad9b3dad27eca0228fb4d7ba45ec459df Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 30 Aug 2021 18:12:13 +0200 Subject: 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. --- cpukit/score/src/threadqflush.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'cpukit/score/src/threadqflush.c') diff --git a/cpukit/score/src/threadqflush.c b/cpukit/score/src/threadqflush.c index 357e3d696e..42b35a499b 100644 --- a/cpukit/score/src/threadqflush.c +++ b/cpukit/score/src/threadqflush.c @@ -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 ); -- cgit v1.2.3