Commit 39635336 by Michael Schmid

Integrated builder into manager

parent eb53dcfb
......@@ -23,34 +23,33 @@ import mvd.jester.tests.TypeFunction.UnkownStructure;
*/
public class App {
public static void main(String[] args) {
// {
// SystemManager manager = new SystemManager(8);
// DagTaskBuilder builder = new DagTaskBuilder();
// TestEnvironment te = new TestEnvironment();
{
SystemManager<DagTaskBuilder> manager = new SystemManager<>(DagTaskBuilder.class);
TestEnvironment te = new TestEnvironment();
// // SchmidMottok sm = new SchmidMottok(new KnownStructure(), manager);
// // JiangYi jy = new JiangYi(manager);
// SchmidMottok sm = new SchmidMottok(new KnownStructure(), manager);
// JiangYi jy = new JiangYi(manager);
// // Set<DagTask> set = builder.generateRenyiTaskSet(7.0);
// // final SortedTaskSet<DagTask> rmTasks = new SortedTaskSet<>(sm.getPriorityManager());
// // rmTasks.addAll(set);
// Set<DagTask> set = builder.generateRenyiTaskSet(7.0);
// final SortedTaskSet<DagTask> rmTasks = new SortedTaskSet<>(sm.getPriorityManager());
// rmTasks.addAll(set);
// // final SortedTaskSet<DagTask> edfTasks = new SortedTaskSet<>(jy.getPriorityManager());
// // edfTasks.addAll(set);
// final SortedTaskSet<DagTask> edfTasks = new SortedTaskSet<>(jy.getPriorityManager());
// edfTasks.addAll(set);
// // jy.runSchedulabilityCheck(edfTasks);
// // sm.runSchedulabilityCheck(rmTasks);
// jy.runSchedulabilityCheck(edfTasks);
// sm.runSchedulabilityCheck(rmTasks);
// List<AbstractTest<DagTask>> tests = te.registerTests(Arrays.asList(
// new SchmidMottok(new KnownStructureWithMaxThreads(manager), manager),
// new SchmidMottok(new KnownStructure(), manager),
// // new MelaniButtazzo(manager),
// // new FonsecaNelis(manager),
// new JiangYi(manager)));
List<AbstractTest<DagTask>> tests = te.registerTests(Arrays.asList(
new SchmidMottok(new KnownStructureWithMaxThreads(manager), manager),
new SchmidMottok(new KnownStructure(), manager),
// new MelaniButtazzo(manager),
// new FonsecaNelis(manager),
new JiangYi(manager)));
// te.varyRenyiUtilization(builder, tests, 8, 500);
// }
te.varyRenyiUtilization(manager, tests, 500);
}
// {
// SystemManager manager = new SystemManager(8);
// DagTaskBuilder builder = new DagTaskBuilder();
......
......@@ -78,15 +78,15 @@ public class TestEnvironment {
// resultLogger.logTests(abstractTestInstances);
}
public void measureExecutionTimes(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, SystemManager manager,
public void measureExecutionTimes(final SystemManager<DagTaskBuilder> manager,
final List<AbstractTest<DagTask>> abstractTestInstances,
final long numberOfMeasurements) {
Map<AbstractTest<DagTask>, List<Long>> results = new LinkedHashMap<>();
abstractTestInstances.forEach(t -> results.put(t, new ArrayList<>()));
for (int i = 0; i < numberOfMeasurements; ++i) {
double utilization =
ThreadLocalRandom.current().nextDouble(1, manager.getNumberOfProcessors());
Set<DagTask> taskSet = builder.generateTaskSet(utilization);
Set<DagTask> taskSet = manager.getBuilder().generateTaskSet(utilization);
for (AbstractTest<DagTask> testInstance : abstractTestInstances) {
final PriorityManager priorityManager = testInstance.getPriorityManager();
......@@ -108,8 +108,8 @@ public class TestEnvironment {
}
public void varyNumberOfProcessors(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, SystemManager manager,
public void varyNumberOfProcessors(final SystemManager<DagTaskBuilder> manager,
final List<AbstractTest<DagTask>> abstractTestInstances,
final long numberOfTaskSetsPerStep) {
long checkedTasksets = 0;
final long numberOfTaskSets = 8 * numberOfTaskSetsPerStep;
......@@ -123,7 +123,7 @@ public class TestEnvironment {
manager.setNumberOfProcessors(numberOfProcessors);
resultMap.replaceAll((k, v) -> (long) 0);
for (int i = 0; i < numberOfTaskSetsPerStep; ++i) {
final Set<DagTask> taskSet = builder.generateUUnifastTaskSet(
final Set<DagTask> taskSet = manager.getBuilder().generateUUnifastTaskSet(
(long) (1.5 * numberOfProcessors), (double) numberOfProcessors * 0.5);
System.out.print(checkedTasksets + "/" + numberOfTaskSets + " tasksets tested!\r");
......@@ -150,10 +150,11 @@ public class TestEnvironment {
}
public void varyNumberOfTasks(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, final long numberOfProcessors,
public void varyNumberOfTasks(final SystemManager<DagTaskBuilder> manager,
final List<AbstractTest<DagTask>> abstractTestInstances,
final long numberOfTaskSetsPerStep) {
long checkedTasksets = 0;
final long numberOfProcessors = manager.getNumberOfProcessors();
final long numberOfTaskSets = 9 * numberOfTaskSetsPerStep;
final ResultLogger resultLogger = new ResultLogger("numberOfTasks_" + numberOfProcessors);
......@@ -164,8 +165,8 @@ public class TestEnvironment {
for (long numberOfTasks = 4; numberOfTasks <= 20; numberOfTasks += 2) {
resultMap.replaceAll((k, v) -> (long) 0);
for (int i = 0; i < numberOfTaskSetsPerStep; ++i) {
final Set<DagTask> taskSet = builder.generateUUnifastTaskSet(numberOfTasks,
(double) numberOfProcessors * 0.5);
final Set<DagTask> taskSet = manager.getBuilder()
.generateUUnifastTaskSet(numberOfTasks, (double) numberOfProcessors * 0.5);
System.out.print(checkedTasksets + "/" + numberOfTaskSets + " tasksets tested!\r");
for (final AbstractTest<DagTask> testInstance : abstractTestInstances) {
......@@ -190,10 +191,10 @@ public class TestEnvironment {
resultLogger.finalize();
}
public void varyUtilization(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, final long numberOfProcessors,
public void varyUtilization(final SystemManager<DagTaskBuilder> manager,
final List<AbstractTest<DagTask>> abstractTestInstances,
final long numberOfTaskSetsPerUtil) {
final long numberOfProcessors = manager.getNumberOfProcessors();
long checkedTasksets = 0;
final long numberOfTaskSets = ((numberOfProcessors * 4) - 3) * numberOfTaskSetsPerUtil;
......@@ -205,7 +206,7 @@ public class TestEnvironment {
for (double util = 1; util <= numberOfProcessors; util += 0.25) {
resultMap.replaceAll((k, v) -> (long) 0);
for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) {
final Set<DagTask> taskSet = builder.generateTaskSet(util);
final Set<DagTask> taskSet = manager.getBuilder().generateTaskSet(util);
System.out.print(checkedTasksets + "/" + numberOfTaskSets + " tasksets tested!\r");
for (final AbstractTest<DagTask> testInstance : abstractTestInstances) {
......@@ -230,10 +231,10 @@ public class TestEnvironment {
resultLogger.finalize();
}
public void varyRenyiUtilization(final DagTaskBuilder builder,
final List<AbstractTest<DagTask>> abstractTestInstances, final long numberOfProcessors,
public void varyRenyiUtilization(final SystemManager<DagTaskBuilder> manager,
final List<AbstractTest<DagTask>> abstractTestInstances,
final long numberOfTaskSetsPerUtil) {
final long numberOfProcessors = manager.getNumberOfProcessors();
long checkedTasksets = 0;
final long numberOfTaskSets = ((numberOfProcessors * 4) - 3) * numberOfTaskSetsPerUtil;
......@@ -242,10 +243,10 @@ public class TestEnvironment {
abstractTestInstances.forEach(t -> resultMap.put(t, (long) 0));
resultLogger.logHeader(resultMap, "Utilization");
for (double util = 5; util <= numberOfProcessors; util += 0.25) {
for (double util = 1; util <= numberOfProcessors; util += 0.25) {
resultMap.replaceAll((k, v) -> (long) 0);
for (int i = 0; i < numberOfTaskSetsPerUtil; ++i) {
final Set<DagTask> taskSet = builder.generateRenyiTaskSet(util);
final Set<DagTask> taskSet = manager.getBuilder().generateRenyiTaskSet(util);
System.out.print(checkedTasksets + "/" + numberOfTaskSets + " tasksets tested!\r");
for (final AbstractTest<DagTask> testInstance : abstractTestInstances) {
......
......@@ -14,32 +14,50 @@ import org.apache.commons.math3.distribution.GammaDistribution;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
import mvd.jester.utils.DagUtils;
import mvd.jester.model.SystemManager.Builder;
/**
* TaskSet
*/
public class SystemManager {
private long numberOfProcessors;
public class SystemManager<T extends Builder> implements SystemManagerInterface {
public SystemManager(final long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
private final T builder;
public SystemManager(Class<T> builder) {
try {
this.builder = builder.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("Builder could not be instantiated!");
}
}
/**
* @return the numberOfProcessors
*/
public long getNumberOfProcessors() {
return numberOfProcessors;
return builder.getNumberOfProcessors();
}
/**
* @param numberOfProcessors the numberOfProcessors to set
*/
public void setNumberOfProcessors(long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
builder.setNumberOfProcessors(numberOfProcessors);
}
public static class SynchronousTaskBuilder {
public T getBuilder() {
return builder;
}
public static interface Builder {
public long getNumberOfProcessors();
public Builder setNumberOfProcessors(long numberOfProcessors);
}
public static class SynchronousTaskBuilder implements Builder {
private long numberOfProcessors = 4;
private long minPeriod = 100;
private long maxSequentialPeriod = 1000;
......@@ -53,7 +71,6 @@ public class SystemManager {
private final long parallelTaskRatio = 0;
public SynchronousTaskBuilder() {
}
private long randomSequentialTaskPeriod() {
......@@ -110,21 +127,11 @@ public class SystemManager {
return taskSet;
}
// public SystemSetup<SynchronousTask> build() {
// this.ratio = randomTaskRatio(this.parallelTaskRatio);
// final Set<SynchronousTask> taskSet = generateTaskSet();
// return new SystemSetup<>(taskSet, numberOfProcessors);
// }
// public Set<SynchronousTask> rebuild(final SystemSetup<SynchronousTask> systemSetup) {
// this.ratio = randomTaskRatio(this.parallelTaskRatio);
// return generateTaskSet();
// }
public boolean addTask(final Set<SynchronousTask> taskSet) {
return taskSet.add(generateTask());
}
@Override
public SynchronousTaskBuilder setNumberOfProcessors(final long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
......@@ -157,9 +164,14 @@ public class SystemManager {
this.maxNumberOfJobs = maxNumberOfJobs;
return this;
}
@Override
public long getNumberOfProcessors() {
return numberOfProcessors;
}
}
public static class DagTaskBuilder {
public static class DagTaskBuilder implements Builder {
private long numberOfProcessors = 8;
private long minimumWcet = 1;
private long maximumWcet = 100;
......@@ -167,7 +179,7 @@ public class SystemManager {
private long maxNumberOfThreads = numberOfProcessors;
private long depth = 2;
private long p_par = 80;
private long p_add = 10; // TODO: Change back to 0.2
private long p_add = 20; // TODO: Change back to 0.2
public DagTaskBuilder() {
}
......@@ -268,12 +280,13 @@ public class SystemManager {
final long criticalPath = DagUtils.calculateCriticalPath(jobDag);
final long period = randomRenyiPeriod(workload, criticalPath, totalUtilization);
// final long numberOfThreads = LongMath.divide(workload - criticalPath,
// period - criticalPath, RoundingMode.CEILING) + 1;
final long minNumberOfThreads = LongMath.divide(workload - criticalPath,
period - criticalPath, RoundingMode.FLOOR);
final long numberOfThreads = randomNumberOfThreads(numberOfProcessors / 2);
// TODO: change back to following:
// final long numberOfThreads = randomNumberOfThreads(minNumberOfThreads);
return new DagTask(jobDag, period, numberOfThreads);
return new DagTask(jobDag, period, minNumberOfThreads);
}
private long randomRenyiPeriod(final long workload, final long criticalPath,
......@@ -448,6 +461,7 @@ public class SystemManager {
/**
* @param numberOfProcessors the numberOfProcessors to set
*/
@Override
public DagTaskBuilder setNumberOfProcessors(final long numberOfProcessors) {
this.numberOfProcessors = numberOfProcessors;
return this;
......@@ -456,6 +470,7 @@ public class SystemManager {
/**
* @return the numberOfProcessors
*/
@Override
public long getNumberOfProcessors() {
return numberOfProcessors;
}
......
package mvd.jester.model;
public interface SystemManagerInterface {
public long getNumberOfProcessors();
}
package mvd.jester.tests;
import mvd.jester.TypeInterface;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
/**
......@@ -9,9 +9,9 @@ import mvd.jester.model.Task;
*/
public abstract class AbstractTest<T extends Task> implements TestInterface<T>, TypeInterface {
protected final SystemManager manager;
protected final SystemManagerInterface manager;
public AbstractTest(final SystemManager manager) {
public AbstractTest(final SystemManagerInterface manager) {
this.manager = manager;
}
......
......@@ -13,7 +13,7 @@ import mvd.jester.info.TerminationInfo;
import mvd.jester.model.Segment;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SynchronousTask;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.priority.EarliestDeadlineFirst;
import mvd.jester.priority.PriorityManager;
......@@ -25,7 +25,7 @@ public class ChwaLee extends AbstractTest<SynchronousTask> {
private final Map<SynchronousTask, TerminationInfo> responseTimes;
private final PriorityManager priorityManager;
public ChwaLee(final SystemManager manager) {
public ChwaLee(final SystemManagerInterface manager) {
super(manager);
this.responseTimes = new HashMap<>();
this.priorityManager = new EarliestDeadlineFirst();
......
......@@ -21,7 +21,7 @@ import mvd.jester.model.DagTask;
import mvd.jester.model.Job;
import mvd.jester.model.Segment;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
import mvd.jester.model.TreeJob;
import mvd.jester.utils.DagUtils;
......@@ -37,7 +37,7 @@ public class FonsecaNelis extends AbstractTest<DagTask> {
private final PriorityManager priorityManager;
private final Map<Task, Set<Segment>> carryOutSegments;
public FonsecaNelis(final SystemManager manager) {
public FonsecaNelis(final SystemManagerInterface manager) {
super(manager);
this.responseTimes = new HashMap<>();
this.priorityManager = new RateMonotonic();
......
......@@ -12,7 +12,7 @@ import mvd.jester.info.SchedulingInfo.Feasiblity;
import mvd.jester.model.ContainerTask;
import mvd.jester.model.DagTask;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
import mvd.jester.priority.EarliestDeadlineFirst;
import mvd.jester.priority.PriorityManager;
......@@ -21,7 +21,7 @@ public class JiangYi extends AbstractTest<DagTask> {
private final EarliestDeadlineFirst priorityManager;
public JiangYi(SystemManager manager) {
public JiangYi(SystemManagerInterface manager) {
super(manager);
this.priorityManager = new EarliestDeadlineFirst();
}
......
......@@ -10,7 +10,7 @@ import mvd.jester.info.TerminationInfo;
import mvd.jester.model.Segment;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SynchronousTask;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.priority.PriorityManager;
import mvd.jester.priority.RateMonotonic;
......@@ -22,7 +22,7 @@ public class MaiaBertogna extends AbstractTest<SynchronousTask> {
private final Map<SynchronousTask, TerminationInfo> responseTimes;
private final PriorityManager priorityManager;
public MaiaBertogna(final SystemManager manager) {
public MaiaBertogna(final SystemManagerInterface manager) {
super(manager);
this.responseTimes = new HashMap<>();
this.priorityManager = new RateMonotonic();
......
......@@ -9,7 +9,7 @@ import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.TerminationInfo;
import mvd.jester.model.DagTask;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
import mvd.jester.priority.PriorityManager;
import mvd.jester.priority.RateMonotonic;
......@@ -19,7 +19,7 @@ public class MelaniButtazzo extends AbstractTest<DagTask> {
private final Map<Task, TerminationInfo> responseTimes;
private final PriorityManager priorityManager;
public MelaniButtazzo(final SystemManager manager) {
public MelaniButtazzo(final SystemManagerInterface manager) {
super(manager);
this.responseTimes = new HashMap<>();
this.priorityManager = new RateMonotonic();
......
......@@ -7,7 +7,7 @@ import mvd.jester.info.SchedulingInfo;
import mvd.jester.info.TerminationInfo;
import mvd.jester.model.DagTask;
import mvd.jester.model.SortedTaskSet;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
import mvd.jester.priority.PriorityManager;
import mvd.jester.priority.RateMonotonic;
......@@ -21,7 +21,7 @@ public class SchmidMottok extends AbstractTest<DagTask> {
private final PriorityManager priorityManager;
private final TypeFunction structure;
public SchmidMottok(TypeFunction structure, final SystemManager manager) {
public SchmidMottok(TypeFunction structure, final SystemManagerInterface manager) {
super(manager);
this.responseTimes = new HashMap<>();
this.priorityManager = new RateMonotonic();
......@@ -54,22 +54,21 @@ public class SchmidMottok extends AbstractTest<DagTask> {
long responseTime = minimumWcet;
long previousResponseTime = 0;
long occupiedProcessors = 0; // manager.getNumberOfProcessors() + 1;
for (final DagTask t : tasks) {
if (t.getPeriod() < task.getPeriod()) {
final long numberOfProcessors = structure.getNumberOfThreads(t);
occupiedProcessors += numberOfProcessors;
}
}
do {
previousResponseTime = responseTime;
double taskInterference = 0;
long occupiedProcessors = manager.getNumberOfProcessors() + 1;
// for (final DagTask t : tasks) {
// if (t.getPeriod() < task.getPeriod()) {
// final long numberOfProcessors = structure.getNumerOfThreads(t);
// occupiedProcessors += numberOfProcessors;
// }
// }
for (final DagTask t : tasks) {
if (t.getPeriod() < task.getPeriod()) {
final long numberOfProcessors = structure.getNumerOfThreads(t);
for (int p = 0; p < numberOfProcessors; ++p) {
final long numberOfThreads = structure.getNumberOfThreads(t);
for (int p = 0; p < numberOfThreads; ++p) {
if (occupiedProcessors > manager.getNumberOfProcessors()) {
taskInterference +=
Math.min(
......
......@@ -6,7 +6,7 @@ import com.google.common.math.LongMath;
import mvd.jester.info.TerminationInfo;
import mvd.jester.model.DagTask;
import mvd.jester.model.Segment;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManagerInterface;
import mvd.jester.model.Task;
public interface TypeFunction {
......@@ -17,15 +17,15 @@ public interface TypeFunction {
public double getSelfInterference(final DagTask task);
public long getNumerOfThreads(final DagTask task);
public long getNumberOfThreads(final DagTask task);
public String getType();
public class KnownStructureWithMaxThreads implements TypeFunction {
private final SystemManager manager;
private final SystemManagerInterface manager;
public KnownStructureWithMaxThreads(final SystemManager manager) {
public KnownStructureWithMaxThreads(final SystemManagerInterface manager) {
this.manager = manager;
}
......@@ -75,7 +75,7 @@ public interface TypeFunction {
}
@Override
public long getNumerOfThreads(final DagTask task) {
public long getNumberOfThreads(final DagTask task) {
return manager.getNumberOfProcessors();
}
}
......@@ -127,7 +127,7 @@ public interface TypeFunction {
}
@Override
public long getNumerOfThreads(final DagTask task) {
public long getNumberOfThreads(final DagTask task) {
return task.getNumberOfThreads();
}
}
......@@ -180,7 +180,7 @@ public interface TypeFunction {
}
@Override
public long getNumerOfThreads(final DagTask task) {
public long getNumberOfThreads(final DagTask task) {
return task.getNumberOfThreads();
}
}
......
......@@ -8,6 +8,7 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import mvd.jester.model.SynchronousTask;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManager.SynchronousTaskBuilder;
import mvd.jester.simulator.DynamicForkJoin;
import mvd.jester.simulator.ParallelSynchronous;
import mvd.jester.simulator.internals.parallelsynchronous.TaskContext;
......@@ -49,7 +50,8 @@ public class TestEarliestDeadlineFirst {
@DisplayName("Check Getters, Tests and Simulators.")
void testGettersTestsAndSimulators() {
EarliestDeadlineFirst edf = new EarliestDeadlineFirst();
SystemManager manager = new SystemManager(4);
SystemManager<SynchronousTaskBuilder> manager =
new SystemManager<>(SynchronousTaskBuilder.class);
assertTrue(edf.hasTest(ChwaLee.class));
assertFalse(edf.hasTest(MaiaBertogna.class));
assertFalse(edf.hasTest(SchmidMottok.class));
......
......@@ -8,6 +8,7 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import mvd.jester.model.SynchronousTask;
import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManager.SynchronousTaskBuilder;
import mvd.jester.simulator.DynamicForkJoin;
import mvd.jester.simulator.ParallelSynchronous;
import mvd.jester.simulator.internals.parallelsynchronous.TaskContext;
......@@ -48,7 +49,8 @@ public class TestRateMonotonic {
@DisplayName("Check Tests and Simulators.")
void testTestsAndSimulators() {
RateMonotonic rm = new RateMonotonic();
SystemManager manager = new SystemManager(8);
SystemManager<SynchronousTaskBuilder> manager =
new SystemManager<>(SynchronousTaskBuilder.class);
assertFalse(rm.hasTest(ChwaLee.class));
assertTrue(rm.hasTest(MaiaBertogna.class));
assertTrue(rm.hasTest(SchmidMottok.class));
......
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