use of com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis in project jop by jop-devel.
the class MethodBuilder method visitInvokeNode.
public void visitInvokeNode(ControlFlowGraph.InvokeNode n) {
ExecutionContext ctx = new ExecutionContext(n.getBasicBlock().getMethodInfo());
MethodCacheAnalysis mca = new MethodCacheAnalysis(jTrans.getProject());
WCETProcessorModel proc = jTrans.getProject().getWCETProcessorModel();
SubAutomaton invokeAuto;
long staticWCET = proc.basicBlockWCET(ctx, n.getBasicBlock());
if (jTrans.getCacheSim().isAlwaysMiss()) {
staticWCET += mca.getInvokeReturnMissCost(n.getInvokeSite(), CallString.EMPTY);
}
invokeAuto = invokeBuilder.translateInvoke(this, n, staticWCET);
this.nodeTemplates.put(n, invokeAuto);
}
use of com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis in project jop by jop-devel.
the class WCETAnalysis method exploreCacheAnalysis.
/**
* @param mca
* @param iter
* @throws InvalidFlowFactException
*/
@SuppressWarnings("unused")
private void exploreCacheAnalysis() throws InvalidFlowFactException {
// Segment Cache Analysis: Experiments
MethodCacheAnalysis mca = new MethodCacheAnalysis(wcetTool);
/* iterate top down the scope graph (currently: the call graph) */
TopologicalOrderIterator<ExecutionContext, ContextEdge> iter = wcetTool.getCallGraph().reverseTopologicalOrder();
LpSolveWrapper.resetSolverTime();
long blocks = 0;
long start = System.nanoTime();
while (iter.hasNext()) {
ExecutionContext scope = iter.next();
Segment segment = Segment.methodSegment(scope.getMethodInfo(), scope.getCallString(), wcetTool, wcetTool.getCallstringLength(), wcetTool);
int availBlocks = wcetTool.getWCETProcessorModel().getMethodCache().getNumBlocks();
long total, distinctApprox = -1, distinct = -1;
blocks = total = mca.countDistinctBlocksUsed(segment);
if (total > availBlocks || true) {
try {
blocks = distinctApprox = mca.countDistinctBlocksAccessed(segment, false);
if (blocks > availBlocks && blocks < availBlocks * 2 || true) {
blocks = distinct = mca.countDistinctBlocksAccessed(segment, true);
}
} catch (LpSolveException e) {
System.err.println((distinctApprox >= 0 ? "I" : "Relaxed ") + "LP Problem too difficult, giving up: " + e);
}
}
System.out.println(String.format("block-count < %2d [%2d,%2d,%2d] for %-30s @ %s", blocks, total, distinctApprox, distinct, scope.getMethodInfo().getFQMethodName(), scope.getCallString().toStringVerbose(false)));
}
long stop = System.nanoTime();
reportSpecial("block-count", WcetCost.totalCost(blocks), start, stop, LpSolveWrapper.getSolverTime());
System.out.println("solver-time: " + LpSolveWrapper.getSolverTime());
}
use of com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis in project jop by jop-devel.
the class LocalAnalysis method recursiveCost.
public WcetCost recursiveCost(RecursiveAnalysis<AnalysisContextLocal, WcetCost> stagedAnalysis, ControlFlowGraph.InvokeNode n, AnalysisContextLocal ctx) {
CacheCostCalculationMethod cacheMode = ctx.getCacheApproxMode();
if (cacheMode.needsInterProcIPET()) {
throw new AssertionError("Error: Cache Mode " + cacheMode + " not supported using local IPET strategy - " + "it needs an interprocedural IPET analysis");
}
WCETTool project = stagedAnalysis.getWCETTool();
MethodInfo invoker = n.getBasicBlock().getMethodInfo();
MethodInfo invoked = n.getImplementingMethod();
WCETProcessorModel proc = project.getWCETProcessorModel();
MethodCacheAnalysis mca = new MethodCacheAnalysis(project);
long cacheCost;
AnalysisContextLocal recCtx = ctx.withCallString(ctx.getCallString().push(n, maxCallstringLength));
WcetCost recCost = stagedAnalysis.computeCost(invoked, recCtx);
long nonLocalExecCost = recCost.getCost() - recCost.getCacheCost();
long nonLocalCacheCost = recCost.getCacheCost();
long invokeReturnCost = mca.getInvokeReturnMissCost(n.getInvokeSite(), ctx.getCallString());
if (proc.getMethodCache().getNumBlocks() == 0 || cacheMode == CacheCostCalculationMethod.ALWAYS_HIT) {
cacheCost = 0;
} else if (project.getCallGraph().isLeafMethod(invoked)) {
cacheCost = invokeReturnCost + nonLocalCacheCost;
} else if (cacheMode == CacheCostCalculationMethod.ALL_FIT_SIMPLE && allFit(project, invoked, recCtx.getCallString())) {
long returnCost = mca.getMissOnceCost(invoker, false);
/* Maybe its better not to apply the all-fit heuristic ... */
long noAllFitCost = recCost.getCost() + invokeReturnCost;
/* Compute cost without method cache */
AnalysisContextLocal ahCtx = recCtx.withCacheApprox(CacheCostCalculationMethod.ALWAYS_HIT);
long alwaysHitCost = stagedAnalysis.computeCost(invoked, ahCtx).getCost();
/* Compute penalty for loading each method exactly once */
long allFitPenalty = mca.getMissOnceCummulativeCacheCost(invoked, assumeMissOnceOnInvoke);
long allFitCacheCost = allFitPenalty + returnCost;
/* Cost All-Fit: recursive + penalty for loading once + return to caller */
long allFitCost = alwaysHitCost + allFitCacheCost;
/* Choose the better approximation */
if (allFitCost <= noAllFitCost) {
cacheCost = allFitCacheCost;
nonLocalExecCost = alwaysHitCost;
} else {
cacheCost = invokeReturnCost + nonLocalCacheCost;
}
} else {
/* ALWAYS MISS or doesn't fit */
cacheCost = invokeReturnCost + nonLocalCacheCost;
}
WcetCost cost = new WcetCost();
cost.addNonLocalCost(nonLocalExecCost);
cost.addCacheCost(cacheCost);
logger.debug("Recursive WCET computation: " + invoked + ". invoke return cache cost: " + invokeReturnCost + ". non-local cache cost: " + nonLocalCacheCost + ". cummulative cache cost: " + cacheCost + " non local execution cost: " + nonLocalExecCost);
return cost;
}
use of com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis in project jop by jop-devel.
the class RecursiveWcetAnalysis method updateReport.
// FIXME: [recursive-wcet-analysis] Report generation is a big mess
// FIXME: [recursive-wcet-analysis] For now, we only add line costs once per method
private void updateReport(CacheKey key, LocalWCETSolution sol) {
MethodInfo m = key.m;
HashMap<CFGNode, String> nodeFlowCostDescrs = new HashMap<CFGNode, String>();
updateClassReport(key, sol);
Map<String, Object> stats = new HashMap<String, Object>();
stats.put("WCET", sol.getCost());
stats.put("mode", key.ctx);
MethodCacheAnalysis mca = new MethodCacheAnalysis(getWCETTool());
stats.put("all-methods-fit-in-cache", mca.isPersistenceRegion(getWCETTool(), m, key.ctx.getCallString(), EnumSet.allOf(PersistenceCheck.class)));
getWCETTool().getReport().addDetailedReport(m, "WCET_" + key.ctx.toString(), stats, nodeFlowCostDescrs, sol.getEdgeFlow());
}
Aggregations