Search in sources :

Example 1 with CacheAnalysis

use of com.jopdesign.wcet.analysis.cache.CacheAnalysis 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;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) LpSolveException(lpsolve.LpSolveException) CacheModel(com.jopdesign.wcet.jop.CacheModel) MethodCacheAnalysis(com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis) CacheAnalysis(com.jopdesign.wcet.analysis.cache.CacheAnalysis) SuperGraphEdge(com.jopdesign.common.code.SuperGraph.SuperGraphEdge)

Aggregations

SuperGraphEdge (com.jopdesign.common.code.SuperGraph.SuperGraphEdge)1 CacheAnalysis (com.jopdesign.wcet.analysis.cache.CacheAnalysis)1 MethodCacheAnalysis (com.jopdesign.wcet.analysis.cache.MethodCacheAnalysis)1 CacheModel (com.jopdesign.wcet.jop.CacheModel)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 LpSolveException (lpsolve.LpSolveException)1