diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-08-10 15:07:35 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-08-12 20:58:26 +0200 |
commit | a5aaf20a2d25846c2bfe78e286550fed38d2c111 (patch) | |
tree | 6918797e365abb7fba28ef3adc9ef2ed260bde02 /cpukit/include | |
parent | rtems: Fix rtems_partition_return_buffer() (diff) | |
download | rtems-a5aaf20a2d25846c2bfe78e286550fed38d2c111.tar.bz2 |
score: Replace priority prepend it with an enum
Use the new Priority_Group_order enum instead of a boolean to indicated if a
priority should be inserted as the first or last node into its priority group.
This makes the code more expressive. It is also a bit more efficient since a
branch in _Scheduler_Node_set_priority() is avoided and a simple bitwise or
operation can be used.
Diffstat (limited to 'cpukit/include')
-rw-r--r-- | cpukit/include/rtems/posix/muteximpl.h | 2 | ||||
-rw-r--r-- | cpukit/include/rtems/score/coremuteximpl.h | 2 | ||||
-rw-r--r-- | cpukit/include/rtems/score/priorityimpl.h | 44 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulerimpl.h | 12 | ||||
-rw-r--r-- | cpukit/include/rtems/score/schedulernodeimpl.h | 30 | ||||
-rw-r--r-- | cpukit/include/rtems/score/threadimpl.h | 20 |
6 files changed, 69 insertions, 41 deletions
diff --git a/cpukit/include/rtems/posix/muteximpl.h b/cpukit/include/rtems/posix/muteximpl.h index 435b43634d..5d20bc1ef6 100644 --- a/cpukit/include/rtems/posix/muteximpl.h +++ b/cpukit/include/rtems/posix/muteximpl.h @@ -273,7 +273,7 @@ RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Set_priority( owner, &the_mutex->Priority_ceiling, priority_ceiling, - false, + PRIORITY_GROUP_LAST, queue_context ); _Thread_Wait_release( owner, queue_context ); diff --git a/cpukit/include/rtems/score/coremuteximpl.h b/cpukit/include/rtems/score/coremuteximpl.h index cbc1e720fb..426c4c5a95 100644 --- a/cpukit/include/rtems/score/coremuteximpl.h +++ b/cpukit/include/rtems/score/coremuteximpl.h @@ -375,7 +375,7 @@ RTEMS_INLINE_ROUTINE void _CORE_ceiling_mutex_Set_priority( owner, &the_mutex->Priority_ceiling, priority_ceiling, - false, + PRIORITY_GROUP_LAST, queue_context ); _Thread_Wait_release( owner, queue_context ); diff --git a/cpukit/include/rtems/score/priorityimpl.h b/cpukit/include/rtems/score/priorityimpl.h index 7a14ec97b8..2895a0c4a5 100644 --- a/cpukit/include/rtems/score/priorityimpl.h +++ b/cpukit/include/rtems/score/priorityimpl.h @@ -37,6 +37,29 @@ extern "C" { * @{ */ + /** + * @brief The priority group order determines if a priority node is inserted + * as the first or last node into its priority group. + * + * The values of the enumerators matter. The least significant bit of a + * ::Priority_Control value is not used for the actual priority of a node. + * During insertion the least significant bit is used to determine the + * ordering within a priority group based on the enumerator values. + */ +typedef enum { + /** + * @brief Priority group first option requests that the priority node is + * inserted as the first node into its priority group. + */ + PRIORITY_GROUP_FIRST = 0, + + /** + * @brief Priority group last option requests that the priority node is + * inserted as the last node into its priority group. + */ + PRIORITY_GROUP_LAST = 1 +} Priority_Group_order; + /** * @brief Initializes the priority actions empty. * @@ -465,7 +488,7 @@ typedef void ( *Priority_Add_handler )( typedef void ( *Priority_Change_handler )( Priority_Aggregation *aggregation, - bool prepend_it, + Priority_Group_order group_order, Priority_Actions *actions, void *arg ); @@ -482,19 +505,19 @@ typedef void ( *Priority_Remove_handler )( * This method does nothing. * * @param aggregation Is ignored by the method. - * @param prepend_it Is ignored by the method. + * @param group_order Is ignored by the method. * @param actions Is ignored by the method. * @param arg Is ignored by the method. */ RTEMS_INLINE_ROUTINE void _Priority_Change_nothing( Priority_Aggregation *aggregation, - bool prepend_it, + Priority_Group_order group_order, Priority_Actions *actions, void *arg ) { (void) aggregation; - (void) prepend_it; + (void) group_order; (void) actions; (void) arg; } @@ -547,7 +570,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Non_empty_insert( if ( is_new_minimum ) { aggregation->Node.priority = node->priority; - ( *change )( aggregation, false, actions, arg ); + ( *change )( aggregation, PRIORITY_GROUP_LAST, actions, arg ); } } @@ -619,7 +642,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Extract( if ( node->priority < min->priority ) { aggregation->Node.priority = min->priority; - ( *change )( aggregation, true, actions, arg ); + ( *change )( aggregation, PRIORITY_GROUP_FIRST, actions, arg ); } } } @@ -654,7 +677,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Extract_non_empty( if ( node->priority < min->priority ) { aggregation->Node.priority = min->priority; - ( *change )( aggregation, true, actions, arg ); + ( *change )( aggregation, PRIORITY_GROUP_FIRST, actions, arg ); } } @@ -666,8 +689,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Extract_non_empty( * * @param[in, out] aggregation The aggregation to change the node in. * @param node The node that has a new priority and will be reinserted in the aggregation. - * @param prepend_it Indicates whether @a change should prepend if the minimal priority is - * incorrectly set after the change. + * @param group_order The priority group order which may be used by @ change. * @param actions The actions for the case that the minimal priority is incorrectly set * after the change. * @param change Is called if the minimal priority is incorrectly set after the change. @@ -676,7 +698,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Extract_non_empty( RTEMS_INLINE_ROUTINE void _Priority_Changed( Priority_Aggregation *aggregation, Priority_Node *node, - bool prepend_it, + Priority_Group_order group_order, Priority_Actions *actions, Priority_Change_handler change, void *arg @@ -695,7 +717,7 @@ RTEMS_INLINE_ROUTINE void _Priority_Changed( if ( min->priority != aggregation->Node.priority ) { aggregation->Node.priority = min->priority; - ( *change )( aggregation, prepend_it, actions, arg ); + ( *change )( aggregation, group_order, actions, arg ); } } diff --git a/cpukit/include/rtems/score/schedulerimpl.h b/cpukit/include/rtems/score/schedulerimpl.h index 595d6291b4..24db4d7818 100644 --- a/cpukit/include/rtems/score/schedulerimpl.h +++ b/cpukit/include/rtems/score/schedulerimpl.h @@ -1388,7 +1388,11 @@ RTEMS_INLINE_ROUTINE Status_Control _Scheduler_Set( &new_scheduler_node->Thread.Scheduler_node.Chain ); - _Scheduler_Node_set_priority( new_scheduler_node, priority, false ); + _Scheduler_Node_set_priority( + new_scheduler_node, + priority, + PRIORITY_GROUP_LAST + ); if ( _States_Is_ready( current_state ) ) { _Scheduler_Unblock( the_thread ); @@ -1398,7 +1402,11 @@ RTEMS_INLINE_ROUTINE Status_Control _Scheduler_Set( } #endif - _Scheduler_Node_set_priority( new_scheduler_node, priority, false ); + _Scheduler_Node_set_priority( + new_scheduler_node, + priority, + PRIORITY_GROUP_LAST + ); _Scheduler_Update_priority( the_thread ); return STATUS_SUCCESSFUL; } diff --git a/cpukit/include/rtems/score/schedulernodeimpl.h b/cpukit/include/rtems/score/schedulernodeimpl.h index 5d6f795912..9b5c632d86 100644 --- a/cpukit/include/rtems/score/schedulernodeimpl.h +++ b/cpukit/include/rtems/score/schedulernodeimpl.h @@ -47,12 +47,6 @@ extern "C" { RTEMS_CONTAINER_OF( node, Scheduler_Node, Wait.Priority ) /** - * @brief Priority append indicator for the priority control used for the - * scheduler node priority. - */ -#define SCHEDULER_PRIORITY_APPEND_FLAG 1 - -/** * @brief Maps a priority value to support the append indicator. */ #define SCHEDULER_PRIORITY_MAP( priority ) ( ( priority ) << 1 ) @@ -66,13 +60,13 @@ extern "C" { * @brief Clears the priority append indicator bit. */ #define SCHEDULER_PRIORITY_PURIFY( priority ) \ - ( ( priority ) & ~( (Priority_Control) SCHEDULER_PRIORITY_APPEND_FLAG ) ) + ( ( priority ) & ~( (Priority_Control) PRIORITY_GROUP_LAST ) ) /** * @brief Returns the priority control with the append indicator bit set. */ #define SCHEDULER_PRIORITY_APPEND( priority ) \ - ( ( priority ) | SCHEDULER_PRIORITY_APPEND_FLAG ) + ( ( priority ) | ( (Priority_Control) PRIORITY_GROUP_LAST ) ) /** * @brief Returns true, if the item should be appended to its priority group, @@ -80,7 +74,7 @@ extern "C" { * group. */ #define SCHEDULER_PRIORITY_IS_APPEND( priority ) \ - ( ( ( priority ) & SCHEDULER_PRIORITY_APPEND_FLAG ) != 0 ) + ( ( ( priority ) & ( (Priority_Control) PRIORITY_GROUP_LAST ) ) != 0 ) /** * @brief Initializes a node. @@ -173,14 +167,17 @@ RTEMS_INLINE_ROUTINE Priority_Control _Scheduler_Node_get_priority( /** * @brief Sets the priority of the node. * - * @param[in, out] node The node to set the priority of. - * @param new_priority The new priority for @a node. - * @param prepend_it Indicates whether the new priority should be prepended. + * @param[in, out] node is the scheduler node. + * + * @param new_priority is the priority to set. + * + * @param group_order is the priority group order, see #PRIORITY_GROUP_FIRST + * and #PRIORITY_GROUP_LAST. */ RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_priority( - Scheduler_Node *node, - Priority_Control new_priority, - bool prepend_it + Scheduler_Node *node, + Priority_Control new_priority, + Priority_Group_order group_order ) { #if defined(RTEMS_SMP) @@ -189,8 +186,7 @@ RTEMS_INLINE_ROUTINE void _Scheduler_Node_set_priority( seq = _SMP_sequence_lock_Write_begin( &node->Priority.Lock ); #endif - new_priority |= ( prepend_it ? 0 : SCHEDULER_PRIORITY_APPEND_FLAG ); - node->Priority.value = new_priority; + node->Priority.value = new_priority | ( (Priority_Control) group_order ); #if defined(RTEMS_SMP) _SMP_sequence_lock_Write_end( &node->Priority.Lock, seq ); diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index ecc8eee058..c4b6c941a4 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -691,9 +691,10 @@ void _Thread_Priority_remove( * * @param the_thread The thread. * @param[out] priority_node The thread priority node to change. - * @param prepend_it In case this is true, then the thread is prepended to - * its priority group in its home scheduler instance, otherwise it is - * appended. + * @param priority_group_order The priority group order determines if the + * thread is inserted as the first or last node into the ready or scheduled + * queues of its home scheduler, see #PRIORITY_GROUP_FIRST and + * #PRIORITY_GROUP_LAST. * @param queue_context The thread queue context to return an updated set of * threads for _Thread_Priority_update(). The thread queue context must be * initialized via _Thread_queue_Context_clear_priority_updates() before a @@ -704,7 +705,7 @@ void _Thread_Priority_remove( void _Thread_Priority_changed( Thread_Control *the_thread, Priority_Node *priority_node, - bool prepend_it, + Priority_Group_order priority_group_order, Thread_queue_Context *queue_context ); @@ -718,9 +719,10 @@ void _Thread_Priority_changed( * @param[out] priority_node The thread priority node to change. * @param new_priority The new thread priority value of the thread priority * node to change. - * @param prepend_it In case this is true, then the thread is prepended to - * its priority group in its home scheduler instance, otherwise it is - * appended. + * @param priority_group_order The priority group order determines if the + * thread is inserted as the first or last node into the ready or scheduled + * queues of its home scheduler, see #PRIORITY_GROUP_FIRST and + * #PRIORITY_GROUP_LAST. * @param queue_context The thread queue context to return an updated set of * threads for _Thread_Priority_update(). The thread queue context must be * initialized via _Thread_queue_Context_clear_priority_updates() before a @@ -732,7 +734,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Priority_change( Thread_Control *the_thread, Priority_Node *priority_node, Priority_Control new_priority, - bool prepend_it, + Priority_Group_order priority_group_order, Thread_queue_Context *queue_context ) { @@ -740,7 +742,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Priority_change( _Thread_Priority_changed( the_thread, priority_node, - prepend_it, + priority_group_order, queue_context ); } |