URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [Unlimited.txt] - Rev 173
Compare with Previous | Blame | View Log
## $Id: Unlimited.txt,v 1.2 2001-09-27 11:59:34 chris Exp $#This document explains how the unlimited objects support works. This waswritten by Chris Johns <ccj@acm.org> of Objective Design Systems as adesign document. This was submitted as part of the patch which addedthis capability.Unlimited Local Node Objects============================1. Why ?This patch changes the way RTEMS allocates, frees, and manages the'Objects_Control' structure.The 'Objects_Control' structure is at the root of all objects inRTEMS. The RTEMS and POSIX API allows users to create tasks, messagequeues, semaphores and other resources. These are all a type ofObject. The POSIX API allow similar operations. These also map toObjects.Currently the number of objects that can be created is a static valueloaded into the Configuration table before starting the kernel. Theapplication cannot exceed these limits. Various means are used to tunethis value. During development the value is usually set large. Thissaves having to change it everytime a developer adds a newresource. With a large team of developers the configuration table filecan cycle through a large number of revisions. The wasted memory isonly recovered when memory runs short. The issue of the configurationtable parameters become more important the less memory you have.The Configuration table requires a calculation to occur at compiletime to set the size of the Workspace. The calculation is anestimate. You need to specify an overhead value for memory that cannot be calculated. An example of memory that cannot be calculated isstack sizes. This issue is not directly related to allowing unlimitedobjects how-ever the need to calculate the memory usage for a systemin this manner is prone to error.I would like to see download support added to RTEMS. The kernelconfiguration being set at boot time means a download application canbe limited. This can defeat one of the purposes of using downloadedcode, no need to change ROMs. In a system I worked on the cost tochange ROMS in a complete system was high and could take a week. Thischange is the first phase of supporting downloaded applications.1.1 How do Objects work ?All applications interact with the super core (c/src/exec/score) viaan API. The central structure used in the super core is the`object'. Two application interfaces exist. They are RTEMS andPOSIX. Both map to the super core using objects.An object in RTEMS is a resource which the user (through the API)creates. The different types of objects are referred to as classes ofobjects. An object is referenced by an id. This is of type `rtems_id'and is a 32bit unsigned integer. The id is unique for each object nomatter what class.Objects are anchored by the `_Object_Information' structure. There isone per type or class of object. A global table of pointers to eachinformation structure for a class of objects is held in`Objects_Information_table'.Objects consist of 6 main structures. The `_Object_Information' is theroot structure. It contains pointers to the `local_table',`name_table', `global_table', the Inactive chain, and the objectmemory. It also contains the various variables which describe theobject. We are only concerned with the `local_table', `name_table',Inactive chain, and the object memory to support unlimited objects.The `local_table' holds the pointers to open objects. A `local_tableentry which is null is free and the object will be sitting on theInactive chain. The index into the table is based on part of theid. Given an id the you can find the index into the `local_table', andtherefore the object. The `local_table' has the entries for theindexes below the minimum_id's index. The minimum_id is always set to1 (the change allows another value to be selected if require). Theindex of 0 is reserved and never used. This allows any actions usingan id of zero to fail or map to a special case.The `name_table' holds the names of the objects. Each entry in thistable is the maximum size the name of the object can be. The size ofnames is not constrained by the object code (but is by the MP objectcode, and the API and should be fixed).The `global_table' and code that uses it has not changed. I did notlook at the this code, and I am not farmilar with it.The Inactive chain stores objects which are free or notallocated. This design saves searching for a free object whenallocating therefore providing a deterministic allocation scheme. Whenthe chain is empty a null is returned.The change documented below basically extends the `local_table' and`name_table' structures at run-time. The memory used be these tableis not large compared to the memory for the objects, and so are neverreduced in size once extended. The object's memory grows and shrinksdepending of the user's usage.Currently, the user specifies the total number of objects in theConfiguration table. The change alters the function of the values inthe Configuration table. A flag can be masked on to the value whichselects the extending mode. If the user does not set the flag theobject code operates with an object ceiling. A small performanceoverhead will be incurred as the allocate and free routines are nownot inlined and a check of the auto_extend flag is made. The remainingvalue field of the Configuration table entry is total number ofobjects that can be allocated when not in unlimited mode.If the user masks the flag on to a value on the Configuration tableauto-exdending mode is selected for that class of object. The valuebecomes the allocation unit size. If there are no free objects theobject's tables are extended by the allocation unit number ofobjects. The object table is shrunk when the user frees objects. Thetable must have one free allocation block, and at least half theallocation size of another block before the object memory of the freeallocation block is returned to the heap. This stops thresholdthrashing when objects around the allocation unit size and created anddestroyed.At least one allocation block size of objects is created and neverdestroyed.The change to support unlimited objects has extended the objectinformation structure.The flag, `auto_extend' controls if the object can be automaticallyextended. The user masks the flag RTEMS_UNLIMITED_FLAGS onto theConfiguration table number to select the auto-extend mode. This ispassed to the `_Objects_Initialize_information' function in theparameter maximum. The flag is tested for and the auto_extend flagupdated to reflect the state of the flag before being stipped from themaximum.The `allocation_size' is set to the parameter maxium in the function`_Objects_Initialize_information' if `auto_extend' is true. Making theallocation size small causes the memory to be allocated and freed moreoften. This only effects the performance times for creating a resourcesuch as a task. It does how-ever give you fine grain memorycontrol. If the performance of creating resources is not a problemmake the size small.The size of the object is required to be stored. It is used whenextending the object information.A count of the object on the Inactive list is maintained. This is usedduring freeing objects. If the count is above 1.5 times the`allocation_size' an attempt is made to shrink the objectinformtation. Shrinking might not always succeed as a singleallocation block might not be free. Random freeing of objects canresult in some fragmentation. Any further allocations will use thefree objects before extending the object's information tables.A table of inactive objects per block is maintained. This table, likethe `local_table' and `name_table' grows as more blocks areallocated. A check is made of a blocks inactive count when an objectwhich is part of that block is freed. If the total inactive countexceeds 1.5 times the allocation size, and the block's inactive countis the allocation_size, the objects data block is returnd to theworkspace heap.The `objects_blocks' is a table of pointers. The object_block's pointerspoint to the object's data block. The object's data block is a singleallocation of the name space and object space. This was two separateallocations but is now one. The objects_block's table is use todetermine if a block is allocated, and the address of the memory blockto be returned to the workspace heap when the object informtationspace is shrunk.2.0 Detail Of the Auto-Extend Patch to rtems-4.0.0, Snapshot 19990302o Configuration table support.Added a flag OBJECTS_UNLIMITED_OBJECTS to score/headers/object.hheader file. This is referenced in the file sapi/headers/config.h tocreate the flag RTEMS_UNLIMITED_OBJECTS. A macro is provided to takea resource count and apply the flag. The macro is called`rtems_resource_unlimited'. The user uses this macro when building aconfiguration table. It can be used with the condefs.h header file.o Object Information StructureThe object information structure, Objects_Information, has beenextended with the follow fields :boolean auto_extend -When true the object's information tables can be extended untillall memory is used. When false the current functionallity ismaintained.unsigned32 allocation_size -When auto_extend is true, it is the value in the Configurationtable and is the number of objects the object's informationtables are extended or shrunk.unsigned32 size -The size of the object. It is used to calculate the size ofmemory required to be allocated when extending the table.unsigned32 inactive -The number of elements on the Inactive chain.unsigned32 *inactive_per_block -Pointer to a table of counts of the inactive objects from ablock on the Inactive chain. It is used to know which blocks areall free and therefore can be returned to the heap.void **object_blocks -Pointer to a table of pointers to the object data. The tableholds the pointer used to return a block to the heap whenshrinking the object's information tables.o Changes to Existing Object FunctionsTwo functions prototypes are added. They are :_Objects_Extend_information,_Objects_Shrink_information_Object_Allocate, and_Object_FreeThe last were inlined, how-ever now they are not as they are toocomplex to implement as macros now.o Object Inline and Macro ChangesThe functions :_Object_Allocate, and_Object_Freeare now not inlined. The function :_Objects_Get_local_object, and_Objects_Set_local_objecthave been added. There was no provided interface to allow an API toget/set an objects local pointer given an index. The POSIX codeshould be updated to use this interface.The function :_Objects_Get_informationhas been moved to be an inline function. It is used in the getobject call which the API uses for every object reference.o Object InitialisationThe function _Objects_Initialize_information has been changed toinitialisation of the information structure's fields then call thenew function _Objects_Extend_information.The first block of objects is always allocated and neverreleased. This means with the auto-extend flag set to true the userstill sees the same behaviour expected without this change. That isthe number objects specified in the Configuration table is thenumber of object allocated during RTEMS initialisation. If notenough memory is found during this initial extend a fatal erroroccurs. The fatal error only occurs for this case of extending theobject's information tables.o Object Information ExtendThe _Object_Information_Extend is a new function. It takes some ofthe code form the old _Object_Initialize_information function. Thefunction extends an object's information base.Extending the first time is a special case. The function assumes themaximum index will be less than the minimum index. This means theminimum index must be greater than 0 at initialisation. The otherspecial case made is coping the tables from the old location to thenew location. The first block case is trapped and tables areinitialised instead. Workspace allocation for the first block istested for an if the first block the allocate or fatal error call ismade. This traps an RTEMS initialise allocation error.The remainder of the code deals with all cases of extending theobject's information.The current block count is first determined, then a scan of theobject_block table is made to locate a free slot. Blocks can befreed in any order. The index base for the block is also determined.If the index base is greater than the maximum index, the tables mustgrow. To grow the tables, a new larger memory block is allocated andthe tables copied. The object's information structure is thenupdated to point to the new tables. The tables are allocated in onememory block from the work-space heap. The single block is thenbroken down in the required tables.Once the tables are copied, and the new extended parts initialisedthe table pointers in the object's information structure areupdated. This is protected by masking interrupts.The old table's memory block is returned to the heap.The names table and object is allocated. This again is a singleblock which is divided.The objects are initialised onto a local Inactive chain. They arethen copied to the object's Inactive chain to complete theinitialisation.o Object Informtation ShrinkThe _Object_Shrink_information function is new. It is required toscan all the blocks to see which one has no objects allocated. Thelast object freed might not belong to a block which is completelyfree.Once a block is located, the Inactive chain is interated downlooking for objects which belong to the block of object beingreleased.Once the Inactive chain scan is complete the names table and objectmemory is returned to the work-space heap and the table references cleared.XXX - I am not sure if this should occur if better protection ordifferent code to provide better protection.The information tables do not change size. Once extended they nevershrink.o Object AllocationThe _Objects_Allocate attempts to get an object from the Inactivechain. If auto-extend mode is not enabled no further processingoccurs. The extra overhead for this implemetation is the function isnot inlined and check of a boolean occurs. It should effect thetiming figures.If auto-extend is enabled, a further check is made to see if the getfrom the Inactive chain suceeded in getting an object. If it faileda call is made to extend the object's information tables.The get from the Inactive chain is retried. The result of this isreturned to the user. A failure here is the users problem.o Object FreeThe _Objects_Free puts the object back onto the Inactivechain. Again if auto-extend mode is not enabled no furtherprocessing occurs and performance overhead will low.If auto-extend mode is enabled, a check is to see if the number ofInactive objects is one and a half times the allocation size. Ifthere are that many free objects an attempt is made to shrink theobject's information.o Object Index and the Get FunctionThe existing code allocates the number of object specified in theconfiguration table, how-ever it makes the local_table have one moreelement. This is the slot for an id of 0. The 0 slot is always aNULL providing a simple check for a 0 id for object classes.The existing _Objects_Get code removes the minimum id, which I thinkcould only be 1 from the index, then adds one for the 0 slot.This change removes this index adjustment code in _Objects_Get.The extend information starts the index count when scanning for freeblocks at the minumun index. This means the base index for a blockwill always be adjusted by the minimum index. The extend informationfunction only ever allocates the allocation size ofobjects. Finially the object's local_table size is the maximum plusthe minumum index size. The maximum is really the maximum index.This means the values in the object's information structure andtables do not need the index adjustments which existed before.o The TestA new sample test, unlimited is provided. It attempts to test thischange.
