Warning, /cpukit/score/src/README.md is written in an unsupported language. File is not indexed.
0001 Unlimited Local Node Objects
0002 ============================
0003
0004 This document explains how the unlimited objects support works. This was
0005 written by Chris Johns <ccj@acm.org> of Objective Design Systems as a
0006 design document. This was submitted as part of the patch which added
0007 this capability.
0008
0009
0010 1. Why ?
0011
0012 This patch changes the way RTEMS allocates, frees, and manages the
0013 'Objects_Control' structure.
0014
0015 The 'Objects_Control' structure is at the root of all objects in
0016 RTEMS. The RTEMS and POSIX API allows users to create tasks, message
0017 queues, semaphores and other resources. These are all a type of
0018 Object. The POSIX API allow similar operations. These also map to
0019 Objects.
0020
0021 Currently the number of objects that can be created is a static value
0022 loaded into the Configuration table before starting the kernel. The
0023 application cannot exceed these limits. Various means are used to tune
0024 this value. During development the value is usually set large. This
0025 saves having to change it everytime a developer adds a new
0026 resource. With a large team of developers the configuration table file
0027 can cycle through a large number of revisions. The wasted memory is
0028 only recovered when memory runs short. The issue of the configuration
0029 table parameters become more important the less memory you have.
0030
0031 The Configuration table requires a calculation to occur at compile
0032 time to set the size of the Workspace. The calculation is an
0033 estimate. You need to specify an overhead value for memory that can
0034 not be calculated. An example of memory that cannot be calculated is
0035 stack sizes. This issue is not directly related to allowing unlimited
0036 objects how-ever the need to calculate the memory usage for a system
0037 in this manner is prone to error.
0038
0039 I would like to see download support added to RTEMS. The kernel
0040 configuration being set at boot time means a download application can
0041 be limited. This can defeat one of the purposes of using downloaded
0042 code, no need to change ROMs. In a system I worked on the cost to
0043 change ROMS in a complete system was high and could take a week. This
0044 change is the first phase of supporting downloaded applications.
0045
0046 1.1 How do Objects work ?
0047
0048 All applications interact with the super core (c/src/exec/score) via
0049 an API. The central structure used in the super core is the
0050 `object'. Two application interfaces exist. They are RTEMS and
0051 POSIX. Both map to the super core using objects.
0052
0053 An object in RTEMS is a resource which the user (through the API)
0054 creates. The different types of objects are referred to as classes of
0055 objects. An object is referenced by an id. This is of type `rtems_id'
0056 and is a 32bit unsigned integer. The id is unique for each object no
0057 matter what class.
0058
0059 Objects are anchored by the `_Object_Information' structure. There is
0060 one per type or class of object. A global table of pointers to each
0061 information structure for a class of objects is held in
0062 `Objects_Information_table'.
0063
0064 Objects consist of 6 main structures. The `_Object_Information' is the
0065 root structure. It contains pointers to the `local_table',
0066 `name_table', `global_table', the Inactive chain, and the object
0067 memory. It also contains the various variables which describe the
0068 object. We are only concerned with the `local_table', `name_table',
0069 Inactive chain, and the object memory to support unlimited objects.
0070
0071 The `local_table' holds the pointers to open objects. A `local_table
0072 entry which is null is free and the object will be sitting on the
0073 Inactive chain. The index into the table is based on part of the
0074 id. Given an id the you can find the index into the `local_table', and
0075 therefore the object. The `local_table' has the entries for the
0076 indexes below the minimum_id's index. The minimum_id is always set to
0077 1 (the change allows another value to be selected if require). The
0078 index of 0 is reserved and never used. This allows any actions using
0079 an id of zero to fail or map to a special case.
0080
0081 The `name_table' holds the names of the objects. Each entry in this
0082 table is the maximum size the name of the object can be. The size of
0083 names is not constrained by the object code (but is by the MP object
0084 code, and the API and should be fixed).
0085
0086 The `global_table' and code that uses it has not changed. I did not
0087 look at the this code, and I am not farmilar with it.
0088
0089 The Inactive chain stores objects which are free or not
0090 allocated. This design saves searching for a free object when
0091 allocating therefore providing a deterministic allocation scheme. When
0092 the chain is empty a null is returned.
0093
0094 The change documented below basically extends the `local_table' and
0095 `name_table' structures at run-time. The memory used be these table
0096 is not large compared to the memory for the objects, and so are never
0097 reduced in size once extended. The object's memory grows and shrinks
0098 depending of the user's usage.
0099
0100 Currently, the user specifies the total number of objects in the
0101 Configuration table. The change alters the function of the values in
0102 the Configuration table. A flag can be masked on to the value which
0103 selects the extending mode. If the user does not set the flag the
0104 object code operates with an object ceiling. A small performance
0105 overhead will be incurred as the allocate and free routines are now
0106 not inlined and a check of the auto_extend flag is made. The remaining
0107 value field of the Configuration table entry is total number of
0108 objects that can be allocated when not in unlimited mode.
0109
0110 If the user masks the flag on to a value on the Configuration table
0111 auto-exdending mode is selected for that class of object. The value
0112 becomes the allocation unit size. If there are no free objects the
0113 object's tables are extended by the allocation unit number of
0114 objects. The object table is shrunk when the user frees objects. The
0115 table must have one free allocation block, and at least half the
0116 allocation size of another block before the object memory of the free
0117 allocation block is returned to the heap. This stops threshold
0118 thrashing when objects around the allocation unit size and created and
0119 destroyed.
0120
0121 At least one allocation block size of objects is created and never
0122 destroyed.
0123
0124 The change to support unlimited objects has extended the object
0125 information structure.
0126
0127 The flag, `auto_extend' controls if the object can be automatically
0128 extended. The user masks the flag RTEMS_UNLIMITED_FLAGS onto the
0129 Configuration table number to select the auto-extend mode. This is
0130 passed to the `_Objects_Initialize_information' function in the
0131 parameter maximum. The flag is tested for and the auto_extend flag
0132 updated to reflect the state of the flag before being stipped from the
0133 maximum.
0134
0135 The `allocation_size' is set to the parameter maxium in the function
0136 `_Objects_Initialize_information' if `auto_extend' is true. Making the
0137 allocation size small causes the memory to be allocated and freed more
0138 often. This only effects the performance times for creating a resource
0139 such as a task. It does how-ever give you fine grain memory
0140 control. If the performance of creating resources is not a problem
0141 make the size small.
0142
0143 The size of the object is required to be stored. It is used when
0144 extending the object information.
0145
0146 A count of the object on the Inactive list is maintained. This is used
0147 during freeing objects. If the count is above 1.5 times the
0148 `allocation_size' an attempt is made to shrink the object
0149 informtation. Shrinking might not always succeed as a single
0150 allocation block might not be free. Random freeing of objects can
0151 result in some fragmentation. Any further allocations will use the
0152 free objects before extending the object's information tables.
0153
0154 A table of inactive objects per block is maintained. This table, like
0155 the `local_table' and `name_table' grows as more blocks are
0156 allocated. A check is made of a blocks inactive count when an object
0157 which is part of that block is freed. If the total inactive count
0158 exceeds 1.5 times the allocation size, and the block's inactive count
0159 is the allocation_size, the objects data block is returnd to the
0160 workspace heap.
0161
0162 The `objects_blocks' is a table of pointers. The object_block's pointers
0163 point to the object's data block. The object's data block is a single
0164 allocation of the name space and object space. This was two separate
0165 allocations but is now one. The objects_block's table is use to
0166 determine if a block is allocated, and the address of the memory block
0167 to be returned to the workspace heap when the object informtation
0168 space is shrunk.
0169
0170 2.0 Detail Of the Auto-Extend Patch to rtems-4.0.0, Snapshot 19990302
0171
0172 o Configuration table support.
0173
0174 Added a flag OBJECTS_UNLIMITED_OBJECTS to score/headers/object.h
0175 header file. This is referenced in the file sapi/headers/config.h to
0176 create the flag RTEMS_UNLIMITED_OBJECTS. A macro is provided to take
0177 a resource count and apply the flag. The macro is called
0178 `rtems_resource_unlimited'. The user uses this macro when building a
0179 configuration table. It can be used with the condefs.h header file.
0180
0181 o Object Information Structure
0182
0183 The object information structure, Objects_Information, has been
0184 extended with the follow fields :
0185
0186 boolean auto_extend -
0187
0188 When true the object's information tables can be extended untill
0189 all memory is used. When false the current functionallity is
0190 maintained.
0191
0192 uint32_t allocation_size -
0193
0194 When auto_extend is true, it is the value in the Configuration
0195 table and is the number of objects the object's information
0196 tables are extended or shrunk.
0197
0198 uint32_t size -
0199
0200 The size of the object. It is used to calculate the size of
0201 memory required to be allocated when extending the table.
0202
0203 uint32_t inactive -
0204
0205 The number of elements on the Inactive chain.
0206
0207 uint32_t *inactive_per_block -
0208
0209 Pointer to a table of counts of the inactive objects from a
0210 block on the Inactive chain. It is used to know which blocks are
0211 all free and therefore can be returned to the heap.
0212
0213 void **object_blocks -
0214
0215 Pointer to a table of pointers to the object data. The table
0216 holds the pointer used to return a block to the heap when
0217 shrinking the object's information tables.
0218
0219 o Changes to Existing Object Functions
0220
0221 Two functions prototypes are added. They are :
0222
0223 _Objects_Extend_information,
0224 _Objects_Shrink_information
0225 _Object_Allocate, and
0226 _Object_Free
0227
0228 The last were inlined, how-ever now they are not as they are too
0229 complex to implement as macros now.
0230
0231 o Object Initialisation
0232
0233 The function _Objects_Initialize_information has been changed to
0234 initialisation of the information structure's fields then call the
0235 new function _Objects_Extend_information.
0236
0237 The first block of objects is always allocated and never
0238 released. This means with the auto-extend flag set to true the user
0239 still sees the same behaviour expected without this change. That is
0240 the number objects specified in the Configuration table is the
0241 number of object allocated during RTEMS initialisation. If not
0242 enough memory is found during this initial extend a fatal error
0243 occurs. The fatal error only occurs for this case of extending the
0244 object's information tables.
0245
0246 o Object Information Extend
0247
0248 The _Object_Information_Extend is a new function. It takes some of
0249 the code form the old _Object_Initialize_information function. The
0250 function extends an object's information base.
0251
0252 Extending the first time is a special case. The function assumes the
0253 maximum index will be less than the minimum index. This means the
0254 minimum index must be greater than 0 at initialisation. The other
0255 special case made is coping the tables from the old location to the
0256 new location. The first block case is trapped and tables are
0257 initialised instead. Workspace allocation for the first block is
0258 tested for an if the first block the allocate or fatal error call is
0259 made. This traps an RTEMS initialise allocation error.
0260
0261 The remainder of the code deals with all cases of extending the
0262 object's information.
0263
0264 The current block count is first determined, then a scan of the
0265 object_block table is made to locate a free slot. Blocks can be
0266 freed in any order. The index base for the block is also determined.
0267
0268 If the index base is greater than the maximum index, the tables must
0269 grow. To grow the tables, a new larger memory block is allocated and
0270 the tables copied. The object's information structure is then
0271 updated to point to the new tables. The tables are allocated in one
0272 memory block from the work-space heap. The single block is then
0273 broken down in the required tables.
0274
0275 Once the tables are copied, and the new extended parts initialised
0276 the table pointers in the object's information structure are
0277 updated. This is protected by masking interrupts.
0278
0279 The old table's memory block is returned to the heap.
0280
0281 The names table and object is allocated. This again is a single
0282 block which is divided.
0283
0284 The objects are initialised onto a local Inactive chain. They are
0285 then copied to the object's Inactive chain to complete the
0286 initialisation.
0287
0288 o Object Informtation Shrink
0289
0290 The _Object_Shrink_information function is new. It is required to
0291 scan all the blocks to see which one has no objects allocated. The
0292 last object freed might not belong to a block which is completely
0293 free.
0294
0295 Once a block is located, the Inactive chain is interated down
0296 looking for objects which belong to the block of object being
0297 released.
0298
0299 Once the Inactive chain scan is complete the names table and object
0300 memory is returned to the work-space heap and the table references cleared.
0301
0302 XXX - I am not sure if this should occur if better protection or
0303 different code to provide better protection.
0304
0305 The information tables do not change size. Once extended they never
0306 shrink.
0307
0308 o Object Allocation
0309
0310 The _Objects_Allocate attempts to get an object from the Inactive
0311 chain. If auto-extend mode is not enabled no further processing
0312 occurs. The extra overhead for this implemetation is the function is
0313 not inlined and check of a boolean occurs. It should effect the
0314 timing figures.
0315
0316 If auto-extend is enabled, a further check is made to see if the get
0317 from the Inactive chain suceeded in getting an object. If it failed
0318 a call is made to extend the object's information tables.
0319
0320 The get from the Inactive chain is retried. The result of this is
0321 returned to the user. A failure here is the users problem.
0322
0323 o Object Free
0324
0325 The _Objects_Free puts the object back onto the Inactive
0326 chain. Again if auto-extend mode is not enabled no further
0327 processing occurs and performance overhead will low.
0328
0329 If auto-extend mode is enabled, a check is to see if the number of
0330 Inactive objects is one and a half times the allocation size. If
0331 there are that many free objects an attempt is made to shrink the
0332 object's information.
0333
0334 o Object Index and the Get Function
0335
0336 The existing code allocates the number of object specified in the
0337 configuration table, how-ever it makes the local_table have one more
0338 element. This is the slot for an id of 0. The 0 slot is always a
0339 NULL providing a simple check for a 0 id for object classes.
0340
0341 The existing _Objects_Get code removes the minimum id, which I think
0342 could only be 1 from the index, then adds one for the 0 slot.
0343
0344 This change removes this index adjustment code in _Objects_Get.
0345
0346 The extend information starts the index count when scanning for free
0347 blocks at the minumun index. This means the base index for a block
0348 will always be adjusted by the minimum index. The extend information
0349 function only ever allocates the allocation size of
0350 objects. Finially the object's local_table size is the maximum plus
0351 the minumum index size. The maximum is really the maximum index.
0352
0353 This means the values in the object's information structure and
0354 tables do not need the index adjustments which existed before.
0355
0356 o The Test
0357
0358 A new sample test, unlimited is provided. It attempts to test this
0359 change.