Commit b00f2d0e by Michael Schmid

Simulator now works

parent 36080fd3
......@@ -7,6 +7,8 @@ import mvd.jester.model.SystemManager;
import mvd.jester.model.SystemManager.DagTaskBuilder;
import mvd.jester.priority.RateMonotonic;
import mvd.jester.simulator.GlobalScheduler;
import mvd.jester.simulator.model.ExtendedSubtaskContext;
import mvd.jester.simulator.model.JobContext;
import mvd.jester.tests.AbstractTest;
import mvd.jester.tests.FonsecaNelis;
import mvd.jester.tests.MelaniButtazzo;
......@@ -25,7 +27,8 @@ public class App {
GlobalScheduler scheduler = new GlobalScheduler(new RateMonotonic(), 4);
DagTaskBuilder builder = new DagTaskBuilder().setNumberOfProcessors(4);
scheduler.schedule(builder.generateTaskSet(3), 10000);
scheduler.schedule(builder.generateTaskSet(1.0), 10000);
// {
// SystemManager manager = new SystemManager(8);
// DagTaskBuilder builder = new DagTaskBuilder();
......
......@@ -98,4 +98,9 @@ public class DagTask implements Task {
return numberOfThreads;
}
@Override
public String toString() {
return "(P=" + period + ", D=" + deadline + ")";
}
}
......@@ -27,4 +27,10 @@ public class Subtask {
public void setRelativeCompletionTime(long relativeCompletionTime) {
this.relativeCompletionTime = relativeCompletionTime;
}
@Override
public String toString() {
return "(C=" + wcet + ")";
}
}
......@@ -160,10 +160,10 @@ public class SystemManager {
private long numberOfProcessors = 8;
private long minimumWcet = 1;
private long maximumWcet = 100;
private long maxNumberOfBranches = 5;
private long depth = 2;
private long maxNumberOfBranches = 3; // TODO: Change back to 5
private long depth = 1; // TODO: Change back to 2
private long p_par = 80;
private long p_add = 20;
private long p_add = 10; // TODO: Change back to 20
public DagTaskBuilder() {
}
......@@ -252,8 +252,8 @@ public class SystemManager {
return new DagTask(jobDag, period, numberOfProcessors);
}
private Subtask join(final DirectedAcyclicGraph<Subtask, DefaultEdge> jobDag, final Subtask current,
final Set<Subtask> childs) {
private Subtask join(final DirectedAcyclicGraph<Subtask, DefaultEdge> jobDag,
final Subtask current, final Set<Subtask> childs) {
if (childs.size() > 0) {
final Subtask job = new Subtask(randomWcet());
jobDag.addVertex(job);
......
......@@ -3,7 +3,7 @@ package mvd.jester.simulator.events;
import mvd.jester.simulator.model.ExtendedSubtaskContext;
import mvd.jester.simulator.model.JobContext;
public abstract class AbstractContextEvent extends AbstractSubtaskEvent implements ISubtaskEvent {
public abstract class AbstractContextEvent extends AbstractSubtaskEvent {
private final ExtendedSubtaskContext subtask;
......@@ -13,7 +13,7 @@ public abstract class AbstractContextEvent extends AbstractSubtaskEvent implemen
this.subtask = subtask;
}
@Override
// @Override
public ExtendedSubtaskContext getSubtaskContext() {
return subtask;
}
......
......@@ -2,7 +2,7 @@ package mvd.jester.simulator.events;
import mvd.jester.simulator.model.JobContext;
public abstract class AbstractSubtaskEvent extends AbstractEvent {
public abstract class AbstractSubtaskEvent extends AbstractEvent implements ISubtaskEvent {
private final JobContext jobContext;
......
......@@ -5,7 +5,7 @@ import mvd.jester.simulator.model.JobContext;
public interface ISubtaskEvent extends IEvent {
public ExtendedSubtaskContext getSubtaskContext();
// public ExtendedSubtaskContext getSubtaskContext();
public JobContext getJobContext();
......
......@@ -3,25 +3,15 @@ package mvd.jester.simulator.events;
import mvd.jester.model.Subtask;
import mvd.jester.simulator.model.JobContext;
public class SubtaskActivatedEvent extends AbstractEvent {
public class SubtaskActivatedEvent extends AbstractSubtaskEvent {
private final JobContext job;
private final Subtask subtask;
public SubtaskActivatedEvent(final long time, final JobContext job, final Subtask subtask) {
super(EventType.SUBTASK_ACTIVATED, time);
this.job = job;
super(EventType.SUBTASK_ACTIVATED, time, job);
this.subtask = subtask;
}
/**
* @return the job
*/
public JobContext getJobContext() {
return job;
}
/**
* @return the subtask
*/
......@@ -31,7 +21,7 @@ public class SubtaskActivatedEvent extends AbstractEvent {
@Override
protected String getLoggingMessage() {
return "Subtask " + getSubtask() + " released";
return "Subtask " + getSubtask() + " of task " + getJobContext().getTask() + " released";
}
}
......@@ -10,7 +10,8 @@ public class SubtaskCompletedEvent extends AbstractContextEvent {
@Override
protected String getLoggingMessage() {
return "Subtask " + getSubtaskContext() + " completed";
return "Subtask " + getSubtaskContext() + " of task " + getJobContext().getTask()
+ " completed";
}
}
......@@ -16,6 +16,6 @@ public class TaskReleasedEvent extends AbstractEvent {
@Override
public String getLoggingMessage() {
return "task " + getTask() + " started";
return "Task " + getTask() + " started";
}
}
......@@ -15,4 +15,9 @@ public class ExtendedSubtaskContext extends SubtaskContext {
public JobContext getJobContext() {
return jobContext;
}
@Override
public String toString() {
return getSubtask() + " of task " + getJobContext().getTask();
}
}
package mvd.jester.simulator.model;
import java.util.HashSet;
import java.util.Set;
import org.jgrapht.experimental.dag.DirectedAcyclicGraph;
import org.jgrapht.graph.DefaultEdge;
import mvd.jester.model.DagTask;
......@@ -11,6 +13,7 @@ public class JobContext {
private final long releaseTime;
private final long deadline;
private final Subtask source;
private final Set<ExtendedSubtaskContext> finishedSubtasks;
// private long activeThreads; // TODO: Use threads
public JobContext(DagTask task, long releaseTime) {
......@@ -18,6 +21,7 @@ public class JobContext {
this.releaseTime = releaseTime;
this.deadline = releaseTime + task.getDeadline();
this.source = findSource(task);
this.finishedSubtasks = new HashSet<>();
// this.activeThreads = task.getNumberOfThreads();
}
......@@ -59,8 +63,26 @@ public class JobContext {
return releaseTime;
}
/**
* @return the finishedSubtasks
*/
public Set<ExtendedSubtaskContext> getFinishedSubtasks() {
return finishedSubtasks;
}
public void registerFinishedSubtask(ExtendedSubtaskContext subtaskContext) {
if (!finishedSubtasks.add(subtaskContext)) {
throw new RuntimeException(
"Subtask could not be added to finished subtask which means it was executed twice!");
}
}
public boolean checkRemainingThreads() {
return false;
return true; // TODO: implement check in future
}
public String toString() {
return "of task " + getTask();
}
}
package mvd.jester.simulator.model;
import java.util.Comparator;
import java.util.Optional;
import mvd.jester.priority.PriorityManager;
import mvd.jester.simulator.exceptions.DeadlineMissedException;
......@@ -96,4 +97,28 @@ public class ProcessorContext {
return "Processor " + processorId;
}
public static class ProcessorComparator implements Comparator<ProcessorContext> {
private final PriorityManager priorityManager;
public ProcessorComparator(PriorityManager priorityManager) {
this.priorityManager = priorityManager;
}
@Override
public int compare(ProcessorContext p1, ProcessorContext p2) {
if (!p1.getSubtask().isPresent()) {
return -1;
} else if (!p2.getSubtask().isPresent()) {
return 1;
} else {
// Sort in reverse
return priorityManager.compare(p2.currentSubtask.get().getJobContext(),
p1.currentSubtask.get().getJobContext());
}
}
}
}
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