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().
This commit is contained in:
Sebastian Huber
2018-11-05 09:53:04 +01:00
parent d7c51da558
commit 878487b024
2 changed files with 66 additions and 78 deletions

View File

@@ -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;

View File

@@ -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);
}