Commit 8768d1a4 by Michael Schmid

minor changes, TestEnvironment modified for logging

parent 0232b488
......@@ -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);
......
......@@ -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);
......
......@@ -9,7 +9,7 @@ import mvd.jester.model.Task;
*/
public abstract class AbstractTest implements TestInterface {
protected Map<Task, Long> responseTimes;
protected final Map<Task, Long> responseTimes;
public AbstractTest() {
this.responseTimes = new HashMap<Task, Long>();
......
......@@ -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) {
......
......@@ -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;
}
......
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<AbstractTest, Long> testCases = new HashMap<>();
Set<AbstractTest> testCases = new HashSet<>();
Map<Long, Map<AbstractTest, Long>> results = new HashMap<>();
for (Constructor<? extends AbstractTest> 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<AbstractTest, Long>())
.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<AbstractTest> testCases,
Map<Long, Map<AbstractTest, Long>> 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<AbstractTest, Long> 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();
}
}
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) {
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment