Search in sources :

Example 1 with CacheCostCalculationMethod

use of com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod in project jop by jop-devel.

the class GlobalAnalysis method computeWCET.

/**
     * Compute WCET using global IPET, and either ALWAYS_MISS or GLOBAL_ALL_FIT
     */
public WcetCost computeWCET(MethodInfo m, AnalysisContextLocal ctx) throws Exception {
    CacheCostCalculationMethod cacheMode = ctx.getCacheApproxMode();
    String key = "global" + "_" + cacheMode;
    Segment segment = Segment.methodSegment(m, ctx.getCallString(), project, project.getAppInfo().getCallstringLength(), project);
    return computeWCET(key, segment, cacheMode);
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) Segment(com.jopdesign.common.code.Segment)

Example 2 with CacheCostCalculationMethod

use of com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod in project jop by jop-devel.

the class WCETAnalysis method runMetrics.

private void runMetrics(MethodInfo targetMethod) throws Exception {
    /* generate reports later for simple_fit */
    wcetTool.setGenerateWCETReport(false);
    /* check whether the largest method fits into the cache */
    List<MethodInfo> allMethods = wcetTool.getCallGraph().getReachableImplementations(targetMethod);
    MethodInfo largestMethod = MethodCacheAnalysis.checkCache(wcetTool, allMethods);
    int minWords = MiscUtils.bytesToWords(largestMethod.getCode().getNumberOfBytes());
    reportMetric("min-cache-size", largestMethod.getFQMethodName(), minWords);
    /* Compute cyclomatic complexity */
    exec.info("Cyclomatic complexity: " + wcetTool.computeCyclomaticComplexity(targetMethod));
    /* Fast, useful cache approximationx */
    CacheCostCalculationMethod cacheApprox = CacheCostCalculationMethod.ALL_FIT_SIMPLE;
    /* Perform a few standard analysis (MIN_CACHE_COSdT, ALWAYS_HIT, ALWAYS_MISS) without call strings */
    long start, stop;
    /* Tree based WCET analysis - has to be equal to ALWAYS_MISS if no flow facts are used */
    {
        start = System.nanoTime();
        TreeAnalysis treeAna = new TreeAnalysis(wcetTool, false);
        long treeWCET = treeAna.computeWCET(targetMethod);
        stop = System.nanoTime();
        reportMetric("progress-measure", treeAna.getMaxProgress(targetMethod));
        reportSpecial("wcet.tree", WcetCost.totalCost(treeWCET), start, stop, 0.0);
    }
    RecursiveWcetAnalysis<AnalysisContextLocal> an = new RecursiveWcetAnalysis<AnalysisContextLocal>(wcetTool, ipetConfig, new LocalAnalysis(wcetTool, ipetConfig));
    /* always miss */
    start = System.nanoTime();
    alwaysMissCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_MISS));
    stop = System.nanoTime();
    reportSpecial("always-miss", alwaysMissCost, start, stop, LpSolveWrapper.getSolverTime());
    /* always hit */
    LpSolveWrapper.resetSolverTime();
    start = System.nanoTime();
    alwaysHitCost = an.computeCost(targetMethod, new AnalysisContextLocal(CacheCostCalculationMethod.ALWAYS_HIT));
    stop = System.nanoTime();
    reportSpecial("always-hit", alwaysHitCost, start, stop, LpSolveWrapper.getSolverTime());
    /* simple approx */
    wcetTool.setGenerateWCETReport(true);
    start = System.nanoTime();
    approxCost = an.computeCost(targetMethod, new AnalysisContextLocal(cacheApprox));
    stop = System.nanoTime();
    reportSpecial("recursive-report", approxCost, start, stop, LpSolveWrapper.getSolverTime());
    wcetTool.setGenerateWCETReport(false);
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) MethodInfo(com.jopdesign.common.MethodInfo) RecursiveWcetAnalysis(com.jopdesign.wcet.analysis.RecursiveWcetAnalysis) LocalAnalysis(com.jopdesign.wcet.analysis.LocalAnalysis) AnalysisContextLocal(com.jopdesign.wcet.analysis.AnalysisContextLocal) TreeAnalysis(com.jopdesign.wcet.analysis.TreeAnalysis)

Example 3 with CacheCostCalculationMethod

use of com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod in project jop by jop-devel.

the class GreedyConfig method getCacheApproximation.

public CacheCostCalculationMethod getCacheApproximation() {
    CacheCostCalculationMethod defaultValue = options.getOption(WCA_CACHE_APPROXIMATION);
    if (defaultValue != null) {
        return defaultValue;
    }
    AnalysisType analysisType = getCacheAnalysisType();
    if (analysisType == AnalysisType.ALWAYS_HIT) {
        return CacheCostCalculationMethod.ALWAYS_HIT;
    }
    if (analysisType == AnalysisType.ALWAYS_MISS) {
        return CacheCostCalculationMethod.ALWAYS_MISS;
    }
    if (analysisType == AnalysisType.ALWAYS_MISS_OR_HIT) {
        return CacheCostCalculationMethod.ALL_FIT_SIMPLE;
    }
    return CacheCostCalculationMethod.ALL_FIT_REGIONS;
}
Also used : AnalysisType(com.jopdesign.jcopter.analysis.MethodCacheAnalysis.AnalysisType) CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod)

Example 4 with CacheCostCalculationMethod

use of com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod 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 5 with CacheCostCalculationMethod

use of com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod 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);
    }
}
Also used : CacheCostCalculationMethod(com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod) CFGNode(com.jopdesign.common.code.ControlFlowGraph.CFGNode) GlobalAnalysis(com.jopdesign.wcet.analysis.GlobalAnalysis) ContextCFG(com.jopdesign.common.code.SuperGraph.ContextCFG) ArrayList(java.util.ArrayList) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge) MONITORENTER(org.apache.bcel.generic.MONITORENTER) Segment(com.jopdesign.common.code.Segment) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

CacheCostCalculationMethod (com.jopdesign.wcet.ipet.IPETConfig.CacheCostCalculationMethod)6 Segment (com.jopdesign.common.code.Segment)3 MethodInfo (com.jopdesign.common.MethodInfo)2 GlobalAnalysis (com.jopdesign.wcet.analysis.GlobalAnalysis)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)1 SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)1 AnalysisType (com.jopdesign.jcopter.analysis.MethodCacheAnalysis.AnalysisType)1 WCETProcessorModel (com.jopdesign.wcet.WCETProcessorModel)1 WCETTool (com.jopdesign.wcet.WCETTool)1 AnalysisContextLocal (com.jopdesign.wcet.analysis.AnalysisContextLocal)1 LocalAnalysis (com.jopdesign.wcet.analysis.LocalAnalysis)1 RecursiveWcetAnalysis (com.jopdesign.wcet.analysis.RecursiveWcetAnalysis)1 TreeAnalysis (com.jopdesign.wcet.analysis.TreeAnalysis)1 MethodCacheAnalysis (com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis)1 ArrayList (java.util.ArrayList)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 MONITORENTER (org.apache.bcel.generic.MONITORENTER)1