diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-12-07 11:48:36 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-12-11 09:05:07 +0100 |
commit | 01f8c12ee57230fca1581e1b5be91f3decba0488 (patch) | |
tree | 279ef8193d107ea59490e3fdeb18d20639c54f36 /cpukit/include | |
parent | score: Optimize _TLS_Get_size() (diff) | |
download | rtems-01f8c12ee57230fca1581e1b5be91f3decba0488.tar.bz2 |
rtems: Optimize semaphore control block
Move variant, discipline, and global information to flags stored in a
node pointer of active semaphores.
Update #3833.
Diffstat (limited to 'cpukit/include')
-rw-r--r-- | cpukit/include/rtems/rtems/semdata.h | 28 | ||||
-rw-r--r-- | cpukit/include/rtems/rtems/semimpl.h | 69 |
2 files changed, 75 insertions, 22 deletions
diff --git a/cpukit/include/rtems/rtems/semdata.h b/cpukit/include/rtems/rtems/semdata.h index d2275e5dfe..f5a8afcc87 100644 --- a/cpukit/include/rtems/rtems/semdata.h +++ b/cpukit/include/rtems/rtems/semdata.h @@ -38,7 +38,15 @@ extern "C" { * The following defines the control block used to manage each semaphore. */ typedef struct { - /** This field is the object management portion of a Semaphore instance. */ + /** + * @brief The object management portion of a semaphore instance. + * + * A pointer of the node of active semaphores contains the semaphore flags, + * see _Semaphore_Get_flags(). The rational for this optimization is a + * reduction of the semaphore control size in general and the ability to + * allow a configuration dependent size of the semaphore control block, e.g. + * for the MrsP semaphores. + */ Objects_Control Object; /** @@ -72,24 +80,6 @@ typedef struct { MRSP_Control MRSP; #endif } Core_control; - - /** - * @brief The semaphore variant. - * - * @see Semaphore_Variant. - */ - unsigned int variant : 3; - - /** - * @brief The semaphore thread queue discipline. - * - * @see Semaphore_Discipline. - */ - unsigned int discipline : 1; - -#if defined(RTEMS_MULTIPROCESSING) - unsigned int is_global : 1; -#endif } Semaphore_Control; /** diff --git a/cpukit/include/rtems/rtems/semimpl.h b/cpukit/include/rtems/rtems/semimpl.h index dd6a8b4e48..0cb78e35d4 100644 --- a/cpukit/include/rtems/rtems/semimpl.h +++ b/cpukit/include/rtems/rtems/semimpl.h @@ -56,15 +56,78 @@ typedef enum { SEMAPHORE_DISCIPLINE_FIFO } Semaphore_Discipline; -RTEMS_INLINE_ROUTINE const Thread_queue_Operations *_Semaphore_Get_operations( +RTEMS_INLINE_ROUTINE uintptr_t _Semaphore_Get_flags( const Semaphore_Control *the_semaphore ) { - if ( the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY ) { + _Assert( _Chain_Is_node_off_chain( &the_semaphore->Object.Node ) ); + return (uintptr_t) the_semaphore->Object.Node.previous; +} + +RTEMS_INLINE_ROUTINE void _Semaphore_Set_flags( + Semaphore_Control *the_semaphore, + uintptr_t flags +) +{ + _Assert( _Chain_Is_node_off_chain( &the_semaphore->Object.Node ) ); + the_semaphore->Object.Node.previous = (Chain_Node *) flags; +} + +RTEMS_INLINE_ROUTINE Semaphore_Variant _Semaphore_Get_variant( + uintptr_t flags +) +{ + return (Semaphore_Discipline) ( flags & 0x7 ); +} + +RTEMS_INLINE_ROUTINE uintptr_t _Semaphore_Set_variant( + uintptr_t flags, + Semaphore_Variant variant +) +{ + return flags | variant; +} + +RTEMS_INLINE_ROUTINE Semaphore_Discipline _Semaphore_Get_discipline( + uintptr_t flags +) +{ + return (Semaphore_Discipline) ( ( flags >> 3 ) & 0x1 ); +} + +RTEMS_INLINE_ROUTINE uintptr_t _Semaphore_Set_discipline( + uintptr_t flags, + Semaphore_Discipline discipline +) +{ + return flags | ( discipline << 3 ); +} + +#if defined(RTEMS_MULTIPROCESSING) +RTEMS_INLINE_ROUTINE bool _Semaphore_Is_global( + uintptr_t flags +) +{ + return ( flags & 0x10 ) != 0; +} + +RTEMS_INLINE_ROUTINE uintptr_t _Semaphore_Make_global( uintptr_t flags ) +{ + return flags | 0x10; +} +#endif + +RTEMS_INLINE_ROUTINE const Thread_queue_Operations *_Semaphore_Get_operations( + uintptr_t flags +) +{ + if ( + _Semaphore_Get_variant( flags ) == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY + ) { return &_Thread_queue_Operations_priority_inherit; } - if ( the_semaphore->discipline == SEMAPHORE_DISCIPLINE_PRIORITY ) { + if ( _Semaphore_Get_discipline( flags ) == SEMAPHORE_DISCIPLINE_PRIORITY ) { return &_Thread_queue_Operations_priority; } |