From 8768d1a45fe2ca2854206254ba2e0386e3f477ca Mon Sep 17 00:00:00 2001 From: Michael Schmid Date: Mon, 15 Jul 2019 12:49:08 +0200 Subject: [PATCH] minor changes, TestEnvironment modified for logging --- src/main/java/mvd/jester/App.java | 4 ++-- src/main/java/mvd/jester/model/SystemSetup.java | 8 ++++++-- src/main/java/mvd/jester/tests/AbstractTest.java | 2 +- src/main/java/mvd/jester/tests/MaiaBertogna.java | 42 +++++++++++++++++++++++------------------- src/main/java/mvd/jester/tests/SchmidMottok.java | 9 +++++---- src/main/java/mvd/jester/tests/TestEnvironment.java | 47 +++++++++++++++++++++++++++++++++++++++-------- src/main/java/mvd/jester/utils/Logger.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 36 deletions(-) create mode 100644 src/main/java/mvd/jester/utils/Logger.java diff --git a/src/main/java/mvd/jester/App.java b/src/main/java/mvd/jester/App.java index 2edd6d3..9cf2331 100644 --- a/src/main/java/mvd/jester/App.java +++ b/src/main/java/mvd/jester/App.java @@ -11,9 +11,9 @@ import mvd.jester.tests.TestEnvironment; */ public class App { public static void main(String[] args) { - SystemSetup.Builder generator = new SystemSetup.Builder().setNumberOfProcessors(4); + SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8); - TestEnvironment te = new TestEnvironment(generator, 10000); + TestEnvironment te = new TestEnvironment(builder, 40000); te.registerTestInterface(SchmidMottok.class); te.registerTestInterface(MaiaBertogna.class); diff --git a/src/main/java/mvd/jester/model/SystemSetup.java b/src/main/java/mvd/jester/model/SystemSetup.java index fb72d65..4cf81ff 100644 --- a/src/main/java/mvd/jester/model/SystemSetup.java +++ b/src/main/java/mvd/jester/model/SystemSetup.java @@ -74,6 +74,7 @@ public class SystemSetup { } private long randomNumberOfJobs() { + this.maxNumberOfJobs = 3 * this.numberOfProcessors / 2; return ThreadLocalRandom.current().nextLong(minNumberOfJobs, maxNumberOfJobs); } @@ -93,10 +94,13 @@ public class SystemSetup { } else { numberOfSegments = 1; } + long parallelNumberOfJobs = serial ? 1 : randomNumberOfJobs(); for (int i = 0; i < numberOfSegments; ++i) { - serial = i % 2 == 0; + long numberOfJobs = 1; + if (i % 2 == 1) { + numberOfJobs = parallelNumberOfJobs; + } long wcet = randomWcet(period, numberOfSegments); - long numberOfJobs = serial ? 1 : randomNumberOfJobs(); segments.add(new Segment(wcet, numberOfJobs)); } return new Task(period, segments); diff --git a/src/main/java/mvd/jester/tests/AbstractTest.java b/src/main/java/mvd/jester/tests/AbstractTest.java index 1614be2..c75bf40 100644 --- a/src/main/java/mvd/jester/tests/AbstractTest.java +++ b/src/main/java/mvd/jester/tests/AbstractTest.java @@ -9,7 +9,7 @@ import mvd.jester.model.Task; */ public abstract class AbstractTest implements TestInterface { - protected Map responseTimes; + protected final Map responseTimes; public AbstractTest() { this.responseTimes = new HashMap(); diff --git a/src/main/java/mvd/jester/tests/MaiaBertogna.java b/src/main/java/mvd/jester/tests/MaiaBertogna.java index edffae3..96b1483 100644 --- a/src/main/java/mvd/jester/tests/MaiaBertogna.java +++ b/src/main/java/mvd/jester/tests/MaiaBertogna.java @@ -46,19 +46,18 @@ public class MaiaBertogna extends AbstractTest { do { previousResponseTime = responseTime; - long interference = 0; + long taskInterference = 0; for (Task t : systemSetup.getTasks()) { if (t.getPeriod() < task.getPeriod()) { long maxNumberOfJobsOfT = t.getMaximumParallelism(); for (int p = 0; p < maxNumberOfJobsOfT; ++p) { - interference += Math.min(getTaskInterference(t, responseTime, p + 1), + taskInterference += Math.min(getTaskInterference(t, responseTime, p + 1), responseTime - minimumWcet + 1); } } } - double taskInterference = (double) interference / systemSetup.getNumberOfProcessors(); long selfInterference = 0; long maxNumberOfJobs = task.getMaximumParallelism(); @@ -67,7 +66,8 @@ public class MaiaBertogna extends AbstractTest { Math.min(getSelfInterference(task, p + 1), responseTime - minimumWcet + 1); } - long totalInterference = (long) Math.floor(taskInterference + selfInterference); + long totalInterference = LongMath.divide(taskInterference + selfInterference, + systemSetup.getNumberOfProcessors(), RoundingMode.FLOOR); responseTime = minimumWcet + totalInterference; } while (previousResponseTime != responseTime); @@ -89,24 +89,28 @@ public class MaiaBertogna extends AbstractTest { } private long getTaskInterference(Task task, long interval, long parallelism) { - long responseTime = responseTimes.get(task); - long minWcet = getMinimumWcet(task); - long period = task.getPeriod(); - long numberOfJobs = - (LongMath.divide(interval + responseTime - minWcet, period, RoundingMode.FLOOR) - + 1); - - long workload = 0; - - for (Segment s : task.getSegments()) { - if (s.getNumberOfJobs() >= parallelism) { - workload += s.getJobWcet(); + if (responseTimes.containsKey(task)) { + long responseTime = responseTimes.get(task); + long minWcet = getMinimumWcet(task); + long period = task.getPeriod(); + long numberOfJobs = + (LongMath.divide(interval + responseTime - minWcet, period, RoundingMode.FLOOR) + + 1); + + long workload = 0; + + for (Segment s : task.getSegments()) { + if (s.getNumberOfJobs() >= parallelism) { + workload += s.getJobWcet(); + } } - } - long interference = numberOfJobs * workload; + long interference = numberOfJobs * workload; - return interference; + return interference; + } else { + throw new RuntimeException("Task was not found in task set!"); + } } private long getMinimumWcet(Task task) { diff --git a/src/main/java/mvd/jester/tests/SchmidMottok.java b/src/main/java/mvd/jester/tests/SchmidMottok.java index 1aedfe5..62d2d84 100644 --- a/src/main/java/mvd/jester/tests/SchmidMottok.java +++ b/src/main/java/mvd/jester/tests/SchmidMottok.java @@ -72,14 +72,15 @@ public class SchmidMottok extends AbstractTest { private double getSelfInterference(Task task) { double interference = 0; long numberOfProcessors = systemSetup.getNumberOfProcessors(); + long numberOfJobs = task.getMaximumParallelism() > numberOfProcessors ? numberOfProcessors + : task.getMaximumParallelism(); for (Segment s : task.getSegments()) { - long numberOfJobs = s.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors - : s.getNumberOfJobs(); - interference += - (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet() / numberOfJobs; + interference += (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet(); } + interference /= numberOfJobs; + return interference; } diff --git a/src/main/java/mvd/jester/tests/TestEnvironment.java b/src/main/java/mvd/jester/tests/TestEnvironment.java index fc60f2a..f239787 100644 --- a/src/main/java/mvd/jester/tests/TestEnvironment.java +++ b/src/main/java/mvd/jester/tests/TestEnvironment.java @@ -1,11 +1,13 @@ package mvd.jester.tests; import java.lang.reflect.Constructor; +import java.time.LocalTime; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import mvd.jester.model.SystemSetup; +import mvd.jester.utils.Logger; /** * TestEnvironment @@ -36,17 +38,18 @@ public class TestEnvironment { } public void runTests() { - Map testCases = new HashMap<>(); + Set testCases = new HashSet<>(); + + Map> results = new HashMap<>(); for (Constructor t : abstractTests) { try { - testCases.put(t.newInstance(this.systemSetup), (long) 0); + testCases.add(t.newInstance(this.systemSetup)); } catch (Exception e) { System.out.println("Ahhh SHIT!"); } } - long checkedTasksets = 0; while (checkedTasksets < numberOfTaskSets) { @@ -58,9 +61,13 @@ public class TestEnvironment { && checkedTasksets < numberOfTaskSets) { checkedTasksets++; - for (AbstractTest t : testCases.keySet()) { + long roundedUtilization = (long) (utilization * 10); + + for (AbstractTest t : testCases) { if (t.runSchedulabilityCheck()) { - testCases.computeIfPresent(t, (k, v) -> v + 1); + results.computeIfAbsent(roundedUtilization, + k -> new HashMap()) + .compute(t, (k, v) -> (v == null) ? 1 : v + 1); } } builder.addTask(systemSetup); @@ -69,12 +76,36 @@ public class TestEnvironment { } } + logResults(testCases, results); + } + + private void logResults(Set testCases, + Map> results) { + LocalTime date = LocalTime.now(); + Logger log = new Logger("results_" + systemSetup.getNumberOfProcessors() + "_" + + date.getHour() + ":" + date.getMinute() + ".txt"); + String firstLine = new String("Utilization"); - for (AbstractTest t : testCases.keySet()) { - System.out.println("Testcase " + t.getName() + " scheduled " + testCases.get(t) + " of " - + numberOfTaskSets + " tasks!"); + for (AbstractTest t : testCases) { + firstLine = firstLine + "\t" + t.getName(); } + log.log(firstLine); + + for (Long util : results.keySet()) { + String line = String.valueOf((double) util / 10); + Map tests = results.get(util); + + for (AbstractTest t : testCases) { + if (tests.containsKey(t)) { + line += "\t" + tests.get(t); + } else { + line += "\t" + "0"; + } + } + log.log(line); + } + log.finalize(); } } diff --git a/src/main/java/mvd/jester/utils/Logger.java b/src/main/java/mvd/jester/utils/Logger.java new file mode 100644 index 0000000..4ed0e93 --- /dev/null +++ b/src/main/java/mvd/jester/utils/Logger.java @@ -0,0 +1,46 @@ +package mvd.jester.utils; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.PrintWriter; + +/** + * Logger + */ +public class Logger { + + private FileWriter fileWriter; + private BufferedWriter bufferedWriter; + private PrintWriter printWriter; + + public Logger(String pathToFile) { + try { + fileWriter = new FileWriter(pathToFile, true); + bufferedWriter = new BufferedWriter(fileWriter); + printWriter = new PrintWriter(bufferedWriter); + } catch (Exception e) { + System.out.println("Could not create file!"); + } + } + + + public void log(String line) { + printWriter.println(line); + } + + public void finalize() { + try { + if (printWriter != null) { + printWriter.close(); // Will close bw and fw too + } + if (bufferedWriter != null) { + bufferedWriter.close(); // Will close fw too + } + if (fileWriter != null) { + fileWriter.close(); + } + } catch (Exception e) { + } + } + +} -- libgit2 0.26.0