Commit 0232b488 by Michael Schmid

terminated refactoring, looks good now

parent 59c46e2a
package mvd.jester; package mvd.jester;
import mvd.jester.model.Task;
import mvd.jester.model.SystemSetup; import mvd.jester.model.SystemSetup;
import mvd.jester.tests.MaiaBertogna; import mvd.jester.tests.MaiaBertogna;
import mvd.jester.tests.SchmidMottok; import mvd.jester.tests.SchmidMottok;
...@@ -12,8 +11,9 @@ import mvd.jester.tests.TestEnvironment; ...@@ -12,8 +11,9 @@ import mvd.jester.tests.TestEnvironment;
*/ */
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
SystemSetup.Builder generator = new SystemSetup.Builder().setNumberOfProcessors(4);
TestEnvironment te = new TestEnvironment(4000, 4); TestEnvironment te = new TestEnvironment(generator, 10000);
te.registerTestInterface(SchmidMottok.class); te.registerTestInterface(SchmidMottok.class);
te.registerTestInterface(MaiaBertogna.class); te.registerTestInterface(MaiaBertogna.class);
......
...@@ -25,7 +25,7 @@ public class SystemSetup { ...@@ -25,7 +25,7 @@ public class SystemSetup {
return tasks; return tasks;
} }
public void setSortedTaskSet(SortedTaskSet tasks) { public void setTasks(SortedTaskSet tasks) {
this.tasks = tasks; this.tasks = tasks;
} }
...@@ -45,7 +45,7 @@ public class SystemSetup { ...@@ -45,7 +45,7 @@ public class SystemSetup {
return utilization; return utilization;
} }
public static class Generator { public static class Builder {
private long numberOfProcessors = 4; private long numberOfProcessors = 4;
private long minPeriod = 100; private long minPeriod = 100;
private long maxPeriod = 1000; private long maxPeriod = 1000;
...@@ -57,7 +57,7 @@ public class SystemSetup { ...@@ -57,7 +57,7 @@ public class SystemSetup {
private long ratio = randomTaskRatio(); private long ratio = randomTaskRatio();
private PriorityManager priorityManager = new RateMonotonic(); private PriorityManager priorityManager = new RateMonotonic();
public Generator() { public Builder() {
} }
...@@ -119,33 +119,36 @@ public class SystemSetup { ...@@ -119,33 +119,36 @@ public class SystemSetup {
return new SystemSetup(taskSet, numberOfProcessors); return new SystemSetup(taskSet, numberOfProcessors);
} }
public void addTask(SystemSetup taskSet) { public void rebuild(SystemSetup systemSetup) {
taskSet.tasks.add(generateTask()); this.ratio = randomTaskRatio();
systemSetup.tasks = generateTaskSet();
} }
/** public void addTask(SystemSetup systemSetup) {
* @param numberOfProcessors the numberOfProcessors to set systemSetup.tasks.add(generateTask());
*/
public void setNumberOfProcessors(long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
} }
public Builder setNumberOfProcessors(long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
return this;
}
public Generator setNumberOfSegments(long minNumberOfSegments, long maxNumberOfSegments) { public Builder setNumberOfSegments(long minNumberOfSegments, long maxNumberOfSegments) {
this.minNumberOfSegments = minNumberOfSegments; this.minNumberOfSegments = minNumberOfSegments;
this.maxNumberOfSegments = maxNumberOfSegments; this.maxNumberOfSegments = maxNumberOfSegments;
return this; return this;
} }
public Generator setPeriods(long minPeriod, long maxPeriod) { public Builder setPeriods(long minPeriod, long maxPeriod) {
this.minPeriod = minPeriod; this.minPeriod = minPeriod;
this.maxPeriod = maxPeriod; this.maxPeriod = maxPeriod;
return this; return this;
} }
public Generator setPriorityManager(PriorityManager priorityManager) { public Builder setPriorityManager(PriorityManager priorityManager) {
this.priorityManager = priorityManager; this.priorityManager = priorityManager;
return this; return this;
} }
...@@ -153,7 +156,7 @@ public class SystemSetup { ...@@ -153,7 +156,7 @@ public class SystemSetup {
/** /**
* @param maxNumberOfJobs the maxNumberOfJobs to set * @param maxNumberOfJobs the maxNumberOfJobs to set
*/ */
public Generator setNumberOfJobs(long minNumberOfJobs, long maxNumberOfJobs) { public Builder setNumberOfJobs(long minNumberOfJobs, long maxNumberOfJobs) {
this.minNumberOfJobs = minNumberOfJobs; this.minNumberOfJobs = minNumberOfJobs;
this.maxNumberOfJobs = maxNumberOfJobs; this.maxNumberOfJobs = maxNumberOfJobs;
return this; return this;
......
...@@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup; ...@@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup;
*/ */
public class MaiaBertogna extends AbstractTest { public class MaiaBertogna extends AbstractTest {
private SystemSetup systemSetup; private final SystemSetup systemSetup;
public MaiaBertogna() { public MaiaBertogna(SystemSetup systemSetup) {
this.systemSetup = systemSetup;
} }
@Override @Override
public boolean runSchedulabilityCheck(SystemSetup systemSetup) { public boolean runSchedulabilityCheck() {
responseTimes.clear(); responseTimes.clear();
this.systemSetup = systemSetup;
for (Task t : systemSetup.getTasks()) { for (Task t : systemSetup.getTasks()) {
responseTimes.put(t, calculateResponseTime(t)); responseTimes.put(t, calculateResponseTime(t));
} }
......
...@@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup; ...@@ -12,15 +12,15 @@ import mvd.jester.model.SystemSetup;
*/ */
public class SchmidMottok extends AbstractTest { public class SchmidMottok extends AbstractTest {
private SystemSetup systemSetup; private final SystemSetup systemSetup;
public SchmidMottok() { public SchmidMottok(SystemSetup systemSetup) {
this.systemSetup = systemSetup;
} }
@Override @Override
public boolean runSchedulabilityCheck(SystemSetup systemSetup) { public boolean runSchedulabilityCheck() {
responseTimes.clear(); responseTimes.clear();
this.systemSetup = systemSetup;
for (Task t : systemSetup.getTasks()) { for (Task t : systemSetup.getTasks()) {
responseTimes.put(t, calculateResponseTime(t)); responseTimes.put(t, calculateResponseTime(t));
} }
...@@ -56,7 +56,7 @@ public class SchmidMottok extends AbstractTest { ...@@ -56,7 +56,7 @@ public class SchmidMottok extends AbstractTest {
} }
} }
double taskInterference = (double) interference / 4; double taskInterference = (double) interference / systemSetup.getNumberOfProcessors();
double selfInterference = getSelfInterference(task); double selfInterference = getSelfInterference(task);
long totalInterference = (long) Math.floor(taskInterference + selfInterference); long totalInterference = (long) Math.floor(taskInterference + selfInterference);
...@@ -71,11 +71,13 @@ public class SchmidMottok extends AbstractTest { ...@@ -71,11 +71,13 @@ public class SchmidMottok extends AbstractTest {
private double getSelfInterference(Task task) { private double getSelfInterference(Task task) {
double interference = 0; double interference = 0;
long numberOfProcessors = systemSetup.getNumberOfProcessors();
for (Segment s : task.getSegments()) { for (Segment s : task.getSegments()) {
long processingUnits = s.getNumberOfJobs() > 4 ? 4 : s.getNumberOfJobs(); long numberOfJobs = s.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors
: s.getNumberOfJobs();
interference += interference +=
(double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet() / processingUnits; (double) (s.getNumberOfTasklets() - 1) * s.getTaskletWcet() / numberOfJobs;
} }
return interference; return interference;
......
...@@ -5,7 +5,6 @@ import java.util.HashMap; ...@@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SystemSetup; import mvd.jester.model.SystemSetup;
/** /**
...@@ -14,17 +13,24 @@ import mvd.jester.model.SystemSetup; ...@@ -14,17 +13,24 @@ import mvd.jester.model.SystemSetup;
public class TestEnvironment { public class TestEnvironment {
private final long numberOfTaskSets; private final long numberOfTaskSets;
private final long numberOfProcessors; private final SystemSetup systemSetup;
private final Set<Class<? extends AbstractTest>> abstractTests; private final SystemSetup.Builder builder;
private final Set<Constructor<? extends AbstractTest>> abstractTests;
public TestEnvironment(long numberOfTaskSets, long numberOfProcessors) { public TestEnvironment(SystemSetup.Builder builder, long numberOfTaskSets) {
this.numberOfTaskSets = numberOfTaskSets; this.numberOfTaskSets = numberOfTaskSets;
this.numberOfProcessors = numberOfProcessors;
abstractTests = new HashSet<>(); abstractTests = new HashSet<>();
this.builder = builder;
this.systemSetup = builder.build();
} }
public TestEnvironment registerTestInterface(Class<? extends AbstractTest> abstractTest) { public TestEnvironment registerTestInterface(Class<? extends AbstractTest> abstractTest) {
abstractTests.add(abstractTest); try {
abstractTests.add(abstractTest.getConstructor(SystemSetup.class));
} catch (Exception e) {
System.out.println("Missing constructor!");
}
return this; return this;
} }
...@@ -32,9 +38,9 @@ public class TestEnvironment { ...@@ -32,9 +38,9 @@ public class TestEnvironment {
public void runTests() { public void runTests() {
Map<AbstractTest, Long> testCases = new HashMap<>(); Map<AbstractTest, Long> testCases = new HashMap<>();
for (Class<? extends AbstractTest> t : abstractTests) { for (Constructor<? extends AbstractTest> t : abstractTests) {
try { try {
testCases.put(t.newInstance(), (long) 0); testCases.put(t.newInstance(this.systemSetup), (long) 0);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Ahhh SHIT!"); System.out.println("Ahhh SHIT!");
} }
...@@ -43,24 +49,23 @@ public class TestEnvironment { ...@@ -43,24 +49,23 @@ public class TestEnvironment {
long checkedTasksets = 0; long checkedTasksets = 0;
while (checkedTasksets < 4000) { while (checkedTasksets < numberOfTaskSets) {
SystemSetup.Generator generator = new SystemSetup.Generator(); builder.rebuild(this.systemSetup);
SystemSetup systemSetup = generator.build();
double utilization = systemSetup.getUtilization(); double utilization = this.systemSetup.getUtilization();
while (utilization <= systemSetup.getNumberOfProcessors() while (utilization <= this.systemSetup.getNumberOfProcessors()
&& checkedTasksets < numberOfTaskSets) { && checkedTasksets < numberOfTaskSets) {
checkedTasksets++; checkedTasksets++;
for (AbstractTest t : testCases.keySet()) { for (AbstractTest t : testCases.keySet()) {
if (t.runSchedulabilityCheck(systemSetup)) { if (t.runSchedulabilityCheck()) {
testCases.computeIfPresent(t, (k, v) -> v + 1); testCases.computeIfPresent(t, (k, v) -> v + 1);
} }
} }
generator.addTask(systemSetup); builder.addTask(systemSetup);
utilization = systemSetup.getUtilization(); utilization = this.systemSetup.getUtilization();
} }
} }
......
package mvd.jester.tests; package mvd.jester.tests;
import mvd.jester.model.SystemSetup;
/** /**
* TestInterface * TestInterface
*/ */
public interface TestInterface { public interface TestInterface {
public boolean runSchedulabilityCheck(SystemSetup systemSetup); public boolean runSchedulabilityCheck();
public String getName(); public String getName();
......
...@@ -14,7 +14,7 @@ public class TaskSetTest { ...@@ -14,7 +14,7 @@ public class TaskSetTest {
public void testRandomTaskSetGeneration() { public void testRandomTaskSetGeneration() {
for (int i = 0; i < NUMBER_OF_SETS; ++i) { for (int i = 0; i < NUMBER_OF_SETS; ++i) {
SystemSetup taskSet = new SystemSetup.Generator().build(); SystemSetup taskSet = new SystemSetup.Builder().build();
for (Task t : taskSet.getTasks()) { for (Task t : taskSet.getTasks()) {
assertTrue(t.getPeriod() >= 100); assertTrue(t.getPeriod() >= 100);
......
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