use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge in project jop by jop-devel.
the class ObjectCacheAnalysis method extractCost.
/**
* @param segment the segment analyzed
* @param lpCost the lp objective value
* @param flowMap the lp assignment for variables
* @param accessCostInfo information on object cache cost edges
* @param costModel the object cache cost model
* @param refMissEdges the object cache cost edges for references
* @param blockMissEdges the object cache cost edges for blocks
* @return
*/
private ObjectCache.ObjectCacheCost extractCost(Segment segment, long lpCost, Map<SuperGraphEdge, Long> flowMap, AccessCostInfo accessCostInfo, ObjectCacheCostModel costModel, Set<SuperGraphEdge> refMissEdges, Set<SuperGraphEdge> blockMissEdges) {
long missCount = 0;
/* miss count */
long totalMissCost = 0;
/* has to be equal to (cost - bypass cost) */
long bypassAccesses = 0;
/* bypassed fields accesses */
long fieldAccesses = 0;
/* cached fields accessed */
long totalBypassCost = 0;
for (SuperGraphEdge edge : segment.getEdges()) {
long edgeFreq = flowMap.get(edge);
SuperGraphNode node = edge.getTarget();
/* Compute cost for basic block */
BasicBlock bb = node.getCFGNode().getBasicBlock();
if (bb == null)
continue;
long missCost = accessCostInfo.getMissCost(node) * edgeFreq;
totalMissCost += missCost;
totalBypassCost += accessCostInfo.getBypassCost(node) * edgeFreq;
/* Calculate number of unpredictable always-miss accesses, and record them */
long alwaysMissCost = costModel.getReplaceLineCost() + costModel.getLoadCacheBlockCost();
if (alwaysMissCost > 0) {
missCount += missCost / alwaysMissCost;
}
/* count normal and bypass accesses in the basic block */
for (InstructionHandle ih : bb.getInstructions()) {
String handleType = getHandleType(project, node.getCfg(), ih);
if (handleType == null)
continue;
/* No getfield/handle access */
if (!isFieldCached(project, node.getCfg(), ih, maxCachedFieldIndex)) {
bypassAccesses += edgeFreq;
} else {
fieldAccesses += edgeFreq;
}
}
}
/* For each miss edge, there is an associated cost; moreover
* fill-word & single-field: missCount = sum of miss block variables
* fill-line: missCount = sum of miss object reference variables
*/
long totalRefMisses = 0;
for (SuperGraphEdge refMissEdge : refMissEdges) {
totalRefMisses += flowMap.get(refMissEdge);
}
totalMissCost += costModel.getReplaceLineCost() * totalRefMisses;
long totalBlockMisses = 0;
for (SuperGraphEdge blockMissEdge : blockMissEdges) {
totalBlockMisses += flowMap.get(blockMissEdge);
}
totalMissCost += costModel.getLoadCacheBlockCost() * totalBlockMisses;
missCount += totalBlockMisses;
if (totalMissCost + totalBypassCost != lpCost) {
WCETTool.logger.warn(String.format("Error in calculating missCost in all fit-area (misscount = %d): %d but should be %d (%d - %d)", missCount, totalMissCost, lpCost - totalBypassCost, lpCost, totalBypassCost));
}
ObjectCache.ObjectCacheCost ocCost = new ObjectCache.ObjectCacheCost(missCount, totalMissCost, bypassAccesses, totalBypassCost, fieldAccesses);
return ocCost;
}
use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge in project jop by jop-devel.
the class GlobalAnalysis method setExecutionCost.
/**
* Compute the execution time of each edge in in the supergraph
*
* @param segment the supergraph, whose vertices are considered
* @param ipetInst the IPET instance
* @return the cost map
*/
private Map<SuperGraphEdge, WcetCost> setExecutionCost(Segment segment, IPETSolver<SuperGraphEdge> ipetInstance) {
HashMap<SuperGraphEdge, WcetCost> edgeCost = new HashMap<SuperGraphEdge, WcetCost>();
/* Attribute edge cost to edge source */
for (SuperGraphEdge e : segment.getEdges()) {
/* ignore exit edges, because their target is per definitionem not part of the segment */
if (segment.isExitEdge(e))
continue;
SuperGraphNode sg = e.getTarget();
WcetCost cost = calculateCost(sg);
edgeCost.put(e, cost);
ipetInstance.addEdgeCost(e, cost.getCost());
}
return edgeCost;
}
use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge in project jop by jop-devel.
the class GlobalAnalysis method computeWCET.
/**
* Compute WCET for a segment, using global IPET, and cache analysis results
* @throws InvalidFlowFactException
* @throws LpSolveException
* @throws UnsupportedCacheModelException
*/
public WcetCost computeWCET(String key, Segment segment, CacheCostCalculationMethod cacheMode) throws InvalidFlowFactException, LpSolveException, UnsupportedCacheModelException {
/* create an IPET problem for the segment */
String problemId = formatProblemName(key, segment.getEntryCFGs().toString());
IPETSolver<SuperGraphEdge> ipetSolver = buildIpetProblem(project, problemId, segment, ipetConfig);
/* compute cost */
setExecutionCost(segment, ipetSolver);
/* Add constraints for caches */
HashMap<String, Set<SuperGraphEdge>> costMissEdges = new HashMap<String, Set<SuperGraphEdge>>();
for (CacheModel cacheModel : project.getWCETProcessorModel().getCaches()) {
CacheAnalysis cpa = CacheAnalysis.getCacheAnalysisFor(cacheModel, project);
Set<SuperGraphEdge> edges = cpa.addCacheCost(segment, ipetSolver, cacheMode);
costMissEdges.put(cacheModel.toString(), edges);
}
/* Add constraints for object cache */
// ObjectRefAnalysis objectCacheAnalysis = new ObjectRefAnalysis(project, false, 4, 8, 4);
/* Return variables */
Map<SuperGraphEdge, Long> flowMap = new HashMap<SuperGraphEdge, Long>();
/* Solve */
long _start = System.currentTimeMillis();
double relaxedCost = 0;
try {
relaxedCost = ipetSolver.solve(null, false);
} catch (LpSolveException ex) {
WCETTool.logger.error("Solving the relaxed problem failed - bug in lp solving lib?");
}
long _time_rlp = System.currentTimeMillis() - _start;
double ilpCost = ipetSolver.solve(flowMap);
long _time_ilp = System.currentTimeMillis() - _start;
WCETTool.logger.info(String.format("LP (%d ms) %d | %d ILP (%d ms)", _time_rlp, Math.round(relaxedCost), Math.round(ilpCost), _time_ilp));
/* Cost extraction */
WcetCost cost;
/* extract cost and generate a profile in 'profiles' */
cost = exportCostProfile(flowMap, costMissEdges, ipetSolver, problemId);
/* Sanity Check, and Return */
if (Double.isInfinite(ilpCost)) {
throw new AssertionError("[GlobalAnalysis] Unbounded (infinite lp cost)");
}
long objValue = (long) (ilpCost + 0.5);
if (cost.getCost() != objValue) {
throw new AssertionError("[GlobalAnalysis] Inconsistency: lpValue vs. extracted value: " + objValue + " / " + cost.getCost());
}
return cost;
}
use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge in project jop by jop-devel.
the class GlobalAnalysis method getInfeasibleEdgeConstraints.
/**
* For each infeasible edge, assert that the edge has flow 0
* @param wcetTool
* @param segment
* @return
*/
private static Iterable<LinearConstraint<SuperGraphEdge>> getInfeasibleEdgeConstraints(WCETTool wcetTool, Segment segment) {
List<LinearConstraint<SuperGraphEdge>> constraints = new ArrayList<LinearConstraint<SuperGraphEdge>>();
// -- edge = 0
for (ContextCFG ccfg : segment.getCallGraphNodes()) {
for (CFGEdge edge : wcetTool.getInfeasibleEdges(ccfg.getCfg(), ccfg.getCallString())) {
LinearConstraint<SuperGraphEdge> infeasibleConstraint = new LinearConstraint<SuperGraphEdge>(ConstraintType.Equal);
infeasibleConstraint.addLHS(segment.liftCFGEdges(ccfg, Iterators.singleton(edge)));
infeasibleConstraint.addRHS(0);
constraints.add(infeasibleConstraint);
}
}
return constraints;
}
use of com.jopdesign.common.code.SuperGraph.SuperGraphEdge in project jop by jop-devel.
the class WCETAnalysis method runBlockingTimeAnalysis.
private void runBlockingTimeAnalysis(MethodInfo targetMethod) throws InvalidFlowFactException, LpSolveException, UnsupportedCacheModelException {
GlobalAnalysis an = new GlobalAnalysis(wcetTool, ipetConfig);
CacheCostCalculationMethod requestedCacheApprox = IPETConfig.getRequestedCacheApprox(config);
/* Find all synchronized segments */
Segment target = Segment.methodSegment(targetMethod, CallString.EMPTY, wcetTool, wcetTool.getCallstringLength(), wcetTool);
ArrayList<SynchronizedBlockResult> sBlocks = new ArrayList<SynchronizedBlockResult>();
for (ContextCFG ccfg : target.getCallGraphNodes()) {
for (CFGNode cfgNode : ccfg.getCfg().vertexSet()) {
if (cfgNode.getBasicBlock() == null)
continue;
for (InstructionHandle ih : cfgNode.getBasicBlock().getInstructions()) {
if (ih.getInstruction() instanceof MONITORENTER) {
/* compute synchronized block WCET */
Segment synchronizedSegment = Segment.synchronizedSegment(ccfg, cfgNode, ih, wcetTool, wcetTool.getCallstringLength(), wcetTool);
wcet = an.computeWCET(targetMethod.getShortName(), synchronizedSegment, requestedCacheApprox);
sBlocks.add(new SynchronizedBlockResult(sBlocks.size(), synchronizedSegment, cfgNode, ih, wcet));
}
}
}
}
/* check nested synchronized blocks */
for (SynchronizedBlockResult sBlock : sBlocks) {
for (SynchronizedBlockResult otherBlock : sBlocks) {
if (sBlock == otherBlock)
continue;
for (SuperGraphEdge entryEdge : otherBlock.synchronizedSegment.getEntryEdges()) {
if (sBlock.synchronizedSegment.includesEdge(entryEdge)) {
sBlock.nested.add(otherBlock);
break;
}
}
}
}
System.out.println("=== Synchronized Blocks ===");
for (SynchronizedBlockResult sBlock : sBlocks) {
sBlock.dump(System.out);
}
}
Aggregations