summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-03 13:31:59 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-03 13:44:41 +0200
commitcef12722f03a24a0e1e3b7502fb5e434d93f1664 (patch)
tree587cd8fcc67cddc7e24c60a973cc4f10e1426608 /opendc-simulator/opendc-simulator-compute/src/test
parent84468f4e3a331d7ea073ac7033b3d9937168ed9f (diff)
simulator: Migrate frequency scaling governors to OS layer
This change moves the CPU frequency scaling governors from the bare-metal/firmware layer (SimBareMetalMachine) to the OS/Hypervisor layer (SimHypervisor) where it can make more informed decisions about the CPU frequency based on the load of the operating system or hypervisor.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt (renamed from opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt)19
2 files changed, 13 insertions, 11 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
index 0bcfd9c6..b15692ec 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt
@@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
import org.junit.jupiter.api.assertDoesNotThrow
+import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor
import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
@@ -95,7 +96,7 @@ internal class SimHypervisorTest {
val platform = SimResourceInterpreter(coroutineContext, clock)
val machine = SimBareMetalMachine(platform, model, SimplePowerDriver(ConstantPowerModel(0.0)))
- val hypervisor = SimFairShareHypervisor(platform, null, listener)
+ val hypervisor = SimFairShareHypervisor(platform, scalingGovernor = PerformanceScalingGovernor(), listener = listener)
launch {
machine.run(hypervisor)
@@ -169,7 +170,7 @@ internal class SimHypervisorTest {
val machine = SimBareMetalMachine(
platform, model, SimplePowerDriver(ConstantPowerModel(0.0))
)
- val hypervisor = SimFairShareHypervisor(platform, null, listener)
+ val hypervisor = SimFairShareHypervisor(platform, listener = listener)
launch {
machine.run(hypervisor)
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt
index c482d348..8e8b09c8 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt
@@ -26,23 +26,24 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
+import org.opendc.simulator.compute.SimProcessingUnit
/**
- * Test suite for the [DemandScalingGovernor]
+ * Test suite for the [PerformanceScalingGovernor]
*/
-internal class DemandScalingGovernorTest {
+internal class PerformanceScalingGovernorTest {
@Test
- fun testSetDemandLimit() {
- val ctx = mockk<ScalingContext>(relaxUnitFun = true)
+ fun testSetStartLimit() {
+ val cpu = mockk<SimProcessingUnit>(relaxUnitFun = true)
- every { ctx.cpu.speed } returns 2100.0
+ every { cpu.model.frequency } returns 4100.0
+ every { cpu.speed } returns 2100.0
- val logic = DemandScalingGovernor().createLogic(ctx)
+ val logic = PerformanceScalingGovernor().createLogic(cpu)
logic.onStart()
- verify(exactly = 0) { ctx.setTarget(any()) }
+ logic.onLimit(1.0)
- logic.onLimit()
- verify(exactly = 1) { ctx.setTarget(2100.0) }
+ verify(exactly = 1) { cpu.capacity = 4100.0 }
}
}