diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2023-11-14 13:28:02 +0100 |
|---|---|---|
| committer | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2023-11-14 13:32:46 +0100 |
| commit | d823cd1eb16d175fb778c9f6c9282aa16f1a25ff (patch) | |
| tree | 28f0461d8ccbac4db69e6ec748554b879b62f179 /opendc-simulator/opendc-simulator-compute/src | |
| parent | 79c1818e116a7ac72d5210865a528538800bb794 (diff) | |
Updated TraceReader, Simulation now continues until all tasks are done
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src')
6 files changed, 54 insertions, 34 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java index a1623351..ffe327d3 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java @@ -72,6 +72,9 @@ public final class SimHypervisor implements SimWorkload { private final ArrayList<VirtualMachine> vms = new ArrayList<>(); private final HvCounters counters = new HvCounters(); + @Override + public void setOffset(long now) {} + /** * Construct a {@link SimHypervisor} instance. * diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java index 7480b3c0..f81b1779 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java @@ -61,6 +61,14 @@ final class SimChainWorkload implements SimWorkload { } @Override + public void setOffset(long now) { + for (SimWorkload workload : this.workloads) { + workload.setOffset(now); + } + + } + + @Override public void onStart(SimMachineContext ctx) { final SimWorkload[] workloads = this.workloads; final int activeWorkloadIndex = this.activeWorkloadIndex; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java index 839856bb..8704f6b9 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java @@ -64,6 +64,9 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic { } @Override + public void setOffset(long now) {} + + @Override public void onStart(SimMachineContext ctx) { this.ctx = ctx; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java index 9c9f4788..bf54142f 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java @@ -63,6 +63,9 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic { } @Override + public void setOffset(long now) {} + + @Override public void onStart(SimMachineContext ctx) { this.ctx = ctx; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java index 1d8667d5..caf0c3d7 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java @@ -68,10 +68,10 @@ public final class SimTrace { /** * Construct a {@link SimWorkload} for this trace. * - * @param offset The offset for the timestamps. +// * @param offset The offset for the timestamps. */ - public SimWorkload createWorkload(long offset) { - return new Workload(offset, usageCol, deadlineCol, coresCol, size, 0); + public SimWorkload createWorkload(long start) { + return new Workload(start, usageCol, deadlineCol, coresCol, size, 0); } /** @@ -206,15 +206,17 @@ public final class SimTrace { private static class Workload implements SimWorkload { private WorkloadStageLogic logic; - private final long offset; + private long offset; + + private final long start; private final double[] usageCol; private final long[] deadlineCol; private final int[] coresCol; private final int size; private final int index; - private Workload(long offset, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) { - this.offset = offset; + private Workload(long start, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) { + this.start = start; this.usageCol = usageCol; this.deadlineCol = deadlineCol; this.coresCol = coresCol; @@ -223,6 +225,11 @@ public final class SimTrace { } @Override + public void setOffset(long now) { + this.offset = now - this.start; + } + + @Override public void onStart(SimMachineContext ctx) { final WorkloadStageLogic logic; if (ctx.getCpus().size() == 1) { @@ -252,7 +259,7 @@ public final class SimTrace { index = logic.getIndex(); } - return new Workload(offset, usageCol, deadlineCol, coresCol, size, index); + return new Workload(start, usageCol, deadlineCol, coresCol, size, index); } } @@ -279,20 +286,20 @@ public final class SimTrace { private final OutPort output; private int index; - private final long offset; - private final double[] usageCol; - private final long[] deadlineCol; - private final int size; + private final long workloadOffset; + private final double[] cpuUsages; + private final long[] deadlines; + private final int traceSize; private final SimMachineContext ctx; private SingleWorkloadLogic( SimMachineContext ctx, long offset, double[] usageCol, long[] deadlineCol, int size, int index) { this.ctx = ctx; - this.offset = offset; - this.usageCol = usageCol; - this.deadlineCol = deadlineCol; - this.size = size; + this.workloadOffset = offset; + this.cpuUsages = usageCol; + this.deadlines = deadlineCol; + this.traceSize = size; this.index = index; final FlowGraph graph = ctx.getGraph(); @@ -309,25 +316,20 @@ public final class SimTrace { @Override public long onUpdate(FlowStage ctx, long now) { - int size = this.size; - long offset = this.offset; - long nowOffset = now - offset; - - int index = this.index; - - long[] deadlines = deadlineCol; - long deadline = deadlines[index]; + // Shift the current time to align with the starting time of the workload + long nowOffset = now - this.workloadOffset; + long deadline = this.deadlines[this.index]; + // Loop through the deadlines until the next deadline is reached. while (deadline <= nowOffset) { - if (++index >= size) { + if (++this.index >= this.traceSize) { return doStop(ctx); } - deadline = deadlines[index]; + deadline = this.deadlines[this.index]; } - this.index = index; - this.output.push((float) usageCol[index]); - return deadline + offset; + this.output.push((float) this.cpuUsages[this.index]); + return deadline + this.workloadOffset; } @Override @@ -366,7 +368,7 @@ public final class SimTrace { private final double[] usageCol; private final long[] deadlineCol; private final int[] coresCol; - private final int size; + private final int traceSize; private final SimMachineContext ctx; @@ -376,14 +378,14 @@ public final class SimTrace { double[] usageCol, long[] deadlineCol, int[] coresCol, - int size, + int traceSize, int index) { this.ctx = ctx; this.offset = offset; this.usageCol = usageCol; this.deadlineCol = deadlineCol; this.coresCol = coresCol; - this.size = size; + this.traceSize = traceSize; this.index = index; final FlowGraph graph = ctx.getGraph(); @@ -406,7 +408,6 @@ public final class SimTrace { @Override public long onUpdate(FlowStage ctx, long now) { - int size = this.size; long offset = this.offset; long nowOffset = now - offset; @@ -415,11 +416,11 @@ public final class SimTrace { long[] deadlines = deadlineCol; long deadline = deadlines[index]; - while (deadline <= nowOffset && ++index < size) { + while (deadline <= nowOffset && ++index < this.traceSize) { deadline = deadlines[index]; } - if (index >= size) { + if (index >= this.traceSize) { final SimMachineContext machineContext = this.ctx; if (machineContext != null) { machineContext.shutdown(); diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java index cad324fb..0c3779bd 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java @@ -50,4 +50,6 @@ public interface SimWorkload { * Create a snapshot of this workload. */ SimWorkload snapshot(); + + void setOffset(long now); } |
