summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/test
diff options
context:
space:
mode:
authorHongyu <hongyuhe.cs@googlemail.com>2021-06-14 13:37:52 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-06-20 21:19:58 +0200
commit85e8303f12b319e2eb231584324327f28d43fc2c (patch)
tree68d511ef0daf622bc5314d8f57ba9492a51a155f /opendc-simulator/opendc-simulator-compute/src/test
parente24e7c1601257cf27d71db8ca3ae273b24ab06ed (diff)
simulator: Add Linux CPU frequency scaling governors
This change adds the CPU frequency scaling governors that are found in the Linux kernel, which include the conservative and on-demand governor.
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/cpufreq/ConservativeScalingGovernorTest.kt98
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/OnDemandScalingGovernorTest.kt81
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt19
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PowerSaveScalingGovernorTest.kt72
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerDriverTest.kt10
5 files changed, 265 insertions, 15 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/ConservativeScalingGovernorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/ConservativeScalingGovernorTest.kt
new file mode 100644
index 00000000..59817f1d
--- /dev/null
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/ConservativeScalingGovernorTest.kt
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.simulator.compute.cpufreq
+
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.verify
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+/**
+ * Test suite for the [ConservativeScalingGovernor]
+ */
+internal class ConservativeScalingGovernorTest {
+ @Test
+ fun testSetStartLimitWithoutPStates() {
+ val cpuCapacity = 4100.0
+ val minSpeed = cpuCapacity / 2
+ val defaultThreshold = 0.8
+ val defaultStepSize = 0.05 * cpuCapacity
+ val governor = ConservativeScalingGovernor()
+
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ every { policy.max } returns cpuCapacity
+ every { policy.min } returns minSpeed
+
+ var target = 0.0
+ every { policy.target } answers { target }
+ every { policy.target = any() } propertyType Double::class answers { target = value }
+
+ val logic = governor.createLogic(policy)
+ logic.onStart()
+ assertEquals(defaultThreshold, governor.threshold)
+
+ logic.onLimit(0.5)
+
+ /* Upwards scaling */
+ logic.onLimit(defaultThreshold + 0.2)
+
+ /* Downwards scaling */
+ logic.onLimit(defaultThreshold + 0.1)
+
+ verify(exactly = 2) { policy.target = minSpeed }
+ verify(exactly = 1) { policy.target = minSpeed + defaultStepSize }
+ }
+
+ @Test
+ fun testSetStartLimitWithPStatesAndParams() {
+ val firstPState = 1000.0
+ val cpuCapacity = 4100.0
+ val minSpeed = firstPState
+ val threshold = 0.5
+ val stepSize = 0.02 * cpuCapacity
+ val governor = ConservativeScalingGovernor(threshold, stepSize)
+
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ every { policy.max } returns cpuCapacity
+ every { policy.min } returns firstPState
+
+ var target = 0.0
+ every { policy.target } answers { target }
+ every { policy.target = any() } propertyType Double::class answers { target = value }
+
+ val logic = governor.createLogic(policy)
+ logic.onStart()
+ assertEquals(threshold, governor.threshold)
+ logic.onLimit(0.5)
+
+ /* Upwards scaling */
+ logic.onLimit(threshold + 0.2)
+
+ /* Downwards scaling */
+ logic.onLimit(threshold + 0.1)
+
+ verify(exactly = 2) { policy.target = minSpeed }
+ verify(exactly = 1) { policy.target = minSpeed + stepSize }
+ }
+}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/OnDemandScalingGovernorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/OnDemandScalingGovernorTest.kt
new file mode 100644
index 00000000..c0c25c97
--- /dev/null
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/OnDemandScalingGovernorTest.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.simulator.compute.cpufreq
+
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.verify
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+/**
+ * Test suite for the [OnDemandScalingGovernor]
+ */
+internal class OnDemandScalingGovernorTest {
+ @Test
+ fun testSetStartLimitWithoutPStates() {
+ val cpuCapacity = 4100.0
+ val minSpeed = cpuCapacity / 2
+ val defaultThreshold = 0.8
+ val governor = OnDemandScalingGovernor()
+
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ every { policy.min } returns minSpeed
+ every { policy.max } returns cpuCapacity
+
+ val logic = governor.createLogic(policy)
+ logic.onStart()
+ assertEquals(defaultThreshold, governor.threshold)
+ verify(exactly = 1) { policy.target = minSpeed }
+
+ logic.onLimit(0.5)
+ verify(exactly = 1) { policy.target = minSpeed + 0.5 * (cpuCapacity - minSpeed) / 100 }
+
+ logic.onLimit(defaultThreshold)
+ verify(exactly = 1) { policy.target = cpuCapacity }
+ }
+
+ @Test
+ fun testSetStartLimitWithPStatesAndParams() {
+ val firstPState = 1000.0
+ val cpuCapacity = 4100.0
+ val threshold = 0.5
+ val governor = OnDemandScalingGovernor(threshold)
+
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ every { policy.max } returns cpuCapacity
+ every { policy.min } returns firstPState
+
+ val logic = governor.createLogic(policy)
+
+ logic.onStart()
+ assertEquals(threshold, governor.threshold)
+ verify(exactly = 1) { policy.target = firstPState }
+
+ logic.onLimit(0.1)
+ verify(exactly = 1) { policy.target = firstPState + 0.1 * (cpuCapacity - firstPState) / 100 }
+
+ logic.onLimit(threshold)
+ verify(exactly = 1) { policy.target = cpuCapacity }
+ }
+}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt
index 8e8b09c8..d7bd6193 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernorTest.kt
@@ -23,10 +23,9 @@
package org.opendc.simulator.compute.cpufreq
import io.mockk.every
-import io.mockk.mockk
+import io.mockk.spyk
import io.mockk.verify
import org.junit.jupiter.api.Test
-import org.opendc.simulator.compute.SimProcessingUnit
/**
* Test suite for the [PerformanceScalingGovernor]
@@ -34,16 +33,18 @@ import org.opendc.simulator.compute.SimProcessingUnit
internal class PerformanceScalingGovernorTest {
@Test
fun testSetStartLimit() {
- val cpu = mockk<SimProcessingUnit>(relaxUnitFun = true)
+ val policy = spyk<ScalingPolicy>()
+ val logic = PerformanceScalingGovernor().createLogic(policy)
- every { cpu.model.frequency } returns 4100.0
- every { cpu.speed } returns 2100.0
-
- val logic = PerformanceScalingGovernor().createLogic(cpu)
+ every { policy.max } returns 4100.0
logic.onStart()
- logic.onLimit(1.0)
+ verify(exactly = 1) { policy.target = 4100.0 }
- verify(exactly = 1) { cpu.capacity = 4100.0 }
+ logic.onLimit(0.0)
+ verify(exactly = 1) { policy.target = 4100.0 }
+
+ logic.onLimit(1.0)
+ verify(exactly = 1) { policy.target = 4100.0 }
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PowerSaveScalingGovernorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PowerSaveScalingGovernorTest.kt
new file mode 100644
index 00000000..8d841981
--- /dev/null
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/cpufreq/PowerSaveScalingGovernorTest.kt
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.simulator.compute.cpufreq
+
+import io.mockk.every
+import io.mockk.mockk
+import io.mockk.verify
+import org.junit.jupiter.api.Test
+
+/**
+ * Test suite for the [PowerSaveScalingGovernor]
+ */
+internal class PowerSaveScalingGovernorTest {
+ @Test
+ fun testSetStartLimitWithoutPStates() {
+ val cpuCapacity = 4100.0
+ val minSpeed = cpuCapacity / 2
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ val logic = PowerSaveScalingGovernor().createLogic(policy)
+
+ every { policy.max } returns cpuCapacity
+ every { policy.min } returns minSpeed
+
+ logic.onStart()
+
+ logic.onLimit(0.0)
+ verify(exactly = 1) { policy.target = minSpeed }
+
+ logic.onLimit(1.0)
+ verify(exactly = 1) { policy.target = minSpeed }
+ }
+
+ @Test
+ fun testSetStartLimitWithPStates() {
+ val cpuCapacity = 4100.0
+ val firstPState = 1000.0
+ val policy = mockk<ScalingPolicy>(relaxUnitFun = true)
+ val logic = PowerSaveScalingGovernor().createLogic(policy)
+
+ every { policy.max } returns cpuCapacity
+ every { policy.min } returns firstPState
+
+ logic.onStart()
+ verify(exactly = 1) { policy.target = firstPState }
+
+ logic.onLimit(0.0)
+ verify(exactly = 1) { policy.target = firstPState }
+
+ logic.onLimit(1.0)
+ verify(exactly = 1) { policy.target = firstPState }
+ }
+}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerDriverTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerDriverTest.kt
index 35fd7c4c..c39859bf 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerDriverTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/PStatePowerDriverTest.kt
@@ -52,7 +52,7 @@ internal class PStatePowerDriverTest {
@Test
fun testPowerWithSingleCpu() {
val machine = mockk<SimBareMetalMachine>()
- val cpu = mockk<SimProcessingUnit>()
+ val cpu = mockk<SimProcessingUnit>(relaxUnitFun = true)
every { cpu.capacity } returns 3200.0
every { cpu.speed } returns 1200.0
@@ -73,10 +73,8 @@ internal class PStatePowerDriverTest {
@Test
fun testPowerWithMultipleCpus() {
val machine = mockk<SimBareMetalMachine>()
- val cpus = listOf(
- mockk<SimProcessingUnit>(),
- mockk()
- )
+ val cpu = mockk<SimProcessingUnit>(relaxUnitFun = true)
+ val cpus = listOf(cpu, cpu)
every { cpus[0].capacity } returns 1000.0
every { cpus[0].speed } returns 1200.0
@@ -100,7 +98,7 @@ internal class PStatePowerDriverTest {
@Test
fun testPowerBasedOnUtilization() {
val machine = mockk<SimBareMetalMachine>()
- val cpu = mockk<SimProcessingUnit>()
+ val cpu = mockk<SimProcessingUnit>(relaxUnitFun = true)
every { cpu.model.frequency } returns 4200.0