Commit 9ea90201 by Michael Schmid

model seems to finally work, need to verify

parent 7999313d
package mvd.jester; package mvd.jester;
import java.io.PrintWriter;
import mvd.jester.model.SystemSetup; import mvd.jester.model.SystemSetup;
import mvd.jester.simulator.EventPrinter;
import mvd.jester.simulator.MaiaBertogna; import mvd.jester.simulator.MaiaBertogna;
import mvd.jester.simulator.SchmidMottok; import mvd.jester.simulator.SchmidMottok;
...@@ -10,43 +12,54 @@ import mvd.jester.simulator.SchmidMottok; ...@@ -10,43 +12,54 @@ import mvd.jester.simulator.SchmidMottok;
*/ */
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
// SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8); SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8);
// TestEnvironment te = new TestEnvironment(builder, 400); TestEnvironment te = new TestEnvironment(builder, 40000);
te.registerTestPair(mvd.jester.tests.MaiaBertogna.class,
mvd.jester.simulator.MaiaBertogna.class);
// te.registerTestPair(mvd.jester.tests.MaiaBertogna.class, te.registerTestPair(mvd.jester.tests.SchmidMottok.class,
// mvd.jester.simulator.MaiaBertogna.class); mvd.jester.simulator.SchmidMottok.class);
// te.registerTestPair(mvd.jester.tests.SchmidMottok.class, te.runTests();
// mvd.jester.simulator.SchmidMottok.class);
// te.runTests(); // boolean mbWorked = false;
// boolean smWorked = false;
boolean mbWorked = false; // SystemSetup thisOne = null;
boolean smWorked = false; // EventPrinter.enablePrinter();
SystemSetup thisOne = null; // do {
// SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8);
// SystemSetup systemSetup = builder.build();
do { // SchmidMottok sm = new SchmidMottok(systemSetup);
SystemSetup.Builder builder = new SystemSetup.Builder().setNumberOfProcessors(8); // MaiaBertogna mb = new MaiaBertogna(systemSetup);
SystemSetup systemSetup = builder.build();
SchmidMottok sm = new SchmidMottok(systemSetup);
MaiaBertogna mb = new MaiaBertogna(systemSetup);
// smWorked = sm.runSimulation();
// mbWorked = mb.runSimulation();
smWorked = sm.runSimulation();
mbWorked = mb.runSimulation();
// thisOne = systemSetup;
// } while (smWorked == mbWorked);
thisOne = systemSetup;
} while (smWorked == mbWorked);
// try (PrintWriter out = new PrintWriter("./results/manCheck.txt")) {
// out.println(thisOne);
// } catch (Exception e) {
// System.out.println("Ähm something went horribly wrong!");
// }
// SchmidMottok sm = new SchmidMottok(thisOne);
// MaiaBertogna mb = new MaiaBertogna(thisOne);
SchmidMottok sm = new SchmidMottok(thisOne); // mb.runSimulation();
MaiaBertogna mb = new MaiaBertogna(thisOne); // sm.runSimulation();
mb.runSimulation(); // SystemSetup systemSetup = SystemSetup.fromFile("results/manCheck.txt");
sm.runSimulation(); // EventPrinter.enablePrinter();
// SchmidMottok sm = new SchmidMottok(systemSetup);
// sm.runSimulation();
} }
} }
package mvd.jester.model; package mvd.jester.model;
import com.google.common.math.LongMath;
// import com.google.common.math.LongMath; // import com.google.common.math.LongMath;
public class Segment { public class Segment {
...@@ -15,14 +17,17 @@ public class Segment { ...@@ -15,14 +17,17 @@ public class Segment {
if (numberOfJobs == 1) { if (numberOfJobs == 1) {
this.taskletWcet = this.jobWcet; this.taskletWcet = this.jobWcet;
this.numberOfTasklets = this.numberOfJobs; this.numberOfTasklets = this.numberOfJobs;
} else if (this.numberOfJobs > this.jobWcet) {
this.taskletWcet = LongMath.gcd(jobWcet, numberOfJobs);
this.numberOfTasklets = this.jobWcet * this.numberOfJobs / this.taskletWcet;
} else { } else {
// this.taskletWcet = LongMath.gcd(jobWcet, numberOfJobs);
// this.numberOfTasklets = this.jobWcet * this.numberOfJobs / this.taskletWcet;
this.taskletWcet = numberOfJobs; this.taskletWcet = numberOfJobs;
this.numberOfTasklets = jobWcet; this.numberOfTasklets = jobWcet;
} }
} }
/** /**
* @return the numberOfJobs * @return the numberOfJobs
*/ */
......
package mvd.jester.simulator; package mvd.jester.simulator;
import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
...@@ -42,11 +43,8 @@ public abstract class AbstractSimulator implements SimulatorInterface { ...@@ -42,11 +43,8 @@ public abstract class AbstractSimulator implements SimulatorInterface {
return false; return false;
} }
Set<ProcessorContext> sortedProcessors = Set<ProcessorContext> sortedProcessors = sortProcessors(processors);
new TreeSet<>((p1, p2) -> (int) (!p1.getJob().isPresent() ? -1
: !p2.getJob().isPresent() ? 1 : -1));
processors.forEach(p -> sortedProcessors.add(p));
for (ProcessorContext p : sortedProcessors) { for (ProcessorContext p : sortedProcessors) {
for (TaskContextInterface tc : readyTasks) { for (TaskContextInterface tc : readyTasks) {
if (p.acceptTask(tc, t)) { if (p.acceptTask(tc, t)) {
...@@ -61,6 +59,7 @@ public abstract class AbstractSimulator implements SimulatorInterface { ...@@ -61,6 +59,7 @@ public abstract class AbstractSimulator implements SimulatorInterface {
if (optionalTc.isPresent()) { if (optionalTc.isPresent()) {
TaskContextInterface tc = optionalTc.get(); TaskContextInterface tc = optionalTc.get();
if (t >= tc.getDeadline()) { if (t >= tc.getDeadline()) {
EventPrinter.print("Time " + t + ": Task " + tc + " failed its deadline!");
return false; return false;
} }
readyTasks.remove(optionalTc.get()); readyTasks.remove(optionalTc.get());
...@@ -79,6 +78,34 @@ public abstract class AbstractSimulator implements SimulatorInterface { ...@@ -79,6 +78,34 @@ public abstract class AbstractSimulator implements SimulatorInterface {
this.hyperPeriod = systemSetup.getTasks().last().getPeriod() * 2; this.hyperPeriod = systemSetup.getTasks().last().getPeriod() * 2;
} }
private Set<ProcessorContext> sortProcessors(Set<ProcessorContext> processors) {
Set<ProcessorContext> sortedProcessors = new TreeSet<>(new ProcessorComparator());
processors.forEach(p -> sortedProcessors.add(p));
return sortedProcessors;
}
private class ProcessorComparator implements Comparator<ProcessorContext> {
@Override
public int compare(ProcessorContext p1, ProcessorContext p2) {
if (!p1.getJob().isPresent()) {
return -1;
} else if (!p2.getJob().isPresent()) {
return 1;
} else {
long p1Period = p1.getJob().get().getTaskContext().getTask().getPeriod();
long p2Period = p2.getJob().get().getTaskContext().getTask().getPeriod();
if (p1Period == p2Period) {
return 1;
} else {
return (int) (p2.getJob().get().getTaskContext().getTask().getPeriod()
- p1.getJob().get().getTaskContext().getTask().getPeriod());
}
}
}
}
} }
package mvd.jester.simulator;
/**
* EventPrinter
*/
public class EventPrinter {
private static boolean printerEnabled;
private EventPrinter() {
printerEnabled = false;
}
public static void enablePrinter() {
printerEnabled = true;
}
public static void disablePrinter() {
printerEnabled = false;
}
public static void print(String text) {
if (printerEnabled) {
System.out.println(text);
}
}
}
...@@ -17,9 +17,13 @@ public class MaiaBertogna extends AbstractSimulator { ...@@ -17,9 +17,13 @@ public class MaiaBertogna extends AbstractSimulator {
protected boolean releaseTasks(long timeStep) { protected boolean releaseTasks(long timeStep) {
for (Task t : systemSetup.getTasks()) { for (Task t : systemSetup.getTasks()) {
if (timeStep % t.getPeriod() == 0) { if (timeStep % t.getPeriod() == 0) {
if (!readyTasks.add(new TaskContext(t, timeStep))) { TaskContext tc = new TaskContext(t, timeStep);
if (!readyTasks.add(tc)) {
EventPrinter
.print("Time " + timeStep + ": Task " + tc + " could not be released!");
return false; return false;
} }
EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!");
} }
} }
return true; return true;
......
...@@ -19,11 +19,13 @@ public class SchmidMottok extends AbstractSimulator { ...@@ -19,11 +19,13 @@ public class SchmidMottok extends AbstractSimulator {
protected boolean releaseTasks(long timeStep) { protected boolean releaseTasks(long timeStep) {
for (Task t : systemSetup.getTasks()) { for (Task t : systemSetup.getTasks()) {
if (timeStep % t.getPeriod() == 0) { if (timeStep % t.getPeriod() == 0) {
TaskContext tc = new TaskContext(t, timeStep); TaskContext tc = new TaskContext(t, systemSetup.getNumberOfProcessors(), timeStep);
if (!readyTasks.add(tc)) { if (!readyTasks.add(tc)) {
EventPrinter
.print("Time " + timeStep + ": Task " + tc + " could not be released!");
return false; return false;
} }
// System.out.println("Time " + timeStep + ": " + "Task " + tc + "activated!"); EventPrinter.print("Time " + timeStep + ": Task " + tc + " released!");
} }
} }
return true; return true;
......
...@@ -16,4 +16,6 @@ public interface JobContextInterface { ...@@ -16,4 +16,6 @@ public interface JobContextInterface {
public Optional<ProcessorContext> getCurrentProcessor(); public Optional<ProcessorContext> getCurrentProcessor();
public TaskContextInterface getTaskContext(); public TaskContextInterface getTaskContext();
public boolean prepareJob(long time);
} }
package mvd.jester.simulator.internals; package mvd.jester.simulator.internals;
import java.util.Optional; import java.util.Optional;
import mvd.jester.simulator.EventPrinter;
/** /**
* Processor * Processor
...@@ -41,17 +42,19 @@ public class ProcessorContext { ...@@ -41,17 +42,19 @@ public class ProcessorContext {
Optional<JobContextInterface> optionalJob = taskContext.getNextJob(); Optional<JobContextInterface> optionalJob = taskContext.getNextJob();
if (optionalJob.isPresent()) { if (optionalJob.isPresent()) {
if (!optionalJob.get().prepareJob(t)) {
return false;
}
if (currentJob.isPresent()) { if (currentJob.isPresent()) {
currentJob.get().setCurrentProcessor(null); currentJob.get().setCurrentProcessor(null);
} }
currentJob = optionalJob; currentJob = optionalJob;
currentJob.get().setCurrentProcessor(this); currentJob.get().setCurrentProcessor(this);
System.out.println( EventPrinter.print(
"Time " + t + ": " + this + " started job " + currentJob.get() + "!"); "Time " + t + ": " + this + " started job " + currentJob.get() + "!");
return true; return true;
} else {
return false;
} }
} }
return false; return false;
......
package mvd.jester.simulator.internals.maiabertogna; package mvd.jester.simulator.internals.maiabertogna;
import java.util.Optional; import java.util.Optional;
import mvd.jester.simulator.EventPrinter;
import mvd.jester.simulator.internals.JobContextInterface; import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.ProcessorContext; import mvd.jester.simulator.internals.ProcessorContext;
import mvd.jester.simulator.internals.TaskContextInterface; import mvd.jester.simulator.internals.TaskContextInterface;
...@@ -31,7 +32,7 @@ public class JobContext implements JobContextInterface { ...@@ -31,7 +32,7 @@ public class JobContext implements JobContextInterface {
executionTime--; executionTime--;
if (executionTime == 0) { if (executionTime == 0) {
System.out.println("Time " + time + ": " + currentProcessor.get() EventPrinter.print("Time " + time + ": " + currentProcessor.get()
+ " finished execution of job " + this + "!"); + " finished execution of job " + this + "!");
currentProcessor.get().setJob(null); currentProcessor.get().setJob(null);
currentProcessor = Optional.empty(); currentProcessor = Optional.empty();
...@@ -86,4 +87,9 @@ public class JobContext implements JobContextInterface { ...@@ -86,4 +87,9 @@ public class JobContext implements JobContextInterface {
return "(jobWcet=" + wcet + ", of task=" + taskContext + ")"; return "(jobWcet=" + wcet + ", of task=" + taskContext + ")";
} }
@Override
public boolean prepareJob(long time) {
return true;
}
} }
...@@ -4,6 +4,7 @@ import java.util.ArrayList; ...@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
import mvd.jester.model.Segment; import mvd.jester.model.Segment;
import mvd.jester.model.Task; import mvd.jester.model.Task;
import mvd.jester.simulator.EventPrinter;
import mvd.jester.simulator.internals.JobContextInterface; import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.TaskContextInterface; import mvd.jester.simulator.internals.TaskContextInterface;
...@@ -52,7 +53,7 @@ public class TaskContext implements TaskContextInterface { ...@@ -52,7 +53,7 @@ public class TaskContext implements TaskContextInterface {
currentSegment++; currentSegment++;
segmentCounter = 0; segmentCounter = 0;
if (currentSegment >= segments.size()) { if (currentSegment >= segments.size()) {
System.out.println("Time " + time + ": Task " + this + "finished!"); EventPrinter.print("Time " + time + ": Task " + this + "finished!");
return Optional.of(this); return Optional.of(this);
} }
} }
......
package mvd.jester.simulator.internals.schmidmottok; package mvd.jester.simulator.internals.schmidmottok;
import java.util.Optional; import java.util.Optional;
import mvd.jester.simulator.EventPrinter;
import mvd.jester.simulator.internals.JobContextInterface; import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.ProcessorContext; import mvd.jester.simulator.internals.ProcessorContext;
import mvd.jester.simulator.internals.TaskContextInterface; import mvd.jester.simulator.internals.TaskContextInterface;
...@@ -30,29 +31,36 @@ public class JobContext implements JobContextInterface { ...@@ -30,29 +31,36 @@ public class JobContext implements JobContextInterface {
} }
public Optional<TaskContextInterface> updateExecution(long time) { public Optional<TaskContextInterface> updateExecution(long time) {
if (!currentTasklet.isPresent()) { boolean jobIsIdle = true;
if (currentTasklet.isPresent()) {
jobIsIdle = currentTasklet.get().updateExecution(time);
}
if (jobIsIdle) {
currentTasklet = segmentContext.getNextTasklet(); currentTasklet = segmentContext.getNextTasklet();
Optional<TaskContextInterface> tc = taskContext.acceptNotification(time);
if (currentTasklet.isPresent()) { if (currentTasklet.isPresent()) {
System.out.println("Time " + time + ": Job " + this + " started executing tasklet " EventPrinter.print("Time " + time + ": Job " + this + " started executing tasklet "
+ currentTasklet.get() + " on Processor " + currentProcessor.get()); + currentTasklet.get() + " on Processor " + currentProcessor.get());
currentTasklet.get().setCurrentJob(this);
} else {
if (currentProcessor.isPresent()) {
currentProcessor.get().setJob(null);
}
currentProcessor = Optional.empty();
return tc;
} }
} }
if (currentTasklet.isPresent()) {
currentTasklet.get().setCurrentJob(this);
// Hier update execution time, dann checken if 0, und wenn 0 gleich nächste Tasklet
// auswählen.
return currentTasklet.get().updateExecution(time);
} else if (currentProcessor.isPresent()) {
currentProcessor.get().setJob(null);
currentProcessor = Optional.empty();
}
return Optional.empty(); return Optional.empty();
} }
public boolean checkExecutionTime() { public boolean checkExecutionTime() {
return executionTime > 0; if (currentTasklet.isPresent()) {
return currentTasklet.get().checkExecutionTime();
}
return false;
} }
/** /**
...@@ -103,4 +111,21 @@ public class JobContext implements JobContextInterface { ...@@ -103,4 +111,21 @@ public class JobContext implements JobContextInterface {
return "(of task=" + taskContext + ")"; return "(of task=" + taskContext + ")";
} }
@Override
public boolean prepareJob(long time) {
if (!currentTasklet.isPresent()) {
currentTasklet = segmentContext.getNextTasklet();
if (currentTasklet.isPresent()) {
currentTasklet.get().setCurrentJob(this);
// EventPrinter.print("Time " + time + ": Job " + this + " started executing
// tasklet"
// + currentTasklet.get());
return true;
} else {
return false;
}
}
return true;
}
} }
...@@ -14,12 +14,15 @@ public class SegmentContext { ...@@ -14,12 +14,15 @@ public class SegmentContext {
private final Set<JobContextInterface> jobs; private final Set<JobContextInterface> jobs;
private final Set<TaskletContext> tasklets; private final Set<TaskletContext> tasklets;
public SegmentContext(TaskContext taskContext, Segment segment) { public SegmentContext(TaskContext taskContext, Segment segment, long numberOfProcessors) {
this.segment = segment; this.segment = segment;
jobs = new HashSet<>(); jobs = new HashSet<>();
tasklets = new HashSet<>(); tasklets = new HashSet<>();
for (int j = 0; j < segment.getNumberOfJobs(); ++j) { long numberOfJobs = segment.getNumberOfJobs() > numberOfProcessors ? numberOfProcessors
: segment.getNumberOfJobs();
for (int j = 0; j < numberOfJobs; ++j) {
jobs.add(new JobContext(taskContext, this)); jobs.add(new JobContext(taskContext, this));
} }
...@@ -36,14 +39,25 @@ public class SegmentContext { ...@@ -36,14 +39,25 @@ public class SegmentContext {
return segment; return segment;
} }
public long getNumberOfJobs() {
return jobs.size();
}
Optional<JobContextInterface> getNextJob() { Optional<JobContextInterface> getNextJob() {
boolean taskletAvailable = tasklets.stream() boolean taskletAvailable = tasklets.stream()
.anyMatch(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime()); .anyMatch(t -> !t.getCurrentJob().isPresent() && t.checkExecutionTime());
if (taskletAvailable) { boolean jobNotFinished = jobs.stream()
.anyMatch(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime());
if (jobNotFinished) {
return jobs.stream() return jobs.stream()
.filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime()) .filter(j -> !j.getCurrentProcessor().isPresent() && j.checkExecutionTime())
.findFirst(); .findFirst();
} else if (taskletAvailable) {
return jobs.stream()
.filter(j -> !j.getCurrentProcessor().isPresent() && !j.checkExecutionTime())
.findFirst();
} else { } else {
return Optional.empty(); return Optional.empty();
} }
......
...@@ -4,6 +4,7 @@ import java.util.ArrayList; ...@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
import mvd.jester.model.Segment; import mvd.jester.model.Segment;
import mvd.jester.model.Task; import mvd.jester.model.Task;
import mvd.jester.simulator.EventPrinter;
import mvd.jester.simulator.internals.JobContextInterface; import mvd.jester.simulator.internals.JobContextInterface;
import mvd.jester.simulator.internals.TaskContextInterface; import mvd.jester.simulator.internals.TaskContextInterface;
...@@ -19,7 +20,7 @@ public class TaskContext implements TaskContextInterface { ...@@ -19,7 +20,7 @@ public class TaskContext implements TaskContextInterface {
private int segmentCounter; private int segmentCounter;
public TaskContext(Task task, long timeStep) { public TaskContext(Task task, long numberOfProcessors, long timeStep) {
this.task = task; this.task = task;
this.segments = new ArrayList<>(); this.segments = new ArrayList<>();
this.currentSegment = 0; this.currentSegment = 0;
...@@ -27,7 +28,7 @@ public class TaskContext implements TaskContextInterface { ...@@ -27,7 +28,7 @@ public class TaskContext implements TaskContextInterface {
this.deadline = timeStep + task.getDeadline(); this.deadline = timeStep + task.getDeadline();
for (Segment s : task.getSegments()) { for (Segment s : task.getSegments()) {
segments.add(new SegmentContext(this, s)); segments.add(new SegmentContext(this, s, numberOfProcessors));
} }
} }
...@@ -52,7 +53,7 @@ public class TaskContext implements TaskContextInterface { ...@@ -52,7 +53,7 @@ public class TaskContext implements TaskContextInterface {
currentSegment++; currentSegment++;
segmentCounter = 0; segmentCounter = 0;
if (currentSegment >= segments.size()) { if (currentSegment >= segments.size()) {
System.out.println("Time " + time + ": Task " + this + "finished!"); EventPrinter.print("Time " + time + ": Task " + this + "finished!");
return Optional.of(this); return Optional.of(this);
} }
} }
......
package mvd.jester.simulator.internals.schmidmottok; package mvd.jester.simulator.internals.schmidmottok;
import java.util.Optional; import java.util.Optional;
import mvd.jester.simulator.internals.TaskContextInterface;
/** /**
* Tasklet * Tasklet
...@@ -33,15 +32,20 @@ public class TaskletContext { ...@@ -33,15 +32,20 @@ public class TaskletContext {
currentJob = Optional.ofNullable(jobContext); currentJob = Optional.ofNullable(jobContext);
} }
public Optional<TaskContextInterface> updateExecution(long time) { /**
* @return true if tasklet finished, false otherwise
*/
public boolean updateExecution(long time) {
executionTime--; executionTime--;
if (executionTime == 0) { if (executionTime == 0) {
currentJob.get().setCurrentTasklet(null); if (currentJob.isPresent()) {
currentJob.get().setCurrentTasklet(null);
}
currentJob = Optional.empty(); currentJob = Optional.empty();
return taskContext.acceptNotification(time); return true;
} }
return Optional.empty(); return false;
} }
public boolean checkExecutionTime() { public boolean checkExecutionTime() {
......
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