diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 11:56:49 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-10-28 12:03:39 +0200 |
| commit | 801ef92fb4d65e301e2488528f1cadd8b4ab6fdd (patch) | |
| tree | 72dc8db0725a1b157241901ba1097775bea3f53e /opendc-simulator | |
| parent | 788c007599ac61a41460589f65454aac1857eb81 (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')
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(); |
