diff options
| author | Hongyu <hongyuhe.cs@googlemail.com> | 2021-03-16 09:08:51 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-18 11:37:43 +0100 |
| commit | dd24782f3710678151c80f8ad365eecc7389b6f8 (patch) | |
| tree | 6e5ddf4e61e70495d67d4220f7657e7b271301e8 /simulator/opendc-compute/opendc-compute-simulator/src/test | |
| parent | 054a3d376b8b31ba98f91e7b34c6e0ca717def18 (diff) | |
simulator: Add the CPU power model from iCanCloud/E-mc2
This change implements the CPU energy model with p-states from iCanCloud/E-mc2:
- Only pushed a portion of the code for discussion as not sure if the idea is
on track.
- Inline comments have been added, and formal documents will follow once the
model is finalized.
- The p-state power consumptions are currently hard-coded in a companion
object, which should be improved in the next PR(s).
**Breaking Changes**
- CpuPowerModel: directly interact with the machine it is measuring.
- SimBareMetalMachine: expose the speeds of its CPU cores and its clock
instant.
Diffstat (limited to 'simulator/opendc-compute/opendc-compute-simulator/src/test')
2 files changed, 47 insertions, 6 deletions
diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt index 9d034a5d..cd18b120 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt +++ b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/CpuPowerModelTest.kt @@ -8,7 +8,6 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource -import org.opendc.compute.simulator.SimHost import org.opendc.compute.simulator.power.api.CpuPowerModel import org.opendc.compute.simulator.power.models.* import org.opendc.simulator.compute.SimBareMetalMachine @@ -18,7 +17,7 @@ import kotlin.math.pow @OptIn(ExperimentalCoroutinesApi::class) internal class CpuPowerModelTest { private val epsilon = 10.0.pow(-3) - private val cpuUtil = .9 + private val cpuUtil = 0.9 @ParameterizedTest @MethodSource("cpuPowerModelArgs") @@ -49,12 +48,10 @@ internal class CpuPowerModelTest { ) { runBlockingTest { val cpuLoads = flowOf(cpuUtil, cpuUtil, cpuUtil).stateIn(this) - val bareMetalDriver = mockkClass(SimHost::class) val machine = mockkClass(SimBareMetalMachine::class) - every { bareMetalDriver.machine } returns machine every { machine.usage } returns cpuLoads - val serverPowerDraw = powerModel.getPowerDraw(bareMetalDriver) + val serverPowerDraw = powerModel.getPowerDraw(machine) assertEquals( serverPowerDraw.first().toDouble(), @@ -62,7 +59,6 @@ internal class CpuPowerModelTest { epsilon ) - verify(exactly = 1) { bareMetalDriver.machine } verify(exactly = 1) { machine.usage } } } diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt new file mode 100644 index 00000000..e144e541 --- /dev/null +++ b/simulator/opendc-compute/opendc-compute-simulator/src/test/kotlin/org/opendc/compute/simulator/power/PStatePowerModelTest.kt @@ -0,0 +1,45 @@ +package org.opendc.compute.simulator.power + +import io.mockk.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test +import org.opendc.compute.simulator.power.models.PStatePowerModel +import org.opendc.simulator.compute.SimBareMetalMachine +import java.time.Clock + +internal class PStatePowerModelTest { + @Test + fun `update CPU power meter with P-states`() { + val p0Power = 8.0 + val p3Power = 94.0 + val p4Power = 103.0 + val expectedP0Power = 8.0 * 10 + val expectedP0P4Power = expectedP0Power + 103.0 * 10 + + val clock = mockkClass(Clock::class) + val machine = mockkClass(SimBareMetalMachine::class) + every { clock.millis() } returnsMany listOf(0L, 0L, 10_000L, 20_000L) + every { machine.speed } returns + listOf(2.8, 2.8, 2.8, 2.8).map { it * 1000 } andThen // Max. 2.8MHz covered by P0 + listOf(1.5, 3.1, 3.3, 3.6).map { it * 1000 } andThen // Max. 3.6MHz covered by P4 + listOf(1.5, 3.1, 3.1, 3.3).map { it * 1000 } // Max. 3.3MHz covered by P3 + + // Power meter initialization. + val pStatePowerModel = PStatePowerModel(machine, clock) + verify(exactly = 2) { clock.millis() } + verify(exactly = 1) { machine.speed } + assertEquals(p0Power, pStatePowerModel.getInstantCpuPower()) + + // The first measure. + pStatePowerModel.updateCpuPowerMeter() + assertEquals(p4Power, pStatePowerModel.getInstantCpuPower()) + assertEquals(expectedP0Power, pStatePowerModel.getAccumulatedCpuPower()) + + // The second measure. + pStatePowerModel.updateCpuPowerMeter() + assertEquals(p3Power, pStatePowerModel.getInstantCpuPower()) + assertEquals(expectedP0P4Power, pStatePowerModel.getAccumulatedCpuPower()) + + verify(exactly = 4) { clock.millis() } + } +} |
