summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-21 16:35:52 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-21 16:37:18 +0200
commit62678b2890a7f3640836b99ca2fec9efd7485929 (patch)
treedc6d6e8bb495c019990513511d7ff042afde0f05 /simulator/opendc-simulator/opendc-simulator-compute/src
parent1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 (diff)
simulator: Migrate to SimulationCoroutineDispatcher
This change migrates the remainder of the codebase to the SimulationCoroutineDispatcher implementation.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt24
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt13
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt19
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt30
4 files changed, 34 insertions, 52 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt
index 99a5fa02..7b97a665 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt
@@ -25,8 +25,6 @@ package org.opendc.simulator.compute
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.TestCoroutineScope
-import kotlinx.coroutines.test.runBlockingTest
import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor
import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver
import org.opendc.simulator.compute.model.MemoryUnit
@@ -34,7 +32,8 @@ import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.workload.SimWorkload
-import org.opendc.simulator.core.DelayControllerClockAdapter
+import org.opendc.simulator.core.SimulationCoroutineScope
+import org.opendc.simulator.core.runBlockingSimulation
import org.opendc.utils.TimerScheduler
import org.openjdk.jmh.annotations.*
import java.time.Clock
@@ -46,15 +45,14 @@ import java.util.concurrent.TimeUnit
@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS)
@OptIn(ExperimentalCoroutinesApi::class)
class SimMachineBenchmarks {
- private lateinit var scope: TestCoroutineScope
+ private lateinit var scope: SimulationCoroutineScope
private lateinit var clock: Clock
private lateinit var scheduler: TimerScheduler<Any>
private lateinit var machineModel: SimMachineModel
@Setup
fun setUp() {
- scope = TestCoroutineScope()
- clock = DelayControllerClockAdapter(scope)
+ scope = SimulationCoroutineScope()
scheduler = TimerScheduler(scope.coroutineContext, clock)
val cpuNode = ProcessingNode("Intel", "Xeon", "amd64", 2)
@@ -77,18 +75,18 @@ class SimMachineBenchmarks {
@Benchmark
fun benchmarkBareMetal(state: Workload) {
- return scope.runBlockingTest {
+ return scope.runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))
)
- return@runBlockingTest machine.run(state.workloads[0])
+ return@runBlockingSimulation machine.run(state.workloads[0])
}
}
@Benchmark
fun benchmarkSpaceSharedHypervisor(state: Workload) {
- return scope.runBlockingTest {
+ return scope.runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))
@@ -100,7 +98,7 @@ class SimMachineBenchmarks {
val vm = hypervisor.createMachine(machineModel)
try {
- return@runBlockingTest vm.run(state.workloads[0])
+ return@runBlockingSimulation vm.run(state.workloads[0])
} finally {
vm.close()
machine.close()
@@ -110,7 +108,7 @@ class SimMachineBenchmarks {
@Benchmark
fun benchmarkFairShareHypervisorSingle(state: Workload) {
- return scope.runBlockingTest {
+ return scope.runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))
@@ -122,7 +120,7 @@ class SimMachineBenchmarks {
val vm = hypervisor.createMachine(machineModel)
try {
- return@runBlockingTest vm.run(state.workloads[0])
+ return@runBlockingSimulation vm.run(state.workloads[0])
} finally {
vm.close()
machine.close()
@@ -132,7 +130,7 @@ class SimMachineBenchmarks {
@Benchmark
fun benchmarkFairShareHypervisorDouble(state: Workload) {
- return scope.runBlockingTest {
+ return scope.runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
index 2c87421f..a067dd2e 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
@@ -26,7 +26,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
@@ -39,7 +38,7 @@ import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.workload.SimTraceWorkload
-import org.opendc.simulator.core.DelayControllerClockAdapter
+import org.opendc.simulator.core.runBlockingSimulation
/**
* Test suite for the [SimHypervisor] class.
@@ -61,8 +60,7 @@ internal class SimHypervisorTest {
* Test overcommitting of resources via the hypervisor with a single VM.
*/
@Test
- fun testOvercommittedSingle() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testOvercommittedSingle() = runBlockingSimulation {
val listener = object : SimHypervisor.Listener {
var totalRequestedWork = 0L
var totalGrantedWork = 0L
@@ -116,7 +114,7 @@ internal class SimHypervisorTest {
{ assertEquals(1023300, listener.totalGrantedWork, "Granted Burst does not match") },
{ assertEquals(90000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
{ assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), res) { "VM usage is correct" } },
- { assertEquals(1200000, currentTime) { "Current time is correct" } }
+ { assertEquals(1200000, clock.millis()) { "Current time is correct" } }
)
}
@@ -124,8 +122,7 @@ internal class SimHypervisorTest {
* Test overcommitting of resources via the hypervisor with two VMs.
*/
@Test
- fun testOvercommittedDual() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testOvercommittedDual() = runBlockingSimulation {
val listener = object : SimHypervisor.Listener {
var totalRequestedWork = 0L
var totalGrantedWork = 0L
@@ -195,7 +192,7 @@ internal class SimHypervisorTest {
{ assertEquals(2082000, listener.totalRequestedWork, "Requested Burst does not match") },
{ assertEquals(1062000, listener.totalGrantedWork, "Granted Burst does not match") },
{ assertEquals(1020000, listener.totalOvercommittedWork, "Overcommissioned Burst does not match") },
- { assertEquals(1200000, currentTime) }
+ { assertEquals(1200000, clock.millis()) }
)
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index 64524452..205f2eca 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -24,7 +24,6 @@ package org.opendc.simulator.compute
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.toList
-import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -37,7 +36,7 @@ import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.workload.SimFlopsWorkload
-import org.opendc.simulator.core.DelayControllerClockAdapter
+import org.opendc.simulator.core.runBlockingSimulation
/**
* Test suite for the [SimBareMetalMachine] class.
@@ -57,23 +56,21 @@ class SimMachineTest {
}
@Test
- fun testFlopsWorkload() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testFlopsWorkload() = runBlockingSimulation {
val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0)))
try {
machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
// Two cores execute 1000 MFlOps per second (1000 ms)
- assertEquals(1000, currentTime)
+ assertEquals(1000, clock.millis())
} finally {
machine.close()
}
}
@Test
- fun testDualSocketMachine() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testDualSocketMachine() = runBlockingSimulation {
val cpuNode = machineModel.cpus[0].node
val machineModel = SimMachineModel(
cpus = List(cpuNode.coreCount * 2) { ProcessingUnit(cpuNode, it % 2, 1000.0) },
@@ -85,15 +82,14 @@ class SimMachineTest {
machine.run(SimFlopsWorkload(2_000, utilization = 1.0))
// Two sockets with two cores execute 2000 MFlOps per second (500 ms)
- assertEquals(500, currentTime)
+ assertEquals(500, clock.millis())
} finally {
machine.close()
}
}
@Test
- fun testUsage() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testUsage() = runBlockingSimulation {
val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0)))
val res = mutableListOf<Double>()
@@ -110,8 +106,7 @@ class SimMachineTest {
}
@Test
- fun testClose() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testClose() = runBlockingSimulation {
val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0)))
machine.close()
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
index fc2bc720..ef6f536d 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt
@@ -25,7 +25,6 @@ package org.opendc.simulator.compute
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.launch
-import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
@@ -40,7 +39,7 @@ import org.opendc.simulator.compute.power.ConstantPowerModel
import org.opendc.simulator.compute.workload.SimFlopsWorkload
import org.opendc.simulator.compute.workload.SimRuntimeWorkload
import org.opendc.simulator.compute.workload.SimTraceWorkload
-import org.opendc.simulator.core.DelayControllerClockAdapter
+import org.opendc.simulator.core.runBlockingSimulation
/**
* A test suite for the [SimSpaceSharedHypervisor].
@@ -62,8 +61,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test a trace workload.
*/
@Test
- fun testTrace() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testTrace() = runBlockingSimulation {
val usagePm = mutableListOf<Double>()
val usageVm = mutableListOf<Double>()
@@ -103,7 +101,7 @@ internal class SimSpaceSharedHypervisorTest {
{ assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usagePm) { "Correct PM usage" } },
// Temporary limitation is that VMs do not emit usage information
// { assertEquals(listOf(0.0, 0.00875, 1.0, 0.0, 0.0571875, 0.0), usageVm) { "Correct VM usage" } },
- { assertEquals(5 * 60L * 4000, currentTime) { "Took enough time" } }
+ { assertEquals(5 * 60L * 4000, clock.millis()) { "Took enough time" } }
)
}
@@ -111,8 +109,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test runtime workload on hypervisor.
*/
@Test
- fun testRuntimeWorkload() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testRuntimeWorkload() = runBlockingSimulation {
val duration = 5 * 60L * 1000
val workload = SimRuntimeWorkload(duration)
val machine = SimBareMetalMachine(
@@ -128,16 +125,14 @@ internal class SimSpaceSharedHypervisorTest {
vm.close()
machine.close()
- assertEquals(duration, currentTime) { "Took enough time" }
+ assertEquals(duration, clock.millis()) { "Took enough time" }
}
/**
* Test FLOPs workload on hypervisor.
*/
@Test
- fun testFlopsWorkload() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
-
+ fun testFlopsWorkload() = runBlockingSimulation {
val duration = 5 * 60L * 1000
val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0)
val machine = SimBareMetalMachine(
@@ -152,15 +147,14 @@ internal class SimSpaceSharedHypervisorTest {
vm.run(workload)
machine.close()
- assertEquals(duration, currentTime) { "Took enough time" }
+ assertEquals(duration, clock.millis()) { "Took enough time" }
}
/**
* Test two workloads running sequentially.
*/
@Test
- fun testTwoWorkloads() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testTwoWorkloads() = runBlockingSimulation {
val duration = 5 * 60L * 1000
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
@@ -180,15 +174,14 @@ internal class SimSpaceSharedHypervisorTest {
vm2.close()
machine.close()
- assertEquals(duration * 2, currentTime) { "Took enough time" }
+ assertEquals(duration * 2, clock.millis()) { "Took enough time" }
}
/**
* Test concurrent workloads on the machine.
*/
@Test
- fun testConcurrentWorkloadFails() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testConcurrentWorkloadFails() = runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))
@@ -212,8 +205,7 @@ internal class SimSpaceSharedHypervisorTest {
* Test concurrent workloads on the machine.
*/
@Test
- fun testConcurrentWorkloadSucceeds() = runBlockingTest {
- val clock = DelayControllerClockAdapter(this)
+ fun testConcurrentWorkloadSucceeds() = runBlockingSimulation {
val machine = SimBareMetalMachine(
coroutineContext, clock, machineModel, PerformanceScalingGovernor(),
SimpleScalingDriver(ConstantPowerModel(0.0))