Search in sources :

Example 31 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.

the class ObjectCacheEvaluation method evaluateObjectCache.

private void evaluateObjectCache(MethodInfo targetMethod) throws InvalidFlowFactException, LpSolveException {
    long start, stop;
    // Method Cache
    //testExactAllFit();
    // Object Cache (debugging)
    ObjectCache objectCache = project.getWCETProcessorModel().getObjectCache();
    if (objectCache == null) {
        throw new AssertionError("Cannot evaluate object cache on a processor without object cache");
    }
    ObjectCacheAnalysis ocAnalysis = new ObjectCacheAnalysis(project, objectCache);
    // ocAnalysis.false, 1, 65536, ObjectCacheAnalysisDemo.DEFAULT_SET_SIZE);
    TopologicalOrderIterator<ExecutionContext, ContextEdge> cgIter = this.project.getCallGraph().topDownIterator();
    while (cgIter.hasNext()) {
        ExecutionContext scope = cgIter.next();
        Set<SymbolicAddress> addresses = ocAnalysis.getAddressSet(scope);
        String entryString = String.format("%-50s ==> |%d|%s ; Saturated Types: (%s)", scope, addresses.size(), ocAnalysis.getAddressSet(scope), ocAnalysis.getSaturatedTypes(scope));
        System.out.println("  " + entryString);
    }
    // Object cache, evaluation
    PrintStream pStream;
    ExecHelper.TeePrintStream oStream;
    try {
        pStream = new PrintStream(project.getProjectConfig().getOutFile("ocache", "eval.txt"));
        oStream = new ExecHelper.TeePrintStream(System.out, pStream);
    } catch (FileNotFoundException e) {
        oStream = new ExecHelper.TeePrintStream(System.out, null);
    }
    ObjectCacheAnalysisDemo oca;
    ObjectCacheTiming[] configs = { // sram,uni:  2 cycles field cost, 2*w cycles line cost
    new OCTimingUni(0, 0, 2), // sdram,uni: 10+2*w cycles for each w-word access
    new OCTimingUni(0, 10, 2), // SRAM, cmp, 2 cycles word load cost, s=2
    new OCTimingCmp(8, 1, 0, 0, 2), // SDRAM, cmp, 18 cycles quadword load cost, s=18
    new OCTimingCmp(8, 4, 0, 10, 2) };
    OCacheMode[] modes = { OCacheMode.BLOCK_FILL, OCacheMode.SINGLE_FIELD };
    List<OCacheAnalysisResult> samples = new ArrayList<OCacheAnalysisResult>();
    // need to be in ascending order
    int[] cacheWays = { 0, 2, 4, 8, 16, 32, 64, 512 };
    int[] lineSizesObjCache = { 4, 8, 16, 32 };
    int[] lineSizesFieldCache = { 1 };
    int[] blockSizesObjCache = { 1, 2, 4, 8, 16 };
    int[] lineSizes;
    for (int configId = 0; configId < configs.length; configId++) {
        ObjectCacheTiming ocConfig = configs[configId];
        oStream.println("---------------------------------------------------------");
        oStream.println("Object Cache Configuration: " + ocConfig);
        oStream.println("---------------------------------------------------------");
        for (OCacheMode mode : modes) {
            long maxCost = 0;
            //			long cacheMisses = Long.MAX_VALUE;
            String modeString;
            lineSizes = lineSizesObjCache;
            if (mode == OCacheMode.BLOCK_FILL)
                modeString = "fill-block";
            else {
                modeString = "field-as-tag";
                lineSizes = lineSizesFieldCache;
            }
            boolean first = true;
            for (int lineSize : lineSizes) {
                for (int blockSize : blockSizesObjCache) {
                    if (blockSize > lineSize)
                        continue;
                    if (mode == OCacheMode.BLOCK_FILL) {
                    } else {
                        if (blockSize > 1)
                            continue;
                    }
                    /* Configure object cache timing */
                    /* We have to take field access count of cache size = 0; our analysis otherwise does not assign
						 * sensible field access counts (thats the fault of the IPET method)
						 */
                    long totalFieldAccesses = -1, cachedFieldAccesses = -1;
                    double bestCyclesPerAccessForConfig = Double.POSITIVE_INFINITY;
                    double bestHitRate = 0.0;
                    long bestCostPerConfig = Long.MAX_VALUE;
                    // assume cacheSizes are in ascending order
                    for (int ways : cacheWays) {
                        ocConfig.setObjectCacheTiming(objectCache, blockSize);
                        if (mode == OCacheMode.SINGLE_FIELD) {
                            objectCache = ObjectCache.createFieldCache(project, ways, 0, 0, 0);
                        } else {
                            objectCache = new ObjectCache(project, ways, blockSize, lineSize, 0, 0, 0);
                        }
                        ocConfig.setObjectCacheTiming(objectCache, blockSize);
                        oca = new ObjectCacheAnalysisDemo(project, objectCache);
                        double cyclesPerAccess, hitRate;
                        ObjectCache.ObjectCacheCost ocCost = oca.computeCost();
                        long cost = ocCost.getCost();
                        if (cost < bestCostPerConfig)
                            bestCostPerConfig = cost;
                        double bestRatio, ratio;
                        if (ways == 0) {
                            maxCost = cost;
                            totalFieldAccesses = ocCost.getTotalFieldAccesses();
                            cachedFieldAccesses = ocCost.getFieldAccessesWithoutBypass();
                            bestRatio = 1.0;
                            ratio = 1.0;
                        } else {
                            bestRatio = (double) bestCostPerConfig / (double) maxCost;
                            ratio = (double) cost / (double) maxCost;
                        }
                        cyclesPerAccess = (double) cost / (double) totalFieldAccesses;
                        if (cyclesPerAccess < bestCyclesPerAccessForConfig || ways <= 1) {
                            bestCyclesPerAccessForConfig = cyclesPerAccess;
                        }
                        /* hit rate is defined as: 1 - ((cache misses+accesses to bypassed fields) / total field accesses (with n=0) */
                        long missAccesses = ocCost.getCacheMissCount() + ocCost.getBypassCount();
                        hitRate = (1 - ((double) missAccesses / (double) totalFieldAccesses));
                        if (hitRate > bestHitRate || ways <= 1) {
                            bestHitRate = hitRate;
                        }
                        if (first) {
                            oStream.println(String.format("***** ***** MODE = %s ***** *****\n", modeString));
                            oStream.println(String.format(" - max tags accessed (upper bound) = %d, max fields accesses = %d", oca.getMaxAccessedTags(targetMethod, CallString.EMPTY), totalFieldAccesses));
                            first = false;
                        }
                        String report = //, %.2f %% 'hitrate')", 
                        String.format(//, %.2f %% 'hitrate')", 
                        " + Cycles Per Access [N=%3d,l=%2d,b=%2d]: %.2f (%d total cost, %.2f %% cost of no cache, %d bypass cost)", ways, lineSize, blockSize, bestCyclesPerAccessForConfig, cost, bestRatio * 100, ocCost.getBypassCost());
                        if (bestCostPerConfig > cost) {
                            report += String.format(" # (analysis cost increased by %.2f %% for this associativity)", ratio * 100);
                        }
                        oStream.println(report);
                        if (mode != OCacheMode.SINGLE_FIELD) {
                            OCacheAnalysisResult sample = new ObjectCacheEvaluationResult.OCacheAnalysisResult(ways, lineSize, blockSize, configId, bestHitRate, bestCyclesPerAccessForConfig, ocCost);
                            samples.add(sample);
                        }
                    }
                }
            }
        }
    }
    OCacheAnalysisResult.dumpBarPlot(samples, oStream);
    OCacheAnalysisResult.dumpPlot(samples, oStream);
    OCacheAnalysisResult.dumpLatex(samples, oStream);
}
Also used : OCacheAnalysisResult(com.jopdesign.wcet.analysis.cache.ObjectCacheEvaluationResult.OCacheAnalysisResult) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) ObjectCacheAnalysis(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysis) CallString(com.jopdesign.common.code.CallString) ObjectCache(com.jopdesign.wcet.jop.ObjectCache) SymbolicAddress(com.jopdesign.dfa.analyses.SymbolicAddress) PrintStream(java.io.PrintStream) ObjectCacheCost(com.jopdesign.wcet.jop.ObjectCache.ObjectCacheCost) ContextEdge(com.jopdesign.common.code.CallGraph.ContextEdge) OCacheMode(com.jopdesign.wcet.analysis.cache.ObjectCacheEvaluationResult.OCacheMode) ExecutionContext(com.jopdesign.common.code.ExecutionContext) ObjectCacheAnalysisDemo(com.jopdesign.wcet.analysis.cache.ObjectCacheAnalysisDemo)

Example 32 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.

the class MethodBuilder method visitBasicBlockNode.

public void visitBasicBlockNode(BasicBlockNode n) {
    ExecutionContext ctx = new ExecutionContext(n.getBasicBlock().getMethodInfo());
    SubAutomaton bbLoc = createBasicBlock(n.getId(), jTrans.getProject().getWCETProcessorModel().basicBlockWCET(ctx, n.getBasicBlock()));
    this.nodeTemplates.put(n, bbLoc);
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext)

Example 33 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.

the class WCETNodeLabeller method addNodeLabel.

@Override
protected void addNodeLabel(BasicBlockNode n, StringBuilder nodeInfo) {
    BasicBlock codeBlock = n.getBasicBlock();
    nodeInfo.append(project.getWCETProcessorModel().basicBlockWCET(new ExecutionContext(codeBlock.getMethodInfo()), codeBlock) + " Cyc, ");
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext) BasicBlock(com.jopdesign.common.code.BasicBlock)

Example 34 with ExecutionContext

use of com.jopdesign.common.code.ExecutionContext in project jop by jop-devel.

the class TemplateBuilder method addLoop.

public int addLoop(CFGNode hol, int nestingDepth, LoopBound lb) {
    ExecutionContext eCtx = new ExecutionContext(hol.getControlFlowGraph().getMethodInfo());
    nestingDepth = nestingDepth - 1;
    int varKey = loopBounds.size();
    getTemplate().appendDeclaration(String.format("const int %s = %d;", loopBoundConst(varKey), lb.getUpperBound(eCtx)));
    getTemplate().appendDeclaration(String.format("const int %s = %d;", loopLowerBoundConst(varKey), lb.getLowerBound(eCtx)));
    while (loopVarBounds.size() < nestingDepth) {
        loopVarBounds.add(0L);
    }
    if (loopVarBounds.size() <= nestingDepth) {
        loopVarBounds.add(lb.getUpperBound(eCtx).longValue());
    } else {
        if (lb.getUpperBound(eCtx).longValue() > loopVarBounds.get(nestingDepth)) {
            loopVarBounds.set(nestingDepth, lb.getUpperBound(eCtx).longValue());
        }
    }
    this.loopBounds.put(hol, varKey);
    this.loopVars.put(hol, nestingDepth);
    return varKey;
}
Also used : ExecutionContext(com.jopdesign.common.code.ExecutionContext)

Aggregations

ExecutionContext (com.jopdesign.common.code.ExecutionContext)34 MethodInfo (com.jopdesign.common.MethodInfo)15 ContextEdge (com.jopdesign.common.code.CallGraph.ContextEdge)11 LinkedHashSet (java.util.LinkedHashSet)10 ControlFlowGraph (com.jopdesign.common.code.ControlFlowGraph)6 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)6 Set (java.util.Set)4 MethodCode (com.jopdesign.common.MethodCode)3 BasicBlockNode (com.jopdesign.common.code.ControlFlowGraph.BasicBlockNode)3 LoopBound (com.jopdesign.common.code.LoopBound)3 DFSTraverser (com.jopdesign.common.graphutils.DFSTraverser)3 EmptyDFSVisitor (com.jopdesign.common.graphutils.DFSTraverser.EmptyDFSVisitor)3 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 InstructionHandle (org.apache.bcel.generic.InstructionHandle)3 ClassInfo (com.jopdesign.common.ClassInfo)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallGraph (com.jopdesign.common.code.CallGraph)2 InvokeSite (com.jopdesign.common.code.InvokeSite)2