430 likes | 546 Views
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
E N D
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 E2PROM… • Different properties access time size restricted to native pointer types
Pointer Types • Different in length 8-bit 16-bit . . . • Different in cost 8-bit is cheaper than 16-bit
Problem to solve • Allocate data and select pointer types in the most efficient way • Frequently accessed data in fast memory • Frequently used pointers & expression have cheap pointer type • Manual Automatic
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion
Why Allocation ? Different pointer types to access different types of memories improves performance : • execution speed • program size • energy consumption • production cost . . .
Allocation Problem • Allocating each variable of a program in a memory segment • Assigning a native pointer type to each pointer expression of the same program • Dependency : latter depends on former ---take both into consider simultaneously
Current solution & Drawback • Manually locate variables and select native pointer types: pragmas or keywords • Drawbacks time-consuming source code non-portable
New Solution • A model which can describe architectures with irregular memory organization and several pointer types. • Derive integer linear program from the model • Solve the program = Solve the allocation problem • Optimal solution ( under assumption )
An Important Condition • Condition : All memory accesses in the program should be known -- whole program optimization ( WPO ) • points-to set :Set of the objects a restricted pointer may point to • Reason The points-to set of a pointer must be allocated where that pointer can reach
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion
Features in Embedded Processors • On-chip memory : efficiently • Zero page : use smaller pointer types , fast , compact code • Harvard architectures : different native pointer representations and addressing mode are used for program and data address space
Separate VS Single address space (1) • Separate address space • disjoint sets of pointer types • know points-to sets to allocate data • use separate address buses • different memory access instructions use different pointer types as operands
Separate VS Single address space (2) • Single address space • A general native pointer type • No restriction on allocation • Try to use cheaper pointer type ( need to know the point-to set to decide if that pointer type can work)
An Abstract Memory Model • Memory Model : Memory Segments, Pointer Types , Relation • Memory Segments : subsets of the total memory space, uniform with properties( speed, addressing modes). M1 , M2 , M3 . . . MS • Pointer Types : P1 ,P2 ,P3 . . . PT • Relation : Pointer Type to Memory Segments
Memory Model • Size( Mj) : number of addressable units of storage in Memory Segment Mj • Relation function Mem( Pk )={ j | Pk can point to Mj } In which Pk Pointer Type • Memory Model can be expressed by a table
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion
Two Kinds of Cost • Cost : Static cost + Dynamic cost • Static cost : the size of a program, expressed by the sum of all statements in instruction set STMTR • Dynamic cost : execution time, for each statement need to be scaled by the estimate execution frequency of the statement
Expressions • V = {v1 , v2 . . . vN } : set of variables referred to in the source program • Size(v) : number of allocation units required by v • STMTR : set of individual occurrences of instructions • E = {e1 , e2 . . . eM } : set of pointer expressions
Functions • PtrExp : STMTR E allow the client of the storage allocator to modify the type of single pointer expressions independently • Seg(v) : V M , the segment where a variable is allocated • PtrT(e) : EP, the pointer type a pointer expression is assigned
Cost of A Statement ( 1 ) • For each statement in STMTR , we can have pointer cost and variable cost • ptrcostS ( e, t ) : pointer cost , the cost contribution of selecting “ t ” as the pointer type for pointer expression “ e ” • varcostS ( v, m ) : variable cost , the cost contribution of variable “ v ” if it is located in memory segment “ m ”
Cost of A Statement ( 2 ) • The cost of a particular solution is defined in terms of the cost contribution of each statement in STMTR Cost(S) = ∑ (eE)ptrcostS ( e, PtrT (e) ) + ∑ (vV)varcostS ( v, Seg(v) )
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion
BIP Formulation • BIP : Binary Integer Program • The storage allocation problem is formulated as a BIP • Based on the model of Memory Organization and the cost model
Feasible Solution • Two condition must be satisfied • Total size of the variables in a single memory segment ≤ size of the segment • Pointer expression that may point to a variable must be assigned a type that can access the segment where that variable is • Find a feasible solution with minimal cost !
BIP ( 1 ) • Each variable can be placed in exactly one memory segment xi1+ xi2 . . . + xiS=1 , 1 ≤ i ≤ N • Total size of the variables in a segment can not be greater than the size of the segment Size(v1) x1m+ Size(v2) x2m+ . . . + Size(vN) xNm ≤ Size(Mm) , 1 ≤ m ≤ S
BIP ( 2 ) • Each pointer expression have a unique pointer type yj1+ yj2 . . . + yjT = 1 , 1 ≤ j≤ M • Type of a pointer expression be general enough for all the variables in its points-to set Seg(v) Mem ( PtrT( ej ) ) , v Pt ( ej )
BIP ( 3 ) • Objective function is the cost of the solution
Discussion : Scalability • Number of variables and number of pointer expressions grow linearly in the size of the program • Number of memory segments and the number of pointer types depend on target architecture , so can be regarded as constants
Discussion : Accuracy • Fundamental to the model : cost of a statement can be expressed as linear combination of cost from variables and pointer expressions ---- Not precise • Some architectures may represent pointers with multiple machine words, so loading a pointer need several instructions
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiment & Results • Conclusion
WPO Prototype • Points-to analysis estimate the points-to set of each pointer • ILP solver Information about all global variables and pointers is put into the solver to get an allocation
Modified ICCAVR • Compile the C source code and use the allocation information by WPO to modify the memory attributes of variables • Allocation information is used during the parsing stage to modify the memory attributes of variables
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion
Experiments • Measure the execution time and code size of 6 benchmarks • Results are compared with code compiled on the standard ICCAR compiler • Different version of AVR microcontroller , internal memory vary from 0 to 4KB or more ( 64KB and 16KB)
Results • Results vary a lot with benchmarks CPU intensive or Memory intensive • Code size decreased slightly for most benchmarks ( Special : statemate ) • Execution time improved for most benchmarks( also Statemate )
Road Map • Brief Background • Memory Organization & Model • Cost Model • Formulation & Discussion • Implementation • Experiments & Results • Conclusion
Conclusion • Model of memory hierarchies for storage allocation for embedded system processors • Implement a memory allocator using ILP to get an optimal allocation under the memory model • Improve program size and speed • Automatically done , portable , robust : no need to include target-specific information in source code
The End Thank You !