summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-11-24 11:51:28 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-12-07 14:22:01 +0100
commit3899bc1a4b3294306ae2fd3f8ff0ee10365d9f4b (patch)
tree3912fc89bbde8a64a20111e02c618e85eb7bb000 /cpukit/score
parentscore: Rename Objects_Information::allocation_size (diff)
downloadrtems-3899bc1a4b3294306ae2fd3f8ff0ee10365d9f4b.tar.bz2
score: Optimize object lookup
Use the maximum ID for the ID to object translation. Using the maximum ID gets rid of an additional load from the object information in _Objects_Get(). In addition, object lookups fail for every ID in case the object information is cleared to zero. This makes it a bit more robust during system startup (see new tests in spconfig02). The local table no longer needs a NULL pointer entry at array index zero. Adjust all the object iteration loops accordingly. Remove Objects_Information::minimum_id since it contains only redundant information. Add _Objects_Get_minimum_id() to get the minimum ID. Update #3621.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/src/objectallocate.c9
-rw-r--r--cpukit/score/src/objectextendinformation.c20
-rw-r--r--cpukit/score/src/objectfree.c3
-rw-r--r--cpukit/score/src/objectgetlocal.c21
-rw-r--r--cpukit/score/src/objectgetnext.c2
-rw-r--r--cpukit/score/src/objectgetnoprotection.c19
-rw-r--r--cpukit/score/src/objectinitializeinformation.c17
-rw-r--r--cpukit/score/src/objectnametoid.c4
-rw-r--r--cpukit/score/src/objectnametoidstring.c2
-rw-r--r--cpukit/score/src/objectshrinkinformation.c10
-rw-r--r--cpukit/score/src/threaditerate.c2
11 files changed, 44 insertions, 65 deletions
diff --git a/cpukit/score/src/objectallocate.c b/cpukit/score/src/objectallocate.c
index 81e322757c..2f991477da 100644
--- a/cpukit/score/src/objectallocate.c
+++ b/cpukit/score/src/objectallocate.c
@@ -62,16 +62,15 @@ Objects_Control *_Objects_Allocate_unprotected(
* extend information base.
*/
- if ( !the_object ) {
+ if ( the_object == NULL ) {
_Objects_Extend_information( information );
the_object = _Objects_Get_inactive( information );
}
- if ( the_object ) {
- uint32_t block;
+ if ( the_object != NULL ) {
+ Objects_Maximum block;
- block = (uint32_t) _Objects_Get_index( the_object->id ) -
- _Objects_Get_index( information->minimum_id );
+ block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
block /= information->objects_per_block;
information->inactive_per_block[ block ]--;
diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
index b8e72f93b6..a8346ce937 100644
--- a/cpukit/score/src/objectextendinformation.c
+++ b/cpukit/score/src/objectextendinformation.c
@@ -48,7 +48,6 @@ void _Objects_Extend_information(
uint32_t block;
uint32_t index_base;
uint32_t index_end;
- uint32_t minimum_index;
uint32_t index;
uint32_t maximum;
size_t object_block_size;
@@ -65,11 +64,9 @@ void _Objects_Extend_information(
* extend the block table, then we will change do_extend.
*/
do_extend = true;
- minimum_index = _Objects_Get_index( information->minimum_id );
- index_base = minimum_index;
+ index_base = 0;
block = 0;
- /* if ( information->maximum < minimum_index ) */
if ( information->object_blocks == NULL )
block_count = 0;
else {
@@ -149,7 +146,7 @@ void _Objects_Extend_information(
* Allocate the tables and break it up.
*/
object_blocks_size = block_count * sizeof( *object_blocks );
- local_table_size = ( maximum + minimum_index ) * sizeof( *local_table );
+ local_table_size = maximum * sizeof( *local_table );
table_size = object_blocks_size
+ local_table_size
+ block_count * sizeof( *inactive_per_block );
@@ -181,7 +178,7 @@ void _Objects_Extend_information(
*/
block_count--;
- if ( information->maximum > minimum_index ) {
+ if ( information->maximum > 0 ) {
/*
* Copy each section of the table over. This has to be performed as
* separate parts as size of each block has changed.
@@ -199,15 +196,8 @@ void _Objects_Extend_information(
memcpy(
local_table,
information->local_table,
- ( information->maximum + minimum_index ) * sizeof( *local_table )
+ information->maximum * sizeof( *local_table )
);
- } else {
- /*
- * Deal with the special case of the 0 to minimum_index
- */
- for ( index = 0; index < minimum_index; index++ ) {
- local_table[ index ] = NULL;
- }
}
/*
@@ -256,7 +246,7 @@ void _Objects_Extend_information(
information->the_api,
information->the_class,
_Objects_Local_node,
- index
+ index + OBJECTS_INDEX_MINIMUM
);
_Chain_Initialize_node( &the_object->Node );
diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c
index 3e7c8e409c..cf31a5b24e 100644
--- a/cpukit/score/src/objectfree.c
+++ b/cpukit/score/src/objectfree.c
@@ -37,8 +37,7 @@ void _Objects_Free(
Objects_Maximum inactive;
objects_per_block = information->objects_per_block;
- block = _Objects_Get_index( the_object->id );
- block -= _Objects_Get_index( information->minimum_id );
+ block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
block /= objects_per_block;
++information->inactive_per_block[ block ];
diff --git a/cpukit/score/src/objectgetlocal.c b/cpukit/score/src/objectgetlocal.c
index a1a81db436..e8a109f457 100644
--- a/cpukit/score/src/objectgetlocal.c
+++ b/cpukit/score/src/objectgetlocal.c
@@ -31,22 +31,29 @@ Objects_Control *_Objects_Get(
const Objects_Information *information
)
{
- uint32_t index;
+ Objects_Id delta;
+ Objects_Id maximum_id;
+ Objects_Id end;
- index = id - information->minimum_id + 1;
+ maximum_id = information->maximum_id;
+ delta = maximum_id - id;
+ end = _Objects_Get_index( maximum_id );
- if ( information->maximum >= index ) {
+ if ( RTEMS_PREDICT_TRUE( delta < end ) ) {
+ ISR_Level level;
Objects_Control *the_object;
- _ISR_lock_ISR_disable( lock_context );
+ _ISR_Local_disable( level );
+ _ISR_lock_Context_set_level( lock_context, level );
- the_object = information->local_table[ index ];
- if ( the_object != NULL ) {
+ the_object =
+ information->local_table[ end - OBJECTS_INDEX_MINIMUM - delta ];
+ if ( RTEMS_PREDICT_TRUE( the_object != NULL ) ) {
/* ISR disabled on behalf of caller */
return the_object;
}
- _ISR_lock_ISR_enable( lock_context );
+ _ISR_Local_enable( level );
}
return NULL;
diff --git a/cpukit/score/src/objectgetnext.c b/cpukit/score/src/objectgetnext.c
index a46c02f2c2..054ed22fc1 100644
--- a/cpukit/score/src/objectgetnext.c
+++ b/cpukit/score/src/objectgetnext.c
@@ -36,7 +36,7 @@ Objects_Control *_Objects_Get_next(
return NULL;
if (_Objects_Get_index(id) == OBJECTS_ID_INITIAL_INDEX)
- next_id = information->minimum_id;
+ next_id = _Objects_Get_minimum_id( information->maximum_id );
else
next_id = id;
diff --git a/cpukit/score/src/objectgetnoprotection.c b/cpukit/score/src/objectgetnoprotection.c
index 85692234fa..e5045b26de 100644
--- a/cpukit/score/src/objectgetnoprotection.c
+++ b/cpukit/score/src/objectgetnoprotection.c
@@ -25,19 +25,16 @@ Objects_Control *_Objects_Get_no_protection(
const Objects_Information *information
)
{
- Objects_Control *the_object;
- uint32_t index;
+ Objects_Id delta;
+ Objects_Id maximum_id;
+ Objects_Id end;
- /*
- * You can't just extract the index portion or you can get tricked
- * by a value between 1 and maximum.
- */
- index = id - information->minimum_id + 1;
+ maximum_id = information->maximum_id;
+ delta = maximum_id - id;
+ end = _Objects_Get_index( maximum_id );
- if ( information->maximum >= index ) {
- if ( (the_object = information->local_table[ index ]) != NULL ) {
- return the_object;
- }
+ if ( RTEMS_PREDICT_TRUE( delta < end ) ) {
+ return information->local_table[ end - OBJECTS_INDEX_MINIMUM - delta ];
}
/*
diff --git a/cpukit/score/src/objectinitializeinformation.c b/cpukit/score/src/objectinitializeinformation.c
index a341dc1a5d..530e4e10ba 100644
--- a/cpukit/score/src/objectinitializeinformation.c
+++ b/cpukit/score/src/objectinitializeinformation.c
@@ -37,9 +37,7 @@ void _Objects_Do_initialize_information(
#endif
)
{
- static Objects_Control *null_local_table = NULL;
- uint32_t minimum_index;
- Objects_Maximum maximum_per_allocation;
+ Objects_Maximum maximum_per_allocation;
information->the_api = the_api;
information->the_class = the_class;
@@ -48,6 +46,7 @@ void _Objects_Do_initialize_information(
information->inactive_per_block = 0;
information->object_blocks = 0;
information->inactive = 0;
+ information->local_table = NULL;
/*
* Set the maximum value to 0. It will be updated when objects are
@@ -79,18 +78,6 @@ void _Objects_Do_initialize_information(
information->objects_per_block = maximum_per_allocation;
/*
- * Provide a null local table entry for the case of any empty table.
- */
- information->local_table = &null_local_table;
-
- /*
- * Calculate minimum and maximum Id's
- */
- minimum_index = (maximum_per_allocation == 0) ? 0 : 1;
- information->minimum_id =
- _Objects_Build_id( the_api, the_class, _Objects_Local_node, minimum_index );
-
- /*
* Calculate the maximum name length
*
* NOTE: Either 4 bytes for Classic API names or an arbitrary
diff --git a/cpukit/score/src/objectnametoid.c b/cpukit/score/src/objectnametoid.c
index 030d64a4bd..c3b014e3e1 100644
--- a/cpukit/score/src/objectnametoid.c
+++ b/cpukit/score/src/objectnametoid.c
@@ -29,7 +29,7 @@ Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
{
bool search_local_node;
Objects_Control *the_object;
- uint32_t index;
+ Objects_Maximum index;
#if defined(RTEMS_MULTIPROCESSING)
Objects_Name name_for_mp;
#endif
@@ -52,7 +52,7 @@ Objects_Name_or_id_lookup_errors _Objects_Name_to_id_u32(
search_local_node = true;
if ( search_local_node ) {
- for ( index = 1; index <= information->maximum; index++ ) {
+ for ( index = 0; index < information->maximum; ++index ) {
the_object = information->local_table[ index ];
if ( !the_object )
continue;
diff --git a/cpukit/score/src/objectnametoidstring.c b/cpukit/score/src/objectnametoidstring.c
index 3bca0441e0..a015d5fc25 100644
--- a/cpukit/score/src/objectnametoidstring.c
+++ b/cpukit/score/src/objectnametoidstring.c
@@ -52,7 +52,7 @@ Objects_Control *_Objects_Get_by_name(
*name_length_p = name_length;
}
- for ( index = 1; index <= information->maximum; index++ ) {
+ for ( index = 0; index < information->maximum; ++index ) {
Objects_Control *the_object;
the_object = information->local_table[ index ];
diff --git a/cpukit/score/src/objectshrinkinformation.c b/cpukit/score/src/objectshrinkinformation.c
index cf3618f8fa..3b1841a16b 100644
--- a/cpukit/score/src/objectshrinkinformation.c
+++ b/cpukit/score/src/objectshrinkinformation.c
@@ -28,9 +28,9 @@ void _Objects_Shrink_information(
)
{
Objects_Maximum objects_per_block;
- Objects_Maximum index_base;
Objects_Maximum block_count;
Objects_Maximum block;
+ Objects_Maximum index_base;
_Assert( _Objects_Allocator_is_owner() );
@@ -39,14 +39,14 @@ void _Objects_Shrink_information(
*/
objects_per_block = information->objects_per_block;
- index_base = _Objects_Get_index( information->minimum_id );
- block_count = ( information->maximum - index_base ) / objects_per_block;
+ block_count = information->maximum / objects_per_block;
+ index_base = 0;
for ( block = 0; block < block_count; block++ ) {
if ( information->inactive_per_block[ block ] == objects_per_block ) {
Chain_Node *node;
const Chain_Node *tail;
- uint32_t index_end;
+ Objects_Maximum index_end;
node = _Chain_First( &information->Inactive );
tail = _Chain_Immutable_tail( &information->Inactive );
@@ -57,7 +57,7 @@ void _Objects_Shrink_information(
uint32_t index;
object = (Objects_Control *) node;
- index = _Objects_Get_index( object->id );
+ index = _Objects_Get_index( object->id ) - OBJECTS_INDEX_MINIMUM;
/*
* Get the next node before the node is extracted
diff --git a/cpukit/score/src/threaditerate.c b/cpukit/score/src/threaditerate.c
index eff3472d57..9fa9b89166 100644
--- a/cpukit/score/src/threaditerate.c
+++ b/cpukit/score/src/threaditerate.c
@@ -39,7 +39,7 @@ void _Thread_Iterate(
continue;
}
- for ( i = 1 ; i <= information->maximum ; ++i ) {
+ for ( i = 0 ; i < information->maximum ; ++i ) {
Thread_Control *the_thread;
the_thread = (Thread_Control *) information->local_table[ i ];