Search in sources :

Example 1 with MethodCacheAnalysis

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);
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) WCETProcessorModel(com.jopdesign.wcet.WCETProcessorModel) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis)

Example 2 with MethodCacheAnalysis

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());
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) LpSolveException(lpsolve.LpSolveException) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) Segment(com.jopdesign.common.code.Segment)

Example 3 with MethodCacheAnalysis

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;
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) WCETProcessorModel(com.jopdesign.wcet.WCETProcessorModel) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) MethodInfo(com.jopdesign.common.MethodInfo) WCETTool(com.jopdesign.wcet.WCETTool)

Example 4 with MethodCacheAnalysis

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());
}
Also used : CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) HashMap(java.util.HashMap) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

MethodCacheAnalysis (com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis)4 MethodInfo (com.jopdesign.common.MethodInfo)2 ExecutionContext (com.jopdesign.common.code.ExecutionContext)2 WCETProcessorModel (com.jopdesign.wcet.WCETProcessorModel)2 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 Segment (com.jopdesign.common.code.Segment)1 WCETTool (com.jopdesign.wcet.WCETTool)1 CacheCostCalculationMethod (com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod)1 HashMap (java.util.HashMap)1 LpSolveException (lpsolve.LpSolveException)1