summaryrefslogtreecommitdiff
path: root/opendc-experiments
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-19 17:27:01 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 17:58:54 +0200
commit86c65e875b7dde8872dc81a37aa9dca72eee7782 (patch)
tree6249023f8f0d56392400c7ebb72238ee848f740a /opendc-experiments
parentba310a3545c9631e1e4ff61a0a1759228ec5cf63 (diff)
refactor(simulator): Support running workloads without coroutines
This change updates the SimMachine interface to drop the coroutine requirement for running a workload on a machines. Users can now asynchronously start a workload and receive notifications via the workload callbacks. Users still have the possibility to suspend execution during workload execution by using the new `runWorkload` method, which is implemented on top of the new `startWorkload` primitive.
Diffstat (limited to 'opendc-experiments')
-rw-r--r--opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt7
1 files changed, 5 insertions, 2 deletions
diff --git a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
index fb36d2c7..1752802f 100644
--- a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
+++ b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt
@@ -34,6 +34,7 @@ import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.power.PowerModel
import org.opendc.simulator.compute.power.SimplePowerDriver
+import org.opendc.simulator.compute.runWorkload
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.flow.*
import java.time.Clock
@@ -128,6 +129,8 @@ public class SimTFDevice(
}
}
+ override fun onStop(ctx: SimMachineContext) {}
+
override fun onStart(conn: FlowConnection, now: Long) {
ctx = conn
capacity = conn.capacity
@@ -172,7 +175,7 @@ public class SimTFDevice(
init {
scope.launch {
- machine.run(workload)
+ machine.runWorkload(workload)
}
}
@@ -189,7 +192,7 @@ public class SimTFDevice(
}
override fun close() {
- machine.close()
+ machine.cancel()
scope.cancel()
}