storage allocation for embedded processors
DESCRIPTION
Storage Allocation for Embedded Processors. By Jan Sjodin & Carl von Platen Present by Xie Lei ( PLS Lab). Memory In Embedded Sys. Several memory areas (on-chip, off-chip) SRAM DRAM E 2 PROM … Different properties - PowerPoint PPT PresentationTRANSCRIPT
Storage Allocation Storage Allocation for for
Embedded Embedded ProcessorsProcessors
By Jan Sjodin & Carl von Platen
Present by Xie Lei ( PLS Lab)
Memory In Embedded Memory In Embedded SysSys
Several memory areas (on-chip, off-chip)Several memory areas (on-chip, off-chip)
SRAMSRAM
DRAMDRAM
EE22PROMPROM …… Different propertiesDifferent properties
access time access time
sizesize
restricted to native pointer types restricted to native pointer types
Pointer TypesPointer Types
Different in lengthDifferent in length
8-bit8-bit
16-bit . . .16-bit . . . Different in cost Different in cost
8-bit is cheaper than 16-bit8-bit is cheaper than 16-bit
Problem to solveProblem to solve
Allocate data and select pointer Allocate data and select pointer types in the most efficient way types in the most efficient way
Frequently accessed data in fast Frequently accessed data in fast memorymemory
Frequently used pointers & Frequently used pointers & expression have cheap pointer typeexpression have cheap pointer type
Manual Manual Automatic Automatic
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiments & ResultsExperiments & Results ConclusionConclusion
Why Allocation ?Why Allocation ?
Different pointer types to access Different pointer types to access different types of memories different types of memories improves performance :improves performance :
execution speedexecution speed program sizeprogram size energy consumptionenergy consumption production cost . . .production cost . . .
Allocation ProblemAllocation Problem
Allocating each variable of a program Allocating each variable of a program in a memory segmentin a memory segment
Assigning a native pointer type to each Assigning a native pointer type to each pointer expression of the same programpointer expression of the same program
Dependency : latter depends on former Dependency : latter depends on former
---take both into consider ---take both into consider simultaneouslysimultaneously
Current solution & Current solution & DrawbackDrawback
Manually locate variables and select Manually locate variables and select native pointer types: pragmas or native pointer types: pragmas or keywordskeywords
DrawbacksDrawbacks
time-consuming time-consuming
source code non-portablesource code non-portable
New SolutionNew Solution
A model which can describe A model which can describe architectures with irregular memory architectures with irregular memory organization and several pointer organization and several pointer types.types.
Derive integer linear program from Derive integer linear program from the modelthe model
Solve the program = Solve the Solve the program = Solve the allocation problemallocation problem
Optimal solution ( under assumption )Optimal solution ( under assumption )
An Important ConditionAn Important Condition
Condition : All memory accesses in the Condition : All memory accesses in the program should be known program should be known
-- whole program optimization -- whole program optimization ( WPO )( WPO )
points-to set points-to set :: Set of the objects a Set of the objects a restricted pointer may point torestricted pointer may point to
Reason Reason
The The points-to set points-to set of a pointer must be of a pointer must be allocated where that pointer can reachallocated where that pointer can reach
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiment & ResultsExperiment & Results ConclusionConclusion
Features in Embedded Features in Embedded ProcessorsProcessors
On-chip memory : efficientlyOn-chip memory : efficiently Zero page : use smaller pointer Zero page : use smaller pointer
types , fast , compact codetypes , fast , compact code Harvard architectures : different Harvard architectures : different
native pointer representations and native pointer representations and addressing mode are used for addressing mode are used for program and data address spaceprogram and data address space
Separate VS Single address Separate VS Single address space (1)space (1)
Separate address spaceSeparate address space
disjoint sets of pointer typesdisjoint sets of pointer types know points-to sets to allocate dataknow points-to sets to allocate data use separate address busesuse separate address buses different memory access instructions different memory access instructions
use different pointer types as operandsuse different pointer types as operands
Separate VS Single address Separate VS Single address space (2)space (2)
Single address spaceSingle address space
A general native pointer typeA general native pointer type No restriction on allocationNo restriction on allocation Try to use cheaper pointer Try to use cheaper pointer type ( need to know the point-to type ( need to know the point-to set to decide if that pointer type set to decide if that pointer type can work)can work)
An Abstract Memory An Abstract Memory ModelModel
Memory Model : Memory Segments, Memory Model : Memory Segments, Pointer Types , RelationPointer Types , Relation
Memory Segments : subsets of the total Memory Segments : subsets of the total memory space, uniform with memory space, uniform with properties( speed, addressing modes). properties( speed, addressing modes). MM1 1 , M, M2 2 , M, M3 3 . . . M. . . MS S
Pointer Types : PPointer Types : P1 1 ,, PP2 2 ,, PP3 3 . . . P. . . PT T
Relation : Pointer Type to Memory Relation : Pointer Type to Memory SegmentsSegments
Memory ModelMemory Model
SizeSize( M( Mjj ) : number of addressable ) : number of addressable units of storage in Memory Segment Munits of storage in Memory Segment Mj j
Relation function Relation function
Mem( PMem( Pk k )={ )={ jj | P | Pk k can point to M can point to Mj j }}
In which In which PPk k Pointer Type Pointer Type Memory Model can be expressed by a Memory Model can be expressed by a
tabletable
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiment & ResultsExperiment & Results ConclusionConclusion
Two Kinds of CostTwo Kinds of Cost
Cost : Static cost + Dynamic costCost : Static cost + Dynamic cost Static cost : the size of a program, Static cost : the size of a program,
expressed by the sum of all expressed by the sum of all statements in instruction set STMTR statements in instruction set STMTR
Dynamic cost : execution time, for Dynamic cost : execution time, for each statement need to be scaled by each statement need to be scaled by the estimate execution frequency of the estimate execution frequency of the statement the statement
ExpressionsExpressions
V = {vV = {v1 1 , v, v2 2 . . . v. . . vN N } : set of variables } : set of variables referred to in the source program referred to in the source program
SizeSize(v) : number of allocation units (v) : number of allocation units required by vrequired by v
STMTR : set of individual STMTR : set of individual occurrences of instructions occurrences of instructions
E = {eE = {e1 1 , e, e2 2 . . . e. . . eMM } : set of pointer } : set of pointer expressionsexpressions
FunctionsFunctions
PtrExp PtrExp : STMTR : STMTR E E
allow the client of the allow the client of the storage allocator to modify the type of storage allocator to modify the type of single pointer expressions single pointer expressions independentlyindependently
Seg(v) Seg(v) : V: V M , the segment where a M , the segment where a variable is allocatedvariable is allocated
PtrT(e) PtrT(e) : E: EP, the pointer type a P, the pointer type a pointer expression is assigned pointer expression is assigned
Cost of A Statement ( 1 )Cost of A Statement ( 1 )
For each statement in STMTR , we can For each statement in STMTR , we can have pointer cost and variable costhave pointer cost and variable cost
ptrcostptrcostS S ( e, t ) : pointer cost , the cost ( e, t ) : pointer cost , the cost contribution of selecting “ t ” as the contribution of selecting “ t ” as the pointer type for pointer expression “ e ”pointer type for pointer expression “ e ”
varcostvarcostS S ( v, m ) : variable cost , the cost ( v, m ) : variable cost , the cost contribution of variable “ v ” if it is contribution of variable “ v ” if it is located in memory segment “ m ” located in memory segment “ m ”
Cost of A Statement ( 2 )Cost of A Statement ( 2 )
The cost of a particular solution is The cost of a particular solution is defined in terms of the cost defined in terms of the cost contribution of each statement in contribution of each statement in STMTR STMTR
Cost(S) = Cost(S) = ∑ ∑ (e(eE)E) ptrcostptrcostS S ( e, ( e, PtrTPtrT (e) )(e) )
+ + ∑ ∑ (v(vV)V) varcostvarcostS S ( v, ( v, SegSeg(v) ) (v) )
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiment & ResultsExperiment & Results ConclusionConclusion
BIP FormulationBIP Formulation
BIP : Binary Integer ProgramBIP : Binary Integer Program The storage allocation problem is The storage allocation problem is
formulated as a BIPformulated as a BIP Based on the model of Memory Based on the model of Memory
Organization and the cost model Organization and the cost model
Feasible SolutionFeasible Solution
Two condition must be satisfiedTwo condition must be satisfied Total size of the variables in a single Total size of the variables in a single
memory segment ≤ size of the segmentmemory segment ≤ size of the segment Pointer expression that may point to a Pointer expression that may point to a
variable must be assigned a type that variable must be assigned a type that can access the segment where that can access the segment where that variable isvariable is
Find a feasible solution with minimal Find a feasible solution with minimal cost !cost !
BIP ( 1 )BIP ( 1 )
Each variable can be placed in exactly one Each variable can be placed in exactly one memory segmentmemory segment
xxi1i1+ x+ xi2 i2 . . . + x. . . + xiSiS=1 , 1 ≤ i ≤ N=1 , 1 ≤ i ≤ N Total size of the variables in a segment can Total size of the variables in a segment can
not be greater than the size of the segmentnot be greater than the size of the segment
SizeSize(v(v11) x) x1m1m+ + SizeSize(v(v22) x) x2m2m+ . . . + + . . . + SizeSize(v(vNN) x) xNmNm
≤ ≤ SizeSize(M(Mmm) , 1 ≤ m ≤ S) , 1 ≤ m ≤ S
BIP ( 2 )BIP ( 2 )
Each pointer expression have a Each pointer expression have a unique pointer typeunique pointer type
yyj1j1+ y+ yj2 j2 . . . + y. . . + yjT jT = 1 , 1 ≤ j≤ M= 1 , 1 ≤ j≤ M Type of a pointer expression be Type of a pointer expression be
general enough for all the variables general enough for all the variables in its points-to setin its points-to set
SegSeg(v) (v) Mem Mem ( ( PtrTPtrT( e( ej j ) ) , v ) ) , v Pt Pt ( e( ej j ) )
BIP ( 3 )BIP ( 3 )
Objective function is the cost of the Objective function is the cost of the solutionsolution
Discussion : ScalabilityDiscussion : Scalability
Number of variables and number of Number of variables and number of pointer expressions grow linearly in pointer expressions grow linearly in the size of the programthe size of the program
Number of memory segments and Number of memory segments and the number of pointer types depend the number of pointer types depend on target architecture , so can be on target architecture , so can be regarded as constantsregarded as constants
Discussion : AccuracyDiscussion : Accuracy
Fundamental to the model : cost of a Fundamental to the model : cost of a statement can be expressed as statement can be expressed as linear combination of cost from linear combination of cost from variables and pointer expressions ---- variables and pointer expressions ---- Not preciseNot precise
Some architectures may represent Some architectures may represent pointers with multiple machine pointers with multiple machine words, so loading a pointer need words, so loading a pointer need several instructionsseveral instructions
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiment & ResultsExperiment & Results ConclusionConclusion
WPO PrototypeWPO Prototype
Points-to analysisPoints-to analysis
estimate the points-to set of each estimate the points-to set of each pointerpointer
ILP solverILP solver
Information about all global Information about all global variables and pointers is put into the variables and pointers is put into the solver to get an allocationsolver to get an allocation
Modified ICCAVRModified ICCAVR
Compile the C source code and use Compile the C source code and use the allocation information by WPO to the allocation information by WPO to modify the memory attributes of modify the memory attributes of variablesvariables
Allocation information is used during Allocation information is used during the parsing stage to modify the the parsing stage to modify the memory attributes of variablesmemory attributes of variables
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiments & ResultsExperiments & Results ConclusionConclusion
ExperimentsExperiments
Measure the execution time and Measure the execution time and code size of 6 benchmarkscode size of 6 benchmarks
Results are compared with code Results are compared with code compiled on the standard ICCAR compiled on the standard ICCAR compilercompiler
Different version of AVR Different version of AVR microcontroller , internal memory microcontroller , internal memory vary from 0 to 4KB or more ( 64KB vary from 0 to 4KB or more ( 64KB and 16KB)and 16KB)
ResultsResults
Results vary a lot with benchmarks Results vary a lot with benchmarks
CPU intensive or Memory CPU intensive or Memory intensiveintensive
Code size decreased slightly for most Code size decreased slightly for most benchmarks ( Special : statemate )benchmarks ( Special : statemate )
Execution time improved for most Execution time improved for most benchmarks( also Statemate ) benchmarks( also Statemate )
Road MapRoad Map
Brief BackgroundBrief Background Memory Organization & ModelMemory Organization & Model Cost ModelCost Model Formulation & DiscussionFormulation & Discussion ImplementationImplementation Experiments & ResultsExperiments & Results ConclusionConclusion
ConclusionConclusion
Model of memory hierarchies for storage Model of memory hierarchies for storage allocation for embedded system allocation for embedded system processorsprocessors
Implement a memory allocator using ILP Implement a memory allocator using ILP to get an optimal allocation under the to get an optimal allocation under the memory modelmemory model
Improve program size and speedImprove program size and speed Automatically done , portable , robust : Automatically done , portable , robust :
no need to include target-specific no need to include target-specific information in source codeinformation in source code