summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator
diff options
context:
space:
mode:
authorHongyu <39747921+HongyuHe@users.noreply.github.com>2021-03-26 15:47:14 +0100
committerGitHub <noreply@github.com>2021-03-26 15:47:14 +0100
commit57ebc8a1c6779d7e7276754838e83f1c026cceb9 (patch)
tree644ff72bba7e31dab19f4258f4feaeaa4bcc275a /simulator/opendc-simulator
parent074dee1cbca7b3a024d45a3b9dd7d8b51acdd4ee (diff)
simulator: Extract hardware power values to a separate file (#105)
This change enables the use of the interpolation model testing on the results of the SPEC benchmark.
Diffstat (limited to 'simulator/opendc-simulator')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/build.gradle.kts1
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt44
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt26
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/test/resources/spec_machines.yml29
4 files changed, 86 insertions, 14 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/build.gradle.kts b/simulator/opendc-simulator/opendc-simulator-compute/build.gradle.kts
index 149c0ed2..4b0069e3 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/build.gradle.kts
+++ b/simulator/opendc-simulator/opendc-simulator-compute/build.gradle.kts
@@ -34,4 +34,5 @@ dependencies {
api(project(":opendc-simulator:opendc-simulator-core"))
api(project(":opendc-simulator:opendc-simulator-resources"))
implementation(project(":opendc-utils"))
+ implementation("org.yaml:snakeyaml:1.28")
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt
index af7b6e6d..69fc0514 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt
@@ -1,33 +1,53 @@
package org.opendc.simulator.compute.power
+import org.yaml.snakeyaml.Yaml
import kotlin.math.ceil
import kotlin.math.floor
/**
* The linear interpolation power model partially adapted from CloudSim.
+ * This model is developed to adopt the <a href="http://www.spec.org/power_ssj2008/">SPECpower benchmark</a>.
*
- * @param maxPower The maximum power draw in Watts of the server.
- * @param staticPowerPercent The static power percentage.
- * @property staticPower The static power consumption that is not dependent on resource usage.
- * It is the amount of energy consumed even when the host is idle.
- * @property constPower The constant power consumption for each fraction of resource used.
+ * @param hardwareName The name of the hardware vendor.
+ * @see <a href="http://www.spec.org/power_ssj2008/results/res2011q1/">Machines used in the SPEC benchmark</a>
+ * @property averagePowerValues A [List] of average active power measured by the power analyzer(s)
+ * and accumulated by the PTDaemon (Power and Temperature Daemon) for this
+ * measurement interval, displayed as watts (W).
*/
-public abstract class InterpolationPowerModel : MachinePowerModel {
+public class InterpolationPowerModel(
+ hardwareName: String,
+) : MachinePowerModel {
+ private val averagePowerValues: List<Double> = loadAveragePowerValue(hardwareName)
public override fun computeCpuPower(cpuUtil: Double): Double {
require(cpuUtil in 0.0..1.0) { "CPU utilization must be in [0, 1]" }
val cpuUtilFlr = floor(cpuUtil * 10).toInt()
val cpuUtilCil = ceil(cpuUtil * 10).toInt()
- val power1: Double = getPowerData(cpuUtilFlr)
- val power2: Double = getPowerData(cpuUtilCil)
- val delta = (power2 - power1) / 10
+ val powerFlr: Double = getAveragePowerValue(cpuUtilFlr)
+ val powerCil: Double = getAveragePowerValue(cpuUtilCil)
+ val delta = (powerCil - powerFlr) / 10
return if (cpuUtil % 0.1 == 0.0)
- getPowerData((cpuUtil * 10).toInt())
+ getAveragePowerValue((cpuUtil * 10).toInt())
else
- power1 + delta * (cpuUtil - cpuUtilFlr.toDouble() / 10) * 100
+ powerFlr + delta * (cpuUtil - cpuUtilFlr.toDouble() / 10) * 100
}
- public abstract fun getPowerData(index: Int): Double
+ /**
+ * Gets the power consumption for a given utilization percentage.
+ *
+ * @param index the utilization percentage in the scale from [0 to 10],
+ * where 10 means 100% of utilization.
+ * @return the power consumption for the given utilization percentage
+ */
+ private fun getAveragePowerValue(index: Int): Double = averagePowerValues[index]
+
+ private fun loadAveragePowerValue(hardwareName: String, path: String = "spec_machines.yml"): List<Double> {
+ val content = this::class
+ .java.classLoader
+ .getResourceAsStream(path)
+ val hardwareToAveragePowerValues: Map<String, List<Double>> = Yaml().load(content)
+ return hardwareToAveragePowerValues.getOrDefault(hardwareName, listOf())
+ }
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt
index 9fdd0363..13bb3668 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/power/MachinePowerModelTest.kt
@@ -1,9 +1,10 @@
package org.opendc.simulator.compute.power
-import io.mockk.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.*
+import org.junit.jupiter.api.Assertions.assertAll
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
@@ -36,6 +37,27 @@ internal class MachinePowerModelTest {
assertEquals(0.0, computedPowerConsumption)
}
+ @Test
+ fun `compute power draw by the SPEC benchmark model`() {
+ val powerModel = InterpolationPowerModel("IBMx3550M3_XeonX5675")
+
+ assertAll(
+ { assertThrows<IllegalArgumentException> { powerModel.computeCpuPower(-1.3) } },
+ { assertThrows<IllegalArgumentException> { powerModel.computeCpuPower(1.3) } },
+ )
+
+ assertAll(
+ { assertEquals(58.4, powerModel.computeCpuPower(0.0)) },
+ { assertEquals(58.4 + (98 - 58.4) / 5, powerModel.computeCpuPower(0.02)) },
+ { assertEquals(98.0, powerModel.computeCpuPower(0.1)) },
+ { assertEquals(140.0, powerModel.computeCpuPower(0.5)) },
+ { assertEquals(189.0, powerModel.computeCpuPower(0.8)) },
+ { assertEquals(189.0 + 0.7 * 10 * (205 - 189) / 10, powerModel.computeCpuPower(0.87)) },
+ { assertEquals(205.0, powerModel.computeCpuPower(0.9)) },
+ { assertEquals(222.0, powerModel.computeCpuPower(1.0)) },
+ )
+ }
+
@Suppress("unused")
private companion object {
@JvmStatic
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/resources/spec_machines.yml b/simulator/opendc-simulator/opendc-simulator-compute/src/test/resources/spec_machines.yml
new file mode 100644
index 00000000..d51cba80
--- /dev/null
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/resources/spec_machines.yml
@@ -0,0 +1,29 @@
+---
+# The power model of an IBM server x3550 (2 x [Xeon X5675 3067 MHz, 6 cores], 16GB).<br/>
+# <a href="http://www.spec.org/power_ssj2008/results/res2011q2/power_ssj2008-20110406-00368.html">
+# http://www.spec.org/power_ssj2008/results/res2011q2/power_ssj2008-20110406-00368.html</a>
+IBMx3550M3_XeonX5675: [58.4, 98.0, 109.0, 118.0, 128.0, 140.0, 153.0, 170.0, 189.0, 205.0, 222.0]
+ # The power model of an IBM server x3550 (2 x [Xeon X5670 2933 MHz, 6 cores], 12GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2010q2/power_ssj2008-20100315-00239.html">
+ # http://www.spec.org/power_ssj2008/results/res2010q2/power_ssj2008-20100315-00239.html</a>
+IBMx3550M3_XeonX5670: [66.0, 107.0, 120.0, 131.0, 143.0, 156.0, 173.0, 191.0, 211.0, 229.0, 247.0]
+ # the power model of an IBM server x3250 (1 x [Xeon X3480 3067 MHz, 4 cores], 8GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2010q4/power_ssj2008-20101001-00297.html">
+ # http://www.spec.org/power_ssj2008/results/res2010q4/power_ssj2008-20101001-00297.html</a>
+IBMx3250M3_XeonX3480: [42.3, 46.7, 49.7, 55.4, 61.8, 69.3, 76.1, 87.0, 96.1, 106.0, 113.0]
+ # The power model of an IBM server x3250 (1 x [Xeon X3470 2933 MHz, 4 cores], 8GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2009q4/power_ssj2008-20091104-00213.html">
+ # http://www.spec.org/power_ssj2008/results/res2009q4/power_ssj2008-20091104-00213.html</a>
+IBMx3250M3_XeonX3470: [41.6, 46.7, 52.3, 57.9, 65.4, 73.0, 80.7, 89.5, 99.6, 105.0, 113.0]
+ # The power model of an HP ProLiant ML110 G5 (1 x [Xeon 3075 2660 MHz, 2 cores], 4GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110124-00339.html">
+ # http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110124-00339.html</a>
+HPProLiantMl110G5_Xeon3075: [93.7, 97.0, 101.0, 105.0, 110.0, 116.0, 121.0, 125.0, 129.0, 133.0, 135.0]
+ # The power model of an HP ProLiant ML110 G4 (1 x [Xeon 3040 1860 MHz, 2 cores], 4GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html">
+ # http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html</a>
+HPProLiantMl110G4_Xeon3040: [86.0, 89.4, 92.6, 96.0, 99.5, 102.0, 106.0, 108.0, 112.0, 114.0, 117.0]
+ # The power model of an HP ProLiant ML110 G3 (1 x [Pentium D930 3000 MHz, 2 cores], 4GB).<br/>
+ # <a href="http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html">
+ # http://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html</a>
+HPProLiantMl110G3_PentiumD930: [105.0, 112.0, 118.0, 125.0, 131.0, 137.0, 147.0, 153.0, 157.0, 164.0, 169.0]