[rtems commit] score: Optimize Objects_Information

Joel Sherrill joel at rtems.org
Tue Nov 6 21:33:39 UTC 2018


Just confirming that no fields changed names.

--joel

On Tue, Nov 6, 2018 at 6:37 AM Sebastian Huber <sebh at rtems.org> wrote:

> Module:    rtems
> Branch:    master
> Commit:    878487b024578e887f27719887d7cada84db23bc
> Changeset:
> http://git.rtems.org/rtems/commit/?id=878487b024578e887f27719887d7cada84db23bc
>
> Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
> Date:      Mon Nov  5 09:53:04 2018 +0100
>
> score: Optimize Objects_Information
>
> Reduce structure internal padding.  Group members used by _Objects_Get()
> together.  Reduce size of some members.
>
> Format and simplify _Objects_Extend_information().
>
> ---
>
>  cpukit/include/rtems/score/objectimpl.h    |  28 +++----
>  cpukit/score/src/objectextendinformation.c | 116
> +++++++++++++----------------
>  2 files changed, 66 insertions(+), 78 deletions(-)
>
> diff --git a/cpukit/include/rtems/score/objectimpl.h
> b/cpukit/include/rtems/score/objectimpl.h
> index 1bef14b..bf4d45d 100644
> --- a/cpukit/include/rtems/score/objectimpl.h
> +++ b/cpukit/include/rtems/score/objectimpl.h
> @@ -120,36 +120,36 @@ typedef void ( *Objects_Thread_queue_Extract_callout
> )(
>   *  manage each class of objects.
>   */
>  typedef struct {
> -  /** This field indicates the API of this object class. */
> -  Objects_APIs      the_api;
> -  /** This is the class of this object set. */
> -  uint16_t          the_class;
>    /** This is the minimum valid id of this object class. */
>    Objects_Id        minimum_id;
>    /** This is the maximum valid id of this object class. */
>    Objects_Id        maximum_id;
> +  /** This points to the table of local objects. */
> +  Objects_Control **local_table;
>    /** This is the maximum number of objects in this class. */
>    Objects_Maximum   maximum;
> +  /** This is the number of objects on the Inactive list. */
> +  Objects_Maximum   inactive;
> +  /** This is the number of objects in a block. */
> +  Objects_Maximum   allocation_size;
> +  /** This is the maximum length of names. */
> +  uint16_t          name_length;
> +  /** This field indicates the API of this object class. */
> +  uint8_t           the_api;
> +  /** This is the class of this object set. */
> +  uint8_t           the_class;
>    /** This is true if names are strings. */
>    bool              is_string;
>    /** This is the true if unlimited objects in this class. */
>    bool              auto_extend;
> -  /** This is the number of objects in a block. */
> -  Objects_Maximum   allocation_size;
>    /** This is the size in bytes of each object instance. */
>    size_t            size;
> -  /** This points to the table of local objects. */
> -  Objects_Control **local_table;
>    /** This is the chain of inactive control blocks. */
>    Chain_Control     Inactive;
> -  /** This is the number of objects on the Inactive list. */
> -  Objects_Maximum   inactive;
>    /** This is the number of inactive objects per block. */
> -  uint32_t         *inactive_per_block;
> +  Objects_Maximum  *inactive_per_block;
>    /** This is a table to the chain of inactive object memory blocks. */
> -  void            **object_blocks;
> -  /** This is the maximum length of names. */
> -  uint16_t          name_length;
> +  Objects_Control **object_blocks;
>    #if defined(RTEMS_MULTIPROCESSING)
>      /** This is this object class' method called when extracting a
> thread. */
>      Objects_Thread_queue_Extract_callout extract;
> diff --git a/cpukit/score/src/objectextendinformation.c
> b/cpukit/score/src/objectextendinformation.c
> index f4ac11b..d2ee7fd 100644
> --- a/cpukit/score/src/objectextendinformation.c
> +++ b/cpukit/score/src/objectextendinformation.c
> @@ -51,8 +51,8 @@ void _Objects_Extend_information(
>    uint32_t          minimum_index;
>    uint32_t          index;
>    uint32_t          maximum;
> -  size_t            block_size;
> -  void             *new_object_block;
> +  size_t            object_block_size;
> +  Objects_Control  *new_object_block;
>    bool              do_extend;
>
>    _Assert(
> @@ -100,13 +100,13 @@ void _Objects_Extend_information(
>     * Allocate the name table, and the objects and if it fails either
> return or
>     * generate a fatal error depending on auto-extending being active.
>     */
> -  block_size = information->allocation_size * information->size;
> +  object_block_size = information->allocation_size * information->size;
>    if ( information->auto_extend ) {
> -    new_object_block = _Workspace_Allocate( block_size );
> +    new_object_block = _Workspace_Allocate( object_block_size );
>      if ( !new_object_block )
>        return;
>    } else {
> -    new_object_block = _Workspace_Allocate_or_fatal_error( block_size );
> +    new_object_block = _Workspace_Allocate_or_fatal_error(
> object_block_size );
>    }
>
>    /*
> @@ -114,13 +114,13 @@ void _Objects_Extend_information(
>     */
>    if ( do_extend ) {
>      ISR_lock_Context  lock_context;
> -    void            **object_blocks;
> -    uint32_t         *inactive_per_block;
> +    Objects_Control **object_blocks;
>      Objects_Control **local_table;
> +    Objects_Maximum  *inactive_per_block;
>      void             *old_tables;
> -    size_t            block_size;
> +    size_t            table_size;
>      uintptr_t         object_blocks_size;
> -    uintptr_t         inactive_per_block_size;
> +    uintptr_t         local_table_size;
>
>      /*
>       *  Growing the tables means allocating a new area, doing a copy and
> @@ -129,58 +129,49 @@ void _Objects_Extend_information(
>       *  If the maximum is minimum we do not have a table to copy. First
>       *  time through.
>       *
> -     *  The allocation has :
> +     *  The allocation has:
>       *
> -     *      void            *objects[block_count];
> -     *      uint32_t         inactive_count[block_count];
> -     *      Objects_Control *local_table[maximum];
> +     *      Objects_Control *object_blocks[ block_count ];
> +     *      Objects_Control *local_table[ maximum ];
> +     *      Objects_Maximum  inactive_count[ block_count ];
>       *
>       *  This is the order in memory. Watch changing the order. See the
> memcpy
>       *  below.
>       */
>
>      /*
> -     *  Up the block count and maximum
> +     *  Up the block count and maximum.
>       */
>      block_count++;
>
>      /*
> -     *  Allocate the tables and break it up. The tables are:
> -     *      1. object_blocks        : void*
> -     *      2. inactive_per_blocks : uint32_t
> -     *      3. local_table         : Objects_Name*
> +     *  Allocate the tables and break it up.
>       */
> -    object_blocks_size = (uintptr_t)_Addresses_Align_up(
> -        (void*)(block_count * sizeof(void*)),
> -        CPU_ALIGNMENT
> -    );
> -    inactive_per_block_size =
> -        (uintptr_t)_Addresses_Align_up(
> -            (void*)(block_count * sizeof(uint32_t)),
> -            CPU_ALIGNMENT
> -        );
> -    block_size = object_blocks_size + inactive_per_block_size +
> -        ((maximum + minimum_index) * sizeof(Objects_Control *));
> +    object_blocks_size = block_count * sizeof( *object_blocks );
> +    local_table_size = ( maximum + minimum_index ) * sizeof( *local_table
> );
> +    table_size = object_blocks_size
> +      + local_table_size
> +      + block_count * sizeof( *inactive_per_block );
>      if ( information->auto_extend ) {
> -      object_blocks = _Workspace_Allocate( block_size );
> +      object_blocks = _Workspace_Allocate( table_size );
>        if ( !object_blocks ) {
>          _Workspace_Free( new_object_block );
>          return;
>        }
>      } else {
> -      object_blocks = _Workspace_Allocate_or_fatal_error( block_size );
> +      object_blocks = _Workspace_Allocate_or_fatal_error( table_size );
>      }
>
>      /*
>       *  Break the block into the various sections.
>       */
> -    inactive_per_block = (uint32_t *) _Addresses_Add_offset(
> -        object_blocks,
> -        object_blocks_size
> +    local_table = _Addresses_Add_offset(
> +      object_blocks,
> +      object_blocks_size
>      );
> -    local_table = (Objects_Control **) _Addresses_Add_offset(
> -        inactive_per_block,
> -        inactive_per_block_size
> +    inactive_per_block = _Addresses_Add_offset(
> +      local_table,
> +      local_table_size
>      );
>
>      /*
> @@ -190,23 +181,26 @@ void _Objects_Extend_information(
>      block_count--;
>
>      if ( information->maximum > minimum_index ) {
> -
>        /*
>         *  Copy each section of the table over. This has to be performed as
>         *  separate parts as size of each block has changed.
>         */
> -
> -      memcpy( object_blocks,
> -              information->object_blocks,
> -              block_count * sizeof(void*) );
> -      memcpy( inactive_per_block,
> -              information->inactive_per_block,
> -              block_count * sizeof(uint32_t) );
> -      memcpy( local_table,
> -              information->local_table,
> -              (information->maximum + minimum_index) *
> sizeof(Objects_Control *) );
> +      memcpy(
> +        object_blocks,
> +        information->object_blocks,
> +        block_count * sizeof( *object_blocks )
> +      );
> +      memcpy(
> +        inactive_per_block,
> +        information->inactive_per_block,
> +        block_count * sizeof( *inactive_per_block )
> +      );
> +      memcpy(
> +        local_table,
> +        information->local_table,
> +        ( information->maximum + minimum_index ) * sizeof( *local_table )
> +      );
>      } else {
> -
>        /*
>         *  Deal with the special case of the 0 to minimum_index
>         */
> @@ -218,9 +212,6 @@ void _Objects_Extend_information(
>      /*
>       *  Initialise the new entries in the table.
>       */
> -    object_blocks[block_count] = NULL;
> -    inactive_per_block[block_count] = 0;
> -
>      for ( index = index_base ; index < index_end ; ++index ) {
>        local_table[ index ] = NULL;
>      }
> @@ -235,11 +226,11 @@ void _Objects_Extend_information(
>      information->local_table = local_table;
>      information->maximum = (Objects_Maximum) maximum;
>      information->maximum_id = _Objects_Build_id(
> -        information->the_api,
> -        information->the_class,
> -        _Objects_Local_node,
> -        information->maximum
> -      );
> +      information->the_api,
> +      information->the_class,
> +      _Objects_Local_node,
> +      information->maximum
> +    );
>
>      _ISR_lock_ISR_enable( &lock_context );
>
> @@ -252,11 +243,13 @@ void _Objects_Extend_information(
>     *  Assign the new object block to the object block table.
>     */
>    information->object_blocks[ block ] = new_object_block;
> +  information->inactive_per_block[ block ] = information->allocation_size;
> +  information->inactive += information->allocation_size;
>
>    /*
>     *  Append to inactive chain.
>     */
> -  the_object = information->object_blocks[ block ];
> +  the_object = new_object_block;
>    for ( index = index_base ; index < index_end ; ++index ) {
>      the_object->id = _Objects_Build_id(
>        information->the_api,
> @@ -268,11 +261,6 @@ void _Objects_Extend_information(
>      _Chain_Initialize_node( &the_object->Node );
>      _Chain_Append_unprotected( &information->Inactive, &the_object->Node
> );
>
> -    the_object = (Objects_Control *)
> -      ( (char *) the_object + information->size );
> +    the_object = _Addresses_Add_offset( the_object, information->size );
>    }
> -
> -  information->inactive_per_block[ block ] = information->allocation_size;
> -  information->inactive =
> -    (Objects_Maximum)(information->inactive +
> information->allocation_size);
>  }
>
> _______________________________________________
> vc mailing list
> vc at rtems.org
> http://lists.rtems.org/mailman/listinfo/vc
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20181106/dd824157/attachment-0001.html>


More information about the devel mailing list