summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-31 15:02:37 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-31 15:50:36 +0100
commitc9750e52a10157f3838b934fed4f04fae69c539a (patch)
tree1dd498da02298c9924f6c37974f4311df6948cb2 /opendc-simulator/opendc-simulator-compute/src/main
parent587a5af75d9adee5a3f765261931cd6e8ab6ff43 (diff)
feat(sim/compute): Add support for snapshotting workloads
This change updates the interface of `SimWorkload` to support snapshotting workloads. We introduce a new method `snapshot()` to this interface which returns a new `SimWorkload` that can be started at a later point in time and on another `SimMachine`, which continues progress from the moment the workload was snapshotted.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java7
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java32
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java15
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java11
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java49
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java5
8 files changed, 120 insertions, 9 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java
index 40c219ed..f684c54d 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java
@@ -131,6 +131,11 @@ public abstract class SimAbstractMachine implements SimMachine {
}
@Override
+ public SimWorkload snapshot() {
+ return workload.snapshot();
+ }
+
+ @Override
public void reset() {
final FlowGraph graph = getMemory().getInput().getGraph();
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java
index 0f7d4c8b..bce5c0a8 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java
@@ -69,6 +69,13 @@ public interface SimMachineContext {
List<? extends SimStorageInterface> getStorageInterfaces();
/**
+ * Create a snapshot of the {@link SimWorkload} running on this machine.
+ *
+ * @throws UnsupportedOperationException if the workload does not support snapshotting.
+ */
+ SimWorkload snapshot();
+
+ /**
* Reset all resources of the machine.
*/
void reset();
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 f03a0c20..4ebcba71 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
@@ -240,6 +240,11 @@ public final class SimHypervisor implements SimWorkload {
}
}
+ @Override
+ public SimWorkload snapshot() {
+ throw new UnsupportedOperationException("Unable to snapshot hypervisor");
+ }
+
/**
* The context which carries the state when the hypervisor is running on a machine.
*/
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 f838328b..7480b3c0 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
@@ -44,9 +44,20 @@ final class SimChainWorkload implements SimWorkload {
* Construct a {@link SimChainWorkload} instance.
*
* @param workloads The workloads to chain.
+ * @param activeWorkloadIndex The index of the active workload.
*/
- SimChainWorkload(SimWorkload... workloads) {
+ SimChainWorkload(SimWorkload[] workloads, int activeWorkloadIndex) {
this.workloads = workloads;
+ this.activeWorkloadIndex = activeWorkloadIndex;
+ }
+
+ /**
+ * Construct a {@link SimChainWorkload} instance.
+ *
+ * @param workloads The workloads to chain.
+ */
+ SimChainWorkload(SimWorkload... workloads) {
+ this(workloads, 0);
}
@Override
@@ -79,6 +90,19 @@ final class SimChainWorkload implements SimWorkload {
tryThrow(context.doStop(workloads[activeWorkloadIndex]));
}
+ @Override
+ public SimChainWorkload snapshot() {
+ final int activeWorkloadIndex = this.activeWorkloadIndex;
+ final SimWorkload[] workloads = this.workloads;
+ final SimWorkload[] newWorkloads = new SimWorkload[workloads.length - activeWorkloadIndex];
+
+ for (int i = 0; i < newWorkloads.length; i++) {
+ newWorkloads[i] = workloads[activeWorkloadIndex + i].snapshot();
+ }
+
+ return new SimChainWorkload(newWorkloads, 0);
+ }
+
/**
* A {@link SimMachineContext} that intercepts the shutdown calls.
*/
@@ -120,6 +144,12 @@ final class SimChainWorkload implements SimWorkload {
}
@Override
+ public SimWorkload snapshot() {
+ final SimWorkload workload = workloads[activeWorkloadIndex];
+ return workload.snapshot();
+ }
+
+ @Override
public void reset() {
ctx.reset();
}
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 f3efbebb..839856bb 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
@@ -60,6 +60,7 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic {
this.flops = flops;
this.utilization = utilization;
+ this.remainingAmount = flops;
}
@Override
@@ -98,8 +99,13 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic {
}
@Override
- public String toString() {
- return "SimFlopsWorkload[FLOPs=" + flops + ",utilization=" + utilization + "]";
+ public SimFlopsWorkload snapshot() {
+ final FlowStage stage = this.stage;
+ if (stage != null) {
+ stage.sync();
+ }
+
+ return new SimFlopsWorkload((long) remainingAmount, utilization);
}
@Override
@@ -138,4 +144,9 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic {
return now + duration;
}
+
+ @Override
+ public String toString() {
+ return "SimFlopsWorkload[FLOPs=" + flops + ",utilization=" + utilization + "]";
+ }
}
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 194efafd..9c9f4788 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
@@ -59,6 +59,7 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
this.duration = duration;
this.utilization = utilization;
+ this.remainingDuration = duration;
}
@Override
@@ -98,6 +99,16 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
}
@Override
+ public SimRuntimeWorkload snapshot() {
+ final FlowStage stage = this.stage;
+ if (stage != null) {
+ stage.sync();
+ }
+
+ return new SimRuntimeWorkload(remainingDuration, utilization);
+ }
+
+ @Override
public long onUpdate(FlowStage ctx, long now) {
long lastUpdate = this.lastUpdate;
this.lastUpdate = now;
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 12a567ff..1d8667d5 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
@@ -71,7 +71,7 @@ public final class SimTrace {
* @param offset The offset for the timestamps.
*/
public SimWorkload createWorkload(long offset) {
- return new Workload(offset, usageCol, deadlineCol, coresCol, size);
+ return new Workload(offset, usageCol, deadlineCol, coresCol, size, 0);
}
/**
@@ -211,22 +211,24 @@ public final class SimTrace {
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) {
+ private Workload(long offset, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) {
this.offset = offset;
this.usageCol = usageCol;
this.deadlineCol = deadlineCol;
this.coresCol = coresCol;
this.size = size;
+ this.index = index;
}
@Override
public void onStart(SimMachineContext ctx) {
final WorkloadStageLogic logic;
if (ctx.getCpus().size() == 1) {
- logic = new SingleWorkloadLogic(ctx, offset, usageCol, deadlineCol, size);
+ logic = new SingleWorkloadLogic(ctx, offset, usageCol, deadlineCol, size, index);
} else {
- logic = new MultiWorkloadLogic(ctx, offset, usageCol, deadlineCol, coresCol, size);
+ logic = new MultiWorkloadLogic(ctx, offset, usageCol, deadlineCol, coresCol, size, index);
}
this.logic = logic;
}
@@ -240,6 +242,18 @@ public final class SimTrace {
logic.getStage().close();
}
}
+
+ @Override
+ public SimWorkload snapshot() {
+ final WorkloadStageLogic logic = this.logic;
+ int index = this.index;
+
+ if (logic != null) {
+ index = logic.getIndex();
+ }
+
+ return new Workload(offset, usageCol, deadlineCol, coresCol, size, index);
+ }
}
/**
@@ -250,6 +264,11 @@ public final class SimTrace {
* Return the {@link FlowStage} belonging to this instance.
*/
FlowStage getStage();
+
+ /**
+ * Return the current index of the workload.
+ */
+ int getIndex();
}
/**
@@ -268,12 +287,13 @@ public final class SimTrace {
private final SimMachineContext ctx;
private SingleWorkloadLogic(
- SimMachineContext ctx, long offset, double[] usageCol, long[] deadlineCol, int size) {
+ 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.index = index;
final FlowGraph graph = ctx.getGraph();
final List<? extends SimProcessingUnit> cpus = ctx.getCpus();
@@ -315,6 +335,11 @@ public final class SimTrace {
return stage;
}
+ @Override
+ public int getIndex() {
+ return index;
+ }
+
/**
* Helper method to stop the execution of the workload.
*/
@@ -346,13 +371,20 @@ public final class SimTrace {
private final SimMachineContext ctx;
private MultiWorkloadLogic(
- SimMachineContext ctx, long offset, double[] usageCol, long[] deadlineCol, int[] coresCol, int size) {
+ SimMachineContext ctx,
+ long offset,
+ double[] usageCol,
+ long[] deadlineCol,
+ int[] coresCol,
+ int size,
+ int index) {
this.ctx = ctx;
this.offset = offset;
this.usageCol = usageCol;
this.deadlineCol = deadlineCol;
this.coresCol = coresCol;
this.size = size;
+ this.index = index;
final FlowGraph graph = ctx.getGraph();
final List<? extends SimProcessingUnit> cpus = ctx.getCpus();
@@ -418,5 +450,10 @@ public final class SimTrace {
public FlowStage getStage() {
return stage;
}
+
+ @Override
+ public int getIndex() {
+ return index;
+ }
}
}
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 7be51265..cad324fb 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
@@ -45,4 +45,9 @@ public interface SimWorkload {
* @param ctx The execution context in which the machine runs.
*/
void onStop(SimMachineContext ctx);
+
+ /**
+ * Create a snapshot of this workload.
+ */
+ SimWorkload snapshot();
}