summaryrefslogtreecommitdiff
path: root/opendc-omega
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-omega')
-rw-r--r--opendc-omega/src/main/kotlin/nl/atlarge/opendc/kernel/omega/OmegaSimulation.kt34
-rw-r--r--opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt41
2 files changed, 66 insertions, 9 deletions
diff --git a/opendc-omega/src/main/kotlin/nl/atlarge/opendc/kernel/omega/OmegaSimulation.kt b/opendc-omega/src/main/kotlin/nl/atlarge/opendc/kernel/omega/OmegaSimulation.kt
index a29f2b08..67b192fb 100644
--- a/opendc-omega/src/main/kotlin/nl/atlarge/opendc/kernel/omega/OmegaSimulation.kt
+++ b/opendc-omega/src/main/kotlin/nl/atlarge/opendc/kernel/omega/OmegaSimulation.kt
@@ -202,7 +202,7 @@ internal class OmegaSimulation(override val kernel: OmegaKernel, override val to
/**
* The last point in time the process has done some work.
*/
- var last: Instant = 0
+ var last: Instant = -1
/**
* The state of the entity.
@@ -332,7 +332,11 @@ internal class OmegaSimulation(override val kernel: OmegaKernel, override val to
* @param duration The duration of simulation time to wait before resuming execution.
*/
suspend override fun wait(duration: Duration) {
- require(duration > 0) { "The amount of time to suspend must be a non-zero positive number" }
+ require(duration >= 0) { "The amount of time to suspend must be a positive number" }
+
+ if (duration == 0.toLong())
+ return
+
schedule(Resume, entity, entity, duration)
while (true) {
@@ -342,6 +346,32 @@ internal class OmegaSimulation(override val kernel: OmegaKernel, override val to
}
/**
+ * Suspend the [Process] of the [Entity] in simulation for the given duration of simulation time before resuming
+ * execution and push all messages that are received during this period to the given queue.
+ *
+ * A call to this method will not make the [Process] sleep for the actual duration of time, but instead suspend
+ * the process until the no more messages at an earlier point in time have to be processed.
+ *
+ * @param duration The duration of simulation time to wait before resuming execution.
+ * @param queue The mutable queue to push the messages to.
+ */
+ suspend override fun wait(duration: Duration, queue: Queue<Any>) {
+ require(duration >= 0) { "The amount of time to suspend must be a positive number" }
+
+ if (duration == 0.toLong())
+ return
+
+ schedule(Resume, entity, entity, duration)
+
+ while (true) {
+ val msg = receive()
+ if (msg is Resume)
+ return
+ queue.add(msg)
+ }
+ }
+
+ /**
* Update the state of the entity being simulated.
*
* <p>Instead of directly mutating the entity, we create a new instance of the entity to prevent other objects
diff --git a/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt
index 4f48f20d..e2eb8269 100644
--- a/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt
+++ b/opendc-omega/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt
@@ -25,25 +25,46 @@
package nl.atlarge.opendc
import nl.atlarge.opendc.kernel.omega.OmegaKernel
+import nl.atlarge.opendc.scheduler.FifoScheduler
+import nl.atlarge.opendc.scheduler.SrtfScheduler
import nl.atlarge.opendc.topology.AdjacencyList
+import nl.atlarge.opendc.topology.container.Datacenter
import nl.atlarge.opendc.topology.container.Rack
+import nl.atlarge.opendc.topology.container.Room
import nl.atlarge.opendc.topology.machine.Cpu
import nl.atlarge.opendc.topology.machine.Machine
+import nl.atlarge.opendc.workload.Task
import org.junit.jupiter.api.Test
+import java.util.*
internal class SmokeTest {
@Test
fun smoke() {
- val rack = Rack()
+ val datacenter = Datacenter(SrtfScheduler(), 50)
val builder = AdjacencyList.builder()
val topology = builder.construct {
- add(rack)
- val n = 100
+ add(datacenter)
+
+ // Add a room to the datacenter
+ val room = Room().also {
+ add(it)
+ connect(datacenter, it, tag = "room")
+ }
+
+ // Add a rack to the room
+ val rack = Rack().also {
+ add(it)
+ connect(room, it, tag = "rack")
+ }
+
+ val n = 10
+
// Create n machines in the rack
repeat(n) {
- val machine = Machine()
- add(machine)
- connect(rack, machine, tag = "machine")
+ val machine = Machine().also {
+ add(it)
+ connect(rack, it, tag = "machine")
+ }
val cpu1 = Cpu(10, 2, 2)
val cpu2 = Cpu(5, 3, 2)
@@ -56,6 +77,12 @@ internal class SmokeTest {
}
val simulation = OmegaKernel.create(topology)
- simulation.run()
+ val random = Random(0)
+ for (i in 0..100) {
+ val task = Task(i, emptySet(), random.nextInt(10000).toLong())
+ simulation.schedule(task, datacenter, delay = random.nextInt(15000).toLong())
+ }
+ simulation.run(50000)
+
}
}