summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 11:56:49 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-10-28 12:03:39 +0200
commit801ef92fb4d65e301e2488528f1cadd8b4ab6fdd (patch)
tree72dc8db0725a1b157241901ba1097775bea3f53e /opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc
parent788c007599ac61a41460589f65454aac1857eb81 (diff)
feat(sim/compute): Add support for resetting machine context
This change updates the interface of `SimMachineContext` to allow workloads to reset all resources provided by the machine to the workload. This allows us to implement a `SimWorkload` that can compose multiple workloads.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimAbstractMachine.java41
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/SimMachineContext.java5
2 files changed, 28 insertions, 18 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 d90a7d6f..d968d884 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
@@ -135,6 +135,28 @@ public abstract class SimAbstractMachine implements SimMachine {
}
@Override
+ public void reset() {
+ final FlowGraph graph = getMemory().getInput().getGraph();
+
+ for (SimProcessingUnit cpu : getCpus()) {
+ final Inlet inlet = cpu.getInput();
+ graph.disconnect(inlet);
+ }
+
+ graph.disconnect(getMemory().getInput());
+
+ for (SimNetworkInterface ifx : getNetworkInterfaces()) {
+ ((NetworkAdapter) ifx).disconnect();
+ }
+
+ for (SimStorageInterface storage : getStorageInterfaces()) {
+ StorageDevice impl = (StorageDevice) storage;
+ graph.disconnect(impl.getRead());
+ graph.disconnect(impl.getWrite());
+ }
+ }
+
+ @Override
public final void shutdown() {
if (isClosed) {
return;
@@ -180,24 +202,7 @@ public abstract class SimAbstractMachine implements SimMachine {
* Run the stop procedures for the resources associated with the machine.
*/
protected void doCancel() {
- final FlowGraph graph = getMemory().getInput().getGraph();
-
- for (SimProcessingUnit cpu : getCpus()) {
- final Inlet inlet = cpu.getInput();
- graph.disconnect(inlet);
- }
-
- graph.disconnect(getMemory().getInput());
-
- for (SimNetworkInterface ifx : getNetworkInterfaces()) {
- ((NetworkAdapter) ifx).disconnect();
- }
-
- for (SimStorageInterface storage : getStorageInterfaces()) {
- StorageDevice impl = (StorageDevice) storage;
- graph.disconnect(impl.getRead());
- graph.disconnect(impl.getWrite());
- }
+ reset();
}
@Override
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 f6a3bd38..5d08e2b7 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
@@ -68,6 +68,11 @@ public interface SimMachineContext {
List<? extends SimStorageInterface> getStorageInterfaces();
/**
+ * Reset all resources of the machine.
+ */
+ void reset();
+
+ /**
* Shutdown the workload.
*/
void shutdown();