Changeset 878487b0 in rtems


Ignore:
Timestamp:
Nov 5, 2018, 8:53:04 AM (6 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
9bb39516
Parents:
d7c51da
git-author:
Sebastian Huber <sebastian.huber@…> (11/05/18 08:53:04)
git-committer:
Sebastian Huber <sebastian.huber@…> (11/06/18 12:36:11)
Message:

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().

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/objectimpl.h

    rd7c51da r878487b0  
    121121 */
    122122typedef struct {
    123   /** This field indicates the API of this object class. */
    124   Objects_APIs      the_api;
    125   /** This is the class of this object set. */
    126   uint16_t          the_class;
    127123  /** This is the minimum valid id of this object class. */
    128124  Objects_Id        minimum_id;
    129125  /** This is the maximum valid id of this object class. */
    130126  Objects_Id        maximum_id;
     127  /** This points to the table of local objects. */
     128  Objects_Control **local_table;
    131129  /** This is the maximum number of objects in this class. */
    132130  Objects_Maximum   maximum;
     131  /** This is the number of objects on the Inactive list. */
     132  Objects_Maximum   inactive;
     133  /** This is the number of objects in a block. */
     134  Objects_Maximum   allocation_size;
     135  /** This is the maximum length of names. */
     136  uint16_t          name_length;
     137  /** This field indicates the API of this object class. */
     138  uint8_t           the_api;
     139  /** This is the class of this object set. */
     140  uint8_t           the_class;
    133141  /** This is true if names are strings. */
    134142  bool              is_string;
    135143  /** This is the true if unlimited objects in this class. */
    136144  bool              auto_extend;
    137   /** This is the number of objects in a block. */
    138   Objects_Maximum   allocation_size;
    139145  /** This is the size in bytes of each object instance. */
    140146  size_t            size;
    141   /** This points to the table of local objects. */
    142   Objects_Control **local_table;
    143147  /** This is the chain of inactive control blocks. */
    144148  Chain_Control     Inactive;
    145   /** This is the number of objects on the Inactive list. */
    146   Objects_Maximum   inactive;
    147149  /** This is the number of inactive objects per block. */
    148   uint32_t         *inactive_per_block;
     150  Objects_Maximum  *inactive_per_block;
    149151  /** This is a table to the chain of inactive object memory blocks. */
    150   void            **object_blocks;
    151   /** This is the maximum length of names. */
    152   uint16_t          name_length;
     152  Objects_Control **object_blocks;
    153153  #if defined(RTEMS_MULTIPROCESSING)
    154154    /** This is this object class' method called when extracting a thread. */
  • cpukit/score/src/objectextendinformation.c

    rd7c51da r878487b0  
    5252  uint32_t          index;
    5353  uint32_t          maximum;
    54   size_t            block_size;
    55   void             *new_object_block;
     54  size_t            object_block_size;
     55  Objects_Control  *new_object_block;
    5656  bool              do_extend;
    5757
     
    101101   * generate a fatal error depending on auto-extending being active.
    102102   */
    103   block_size = information->allocation_size * information->size;
     103  object_block_size = information->allocation_size * information->size;
    104104  if ( information->auto_extend ) {
    105     new_object_block = _Workspace_Allocate( block_size );
     105    new_object_block = _Workspace_Allocate( object_block_size );
    106106    if ( !new_object_block )
    107107      return;
    108108  } else {
    109     new_object_block = _Workspace_Allocate_or_fatal_error( block_size );
     109    new_object_block = _Workspace_Allocate_or_fatal_error( object_block_size );
    110110  }
    111111
     
    115115  if ( do_extend ) {
    116116    ISR_lock_Context  lock_context;
    117     void            **object_blocks;
    118     uint32_t         *inactive_per_block;
     117    Objects_Control **object_blocks;
    119118    Objects_Control **local_table;
     119    Objects_Maximum  *inactive_per_block;
    120120    void             *old_tables;
    121     size_t            block_size;
     121    size_t            table_size;
    122122    uintptr_t         object_blocks_size;
    123     uintptr_t         inactive_per_block_size;
     123    uintptr_t         local_table_size;
    124124
    125125    /*
     
    130130     *  time through.
    131131     *
    132      *  The allocation has :
    133      *
    134      *      void            *objects[block_count];
    135      *      uint32_t         inactive_count[block_count];
    136      *      Objects_Control *local_table[maximum];
     132     *  The allocation has:
     133     *
     134     *      Objects_Control *object_blocks[ block_count ];
     135     *      Objects_Control *local_table[ maximum ];
     136     *      Objects_Maximum  inactive_count[ block_count ];
    137137     *
    138138     *  This is the order in memory. Watch changing the order. See the memcpy
     
    141141
    142142    /*
    143      *  Up the block count and maximum
     143     *  Up the block count and maximum.
    144144     */
    145145    block_count++;
    146146
    147147    /*
    148      *  Allocate the tables and break it up. The tables are:
    149      *      1. object_blocks        : void*
    150      *      2. inactive_per_blocks : uint32_t
    151      *      3. local_table         : Objects_Name*
    152      */
    153     object_blocks_size = (uintptr_t)_Addresses_Align_up(
    154         (void*)(block_count * sizeof(void*)),
    155         CPU_ALIGNMENT
    156     );
    157     inactive_per_block_size =
    158         (uintptr_t)_Addresses_Align_up(
    159             (void*)(block_count * sizeof(uint32_t)),
    160             CPU_ALIGNMENT
    161         );
    162     block_size = object_blocks_size + inactive_per_block_size +
    163         ((maximum + minimum_index) * sizeof(Objects_Control *));
     148     *  Allocate the tables and break it up.
     149     */
     150    object_blocks_size = block_count * sizeof( *object_blocks );
     151    local_table_size = ( maximum + minimum_index ) * sizeof( *local_table );
     152    table_size = object_blocks_size
     153      + local_table_size
     154      + block_count * sizeof( *inactive_per_block );
    164155    if ( information->auto_extend ) {
    165       object_blocks = _Workspace_Allocate( block_size );
     156      object_blocks = _Workspace_Allocate( table_size );
    166157      if ( !object_blocks ) {
    167158        _Workspace_Free( new_object_block );
     
    169160      }
    170161    } else {
    171       object_blocks = _Workspace_Allocate_or_fatal_error( block_size );
     162      object_blocks = _Workspace_Allocate_or_fatal_error( table_size );
    172163    }
    173164
     
    175166     *  Break the block into the various sections.
    176167     */
    177     inactive_per_block = (uint32_t *) _Addresses_Add_offset(
    178         object_blocks,
    179         object_blocks_size
    180     );
    181     local_table = (Objects_Control **) _Addresses_Add_offset(
    182         inactive_per_block,
    183         inactive_per_block_size
     168    local_table = _Addresses_Add_offset(
     169      object_blocks,
     170      object_blocks_size
     171    );
     172    inactive_per_block = _Addresses_Add_offset(
     173      local_table,
     174      local_table_size
    184175    );
    185176
     
    191182
    192183    if ( information->maximum > minimum_index ) {
    193 
    194184      /*
    195185       *  Copy each section of the table over. This has to be performed as
    196186       *  separate parts as size of each block has changed.
    197187       */
    198 
    199       memcpy( object_blocks,
    200               information->object_blocks,
    201               block_count * sizeof(void*) );
    202       memcpy( inactive_per_block,
    203               information->inactive_per_block,
    204               block_count * sizeof(uint32_t) );
    205       memcpy( local_table,
    206               information->local_table,
    207               (information->maximum + minimum_index) * sizeof(Objects_Control *) );
     188      memcpy(
     189        object_blocks,
     190        information->object_blocks,
     191        block_count * sizeof( *object_blocks )
     192      );
     193      memcpy(
     194        inactive_per_block,
     195        information->inactive_per_block,
     196        block_count * sizeof( *inactive_per_block )
     197      );
     198      memcpy(
     199        local_table,
     200        information->local_table,
     201        ( information->maximum + minimum_index ) * sizeof( *local_table )
     202      );
    208203    } else {
    209 
    210204      /*
    211205       *  Deal with the special case of the 0 to minimum_index
     
    219213     *  Initialise the new entries in the table.
    220214     */
    221     object_blocks[block_count] = NULL;
    222     inactive_per_block[block_count] = 0;
    223 
    224215    for ( index = index_base ; index < index_end ; ++index ) {
    225216      local_table[ index ] = NULL;
     
    236227    information->maximum = (Objects_Maximum) maximum;
    237228    information->maximum_id = _Objects_Build_id(
    238         information->the_api,
    239         information->the_class,
    240         _Objects_Local_node,
    241         information->maximum
    242       );
     229      information->the_api,
     230      information->the_class,
     231      _Objects_Local_node,
     232      information->maximum
     233    );
    243234
    244235    _ISR_lock_ISR_enable( &lock_context );
     
    253244   */
    254245  information->object_blocks[ block ] = new_object_block;
     246  information->inactive_per_block[ block ] = information->allocation_size;
     247  information->inactive += information->allocation_size;
    255248
    256249  /*
    257250   *  Append to inactive chain.
    258251   */
    259   the_object = information->object_blocks[ block ];
     252  the_object = new_object_block;
    260253  for ( index = index_base ; index < index_end ; ++index ) {
    261254    the_object->id = _Objects_Build_id(
     
    269262    _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
    270263
    271     the_object = (Objects_Control *)
    272       ( (char *) the_object + information->size );
    273   }
    274 
    275   information->inactive_per_block[ block ] = information->allocation_size;
    276   information->inactive =
    277     (Objects_Maximum)(information->inactive + information->allocation_size);
     264    the_object = _Addresses_Add_offset( the_object, information->size );
     265  }
    278266}
Note: See TracChangeset for help on using the changeset viewer.