summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src/main
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/opendc-simulator-compute/src/main
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/opendc-simulator-compute/src/main')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/InterpolationPowerModel.kt44
1 files changed, 32 insertions, 12 deletions
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())
+ }
}