From c5bc69e2d033f03b4cb346baeb6b64aa63921163 Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Tue, 2 Jun 2020 15:33:30 +0200 Subject: [PATCH] nfj creation now works --- src/main/java/mvd/jester/App.java | 4 +--- src/main/java/mvd/jester/ResultLogger.java | 1 - src/main/java/mvd/jester/TestEnvironment.java | 2 -- src/main/java/mvd/jester/model/Job.java | 9 --------- src/main/java/mvd/jester/model/SystemSetup.java | 24 ++++++++---------------- src/main/java/mvd/jester/tests/FonsecaNelis.java | 18 +++++++++++------- src/main/java/mvd/jester/utils/DagUtils.java | 75 ++++++--------------------------------------------------------------------- src/test/java/mvd/jester/model/TestDagUtils.java | 20 ++++++++------------ src/test/java/mvd/jester/model/TestSystemSetup.java | 4 ++-- 9 files changed, 36 insertions(+), 121 deletions(-) diff --git a/src/main/java/mvd/jester/App.java b/src/main/java/mvd/jester/App.java index 3353dff..d88d5cc 100644 --- a/src/main/java/mvd/jester/App.java +++ b/src/main/java/mvd/jester/App.java @@ -6,8 +6,6 @@ import mvd.jester.model.DagTask; import mvd.jester.model.SystemSetup; import mvd.jester.tests.AbstractTest; import mvd.jester.tests.FonsecaNelis; -import mvd.jester.tests.MelaniButtazzo; -import mvd.jester.tests.SchmidMottok; /** @@ -18,7 +16,7 @@ public class App { public static void main(String[] args) { for (int p = 8; p <= 8; p *= 2) { SystemSetup.DagTaskBuilder builder = - new SystemSetup.DagTaskBuilder(p).setNumberOfProcessors(p); + new SystemSetup.DagTaskBuilder().setNumberOfProcessors(p); TestEnvironment te = new TestEnvironment(); List> tests = diff --git a/src/main/java/mvd/jester/ResultLogger.java b/src/main/java/mvd/jester/ResultLogger.java index 53a90d6..adf5bc4 100644 --- a/src/main/java/mvd/jester/ResultLogger.java +++ b/src/main/java/mvd/jester/ResultLogger.java @@ -3,7 +3,6 @@ package mvd.jester; import java.util.Map; import java.util.Set; import java.util.Map.Entry; -import mvd.jester.info.SchedulingInfo.Feasiblity; import mvd.jester.model.Task; import mvd.jester.tests.AbstractTest; import mvd.jester.utils.Logger; diff --git a/src/main/java/mvd/jester/TestEnvironment.java b/src/main/java/mvd/jester/TestEnvironment.java index 1f5a5b5..e4a5c09 100644 --- a/src/main/java/mvd/jester/TestEnvironment.java +++ b/src/main/java/mvd/jester/TestEnvironment.java @@ -1,8 +1,6 @@ package mvd.jester; import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; diff --git a/src/main/java/mvd/jester/model/Job.java b/src/main/java/mvd/jester/model/Job.java index 7a37c83..0ca9ed1 100644 --- a/src/main/java/mvd/jester/model/Job.java +++ b/src/main/java/mvd/jester/model/Job.java @@ -4,7 +4,6 @@ public class Job { private final long wcet; private long relativeCompletionTime; - private boolean visited = false; public Job(long wcet) { this.wcet = wcet; @@ -15,14 +14,6 @@ public class Job { return wcet; } - public boolean getVisited() { - return visited; - } - - public void setVisited(boolean visited) { - this.visited = visited; - } - /** * @return the relativeCompletionTime */ diff --git a/src/main/java/mvd/jester/model/SystemSetup.java b/src/main/java/mvd/jester/model/SystemSetup.java index d6e8308..1cce652 100644 --- a/src/main/java/mvd/jester/model/SystemSetup.java +++ b/src/main/java/mvd/jester/model/SystemSetup.java @@ -5,7 +5,6 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Optional; -import java.util.Random; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; import com.google.common.collect.ArrayListMultimap; @@ -207,14 +206,12 @@ public class SystemSetup { private long numberOfProcessors = 4; private long minimumWcet = 1; private long maximumWcet = 100; - private long maxNumberOfBranches = 3; // TODO: change back to 5 - private long depth = 1; // change back to 2 + private long maxNumberOfBranches = 5; + private long depth = 2; private long p_par = 80; private long p_add = 20; - private final Random random; - public DagTaskBuilder(long seed) { - random = new Random(seed); + public DagTaskBuilder() { } public double getBeta() { @@ -222,8 +219,7 @@ public class SystemSetup { } private long randomProbability() { - return random.nextInt(100); - // return ThreadLocalRandom.current().nextLong(0, 100); + return ThreadLocalRandom.current().nextLong(0, 100); } public Set generateTaskSet(final double totalUtilization) { @@ -327,20 +323,16 @@ public class SystemSetup { } private long randomTaskPeriod(final long criticalPathLength, final long workload) { - long upper = (long) (workload / getBeta()); - return random.nextInt((int) (upper - criticalPathLength)) + criticalPathLength; - // return ThreadLocalRandom.current().nextLong(criticalPathLength, - // (long) (workload / getBeta())); + return ThreadLocalRandom.current().nextLong(criticalPathLength, + (long) (workload / getBeta())); } private long randomNumberOfBranches() { - return random.nextInt((int) maxNumberOfBranches - 2) + 2; - // return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches); + return ThreadLocalRandom.current().nextLong(2, maxNumberOfBranches); } private long randomWcet() { - return random.nextInt((int) (maximumWcet - minimumWcet)) + minimumWcet; - // return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet); + return ThreadLocalRandom.current().nextLong(minimumWcet, maximumWcet); } /** diff --git a/src/main/java/mvd/jester/tests/FonsecaNelis.java b/src/main/java/mvd/jester/tests/FonsecaNelis.java index e83ed7c..6074a0b 100644 --- a/src/main/java/mvd/jester/tests/FonsecaNelis.java +++ b/src/main/java/mvd/jester/tests/FonsecaNelis.java @@ -233,6 +233,10 @@ public class FonsecaNelis extends AbstractTest { final long totalInterference = (long) Math.floor(taskInterference + selfInterference); responseTime = criticalPath + totalInterference; + // TODO: remove check of deadline if bug is found + if (responseTime > task.getDeadline()) { + return responseTime; + } } while (responseTime != previousResponseTime); return responseTime; @@ -262,10 +266,10 @@ public class FonsecaNelis extends AbstractTest { long workload = getCarryOutWorkload(task, carryOutDistribution, carryInAndOutPeriod); long carryInPeriod = task.getPeriod() - responseTimes.get(task).getResponseTime(); long carryOutPeriod = 0; - final List carryInList = Lists.newArrayList(carryInDistribution); - Collections.reverse(carryInList); + final List reverseCarryInList = Lists.newArrayList(carryInDistribution); + Collections.reverse(reverseCarryInList); - for (final Segment s : carryInList) { + for (final Segment s : reverseCarryInList) { carryInPeriod += s.getJobWcet(); carryOutPeriod = carryInAndOutPeriod - carryInPeriod; final long carryInWorkload = @@ -323,11 +327,11 @@ public class FonsecaNelis extends AbstractTest { final long responseTime = responseTimes.get(task).getResponseTime(); final List distributionList = Lists.newArrayList(carryInDistribution); - for (int i = 0; i < carryInDistribution.size(); ++i) { - final Segment s = distributionList.get(i); + for (int b = 0; b < carryInDistribution.size(); ++b) { + final Segment s = distributionList.get(b); long weightOfRemainingSegments = 0; - for (int j = i + 1; j < carryInDistribution.size(); ++j) { - weightOfRemainingSegments += distributionList.get(j).getJobWcet(); + for (int p = b + 1; p < carryInDistribution.size(); ++p) { + weightOfRemainingSegments += distributionList.get(p).getJobWcet(); } final long width = carryInPeriod - period + responseTime - weightOfRemainingSegments; diff --git a/src/main/java/mvd/jester/utils/DagUtils.java b/src/main/java/mvd/jester/utils/DagUtils.java index 0af8249..8b1c76f 100644 --- a/src/main/java/mvd/jester/utils/DagUtils.java +++ b/src/main/java/mvd/jester/utils/DagUtils.java @@ -13,7 +13,7 @@ import com.google.common.collect.Sets; import org.jgrapht.Graphs; import org.jgrapht.experimental.dag.DirectedAcyclicGraph; import org.jgrapht.graph.DefaultEdge; -import org.jgrapht.traverse.ClosestFirstIterator; +import org.jgrapht.traverse.TopologicalOrderIterator; import mvd.jester.model.Job; import mvd.jester.model.Segment; import mvd.jester.utils.BinaryDecompositionTree.Node; @@ -32,10 +32,6 @@ public class DagUtils { public static long calculateCriticalPath(final DirectedAcyclicGraph jobDag) { long criticalPath = 0; - // BreadthFirstIterator breadthFirstIterator = - // new BreadthFirstIterator<>(jobDag); - // while (breadthFirstIterator.hasNext()) { - // Job job = breadthFirstIterator.next(); for (final Job job : jobDag) { final Set edges = jobDag.incomingEdgesOf(job); long longestRelativeCompletionTime = 0; @@ -110,10 +106,11 @@ public class DagUtils { private static LinkedList getUnvisitedJoinNodes( final DirectedAcyclicGraph jobDag, final Set visitedJobs) { final LinkedList joinNodes = new LinkedList<>(); - final ClosestFirstIterator it = new ClosestFirstIterator<>(jobDag); + final TopologicalOrderIterator it = + new TopologicalOrderIterator<>(jobDag); for (; it.hasNext();) { final Job j = it.next(); - if (jobDag.inDegreeOf(j) > 1 && /* /* !j.getVisited() */!visitedJobs.contains(j)) { + if (jobDag.inDegreeOf(j) > 1 && !visitedJobs.contains(j)) { joinNodes.add(j); } } @@ -139,16 +136,11 @@ public class DagUtils { } final Job joinNode = joins.getFirst(); visitedJobs.add(joinNode); - joinNode.setVisited(true); nextEdge: while (modifiedJobDag.inDegreeOf(joinNode) > 1) { final List predecessors = Graphs.predecessorListOf(modifiedJobDag, joinNode); for (final Job p : predecessors) { if (!checkPredecessors(modifiedJobDag, joinNode, p)) { - // || !checkPredecessors(modifiedJobDag, p, joinNode, ancestorsOfJ)) { - // DefaultEdge e = modifiedJobDag.getEdge(p, joinNode); - // if ((modifiedJobDag.outDegreeOf(p) > 1) - // || checkForFork(modifiedJobDag, joinNode, e)) { final DefaultEdge conflictingEdge = modifiedJobDag.getEdge(p, joinNode); modifiedJobDag.removeEdge(conflictingEdge); if (modifiedJobDag.outDegreeOf(p) == 0) { @@ -169,66 +161,11 @@ public class DagUtils { } - public static boolean checkForFork(final DirectedAcyclicGraph jobDag, - final Job joinNode, final DefaultEdge edge) { - Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); - - nextFork: for (final Job f : jobDag) { - if (jobDag.outDegreeOf(f) > 1) { - final Set descendantsOfF = jobDag.getDescendants(jobDag, f); - final Set inbetweenJobs = new HashSet<>(ancestorsOfJ); - inbetweenJobs.retainAll(descendantsOfF); - if (inbetweenJobs.isEmpty()) { - continue; - } - - for (final Job a : inbetweenJobs) { - final List neighboursOfA = Graphs.neighborListOf(jobDag, a); - for (final Job b : neighboursOfA) { - if (!((jobDag.getAncestors(jobDag, joinNode).contains(b) || b == joinNode) - && (jobDag.getDescendants(jobDag, f).contains(b) || b == f))) { - continue nextFork; - } - } - } - - Job source = jobDag.getEdgeSource(edge); - if (inbetweenJobs.contains(source)) { - return true; - } - } - } - - return false; - } - - private static boolean checkPredecessors(final DirectedAcyclicGraph jobDag, - final Job current, final Job joinNode, final Set ancestorsOfJ2) { - final List successorsOfCurrent = Graphs.successorListOf(jobDag, current); - final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); - ancestorsOfJ.add(joinNode); - if (ancestorsOfJ.containsAll(successorsOfCurrent)) { - final Set descendantsOfCurrent = jobDag.getDescendants(jobDag, current); - if (descendantsOfCurrent.containsAll(Graphs.predecessorListOf(jobDag, joinNode))) { - return true; - } else { - for (final Job p : Graphs.predecessorListOf(jobDag, current)) { - if (!checkPredecessors(jobDag, p, joinNode, ancestorsOfJ)) { - return false; - } - } - return true; - } - } else { - return false; - } - } - private static boolean checkPredecessors(final DirectedAcyclicGraph jobDag, final Job joinNode, Job current) { - final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); - ancestorsOfJ.add(joinNode); if (jobDag.outDegreeOf(current) > 1) { + final Set ancestorsOfJ = jobDag.getAncestors(jobDag, joinNode); + ancestorsOfJ.add(joinNode); if (!ancestorsOfJ.containsAll(Graphs.successorListOf(jobDag, current))) { return false; } diff --git a/src/test/java/mvd/jester/model/TestDagUtils.java b/src/test/java/mvd/jester/model/TestDagUtils.java index c5e88df..a22e20d 100644 --- a/src/test/java/mvd/jester/model/TestDagUtils.java +++ b/src/test/java/mvd/jester/model/TestDagUtils.java @@ -3,7 +3,6 @@ package mvd.jester.model; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; import java.util.Stack; -import java.util.concurrent.ThreadLocalRandom; import org.jgrapht.Graphs; import org.jgrapht.experimental.dag.DirectedAcyclicGraph; import org.jgrapht.graph.DefaultEdge; @@ -40,10 +39,7 @@ public class TestDagUtils { @DisplayName("Check if NFJ DAGs are created correctly.") void checkNfjDagCreation() { for (int i = 0; i < 10000; ++i) { - // { - // int i = 1992; - System.out.println(i); - DagTaskBuilder b = new DagTaskBuilder(i); + DagTaskBuilder b = new DagTaskBuilder(); DagTask t = b.generateTask(); DirectedAcyclicGraph nfjDag = DagUtils.createNFJGraph(t.getJobDag()); @@ -98,11 +94,11 @@ public class TestDagUtils { void checkDecompositionTreeCreation() { for (int i = 0; i < 10000; ++i) { // { - // int i = 847; + // int i = 610; // System.out.println(i); - long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16); - // long numberOfProcessors = 4; - DagTaskBuilder b = new DagTaskBuilder(i).setNumberOfProcessors(numberOfProcessors); + // long numberOfProcessors = ThreadLocalRandom.current().nextLong(4, 16); + long numberOfProcessors = 4; + DagTaskBuilder b = new DagTaskBuilder().setNumberOfProcessors(numberOfProcessors); DagTask t = b.generateTask(); DirectedAcyclicGraph jobDag = t.getJobDag(); DirectedAcyclicGraph nfjJobDag = DagUtils.createNFJGraph(jobDag); @@ -124,9 +120,9 @@ public class TestDagUtils { for (DefaultEdge e : nfjJobDag.edgeSet()) { Job target = nfjJobDag.getEdgeTarget(e); Job source = nfjJobDag.getEdgeSource(e); - // if (jobDagFromTree.containsEdge(source, target)) { - // drawGraph(jobDag); - // } + if (!jobDagFromTree.containsEdge(source, target)) { + drawGraph(jobDag); + } assertTrue(jobDagFromTree.containsEdge(source, target)); } diff --git a/src/test/java/mvd/jester/model/TestSystemSetup.java b/src/test/java/mvd/jester/model/TestSystemSetup.java index 08438f2..7648e4c 100644 --- a/src/test/java/mvd/jester/model/TestSystemSetup.java +++ b/src/test/java/mvd/jester/model/TestSystemSetup.java @@ -74,7 +74,7 @@ public class TestSystemSetup { @DisplayName("Check if DagTaskBuilder works correctly") void testDagTaskBuilder() { for (int i = 0; i < 100; ++i) { - DagTaskBuilder builder = new DagTaskBuilder(i); + DagTaskBuilder builder = new DagTaskBuilder(); DagTask task = builder.generateTask(); DirectedAcyclicGraph jobDag = task.getJobDag(); @@ -103,7 +103,7 @@ public class TestSystemSetup { void testUtil() { for (int i = 0; i < 5; ++i) { for (double d = 0.25; d < 4; d += 0.25) { - DagTaskBuilder builder = new DagTaskBuilder(i); + DagTaskBuilder builder = new DagTaskBuilder(); Set taskSet = builder.generateTaskSet(d); double taskSetUtil = 0; for (DagTask t : taskSet) { -- libgit2 0.26.0