[PATCH 5/5] score: Update priority only if necessary
Gedare Bloom
gedare at rtems.org
Wed Sep 1 17:01:05 UTC 2021
ok, just the one note about doxygen. thanks!
On Tue, Aug 31, 2021 at 5:24 AM Sebastian Huber
<sebastian.huber at embedded-brains.de> wrote:
>
> 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/include/rtems/score/threadqimpl.h | 4 ++--
> cpukit/score/src/threadchangepriority.c | 2 +-
> cpukit/score/src/threadqflush.c | 22 +++++++++++++---------
> 3 files changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/threadqimpl.h b/cpukit/include/rtems/score/threadqimpl.h
> index f42c67cc47..33cdb3058d 100644
> --- a/cpukit/include/rtems/score/threadqimpl.h
> +++ b/cpukit/include/rtems/score/threadqimpl.h
> @@ -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;
> diff --git a/cpukit/score/src/threadchangepriority.c b/cpukit/score/src/threadchangepriority.c
> index ac2e9a6d0c..613d0cd7af 100644
> --- a/cpukit/score/src/threadchangepriority.c
> +++ b/cpukit/score/src/threadchangepriority.c
> @@ -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;
> 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 );
> --
> 2.26.2
>
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
More information about the devel
mailing list