From 57ebc8a1c6779d7e7276754838e83f1c026cceb9 Mon Sep 17 00:00:00 2001 From: Hongyu <39747921+HongyuHe@users.noreply.github.com> Date: Fri, 26 Mar 2021 15:47:14 +0100 Subject: 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. --- .../compute/power/InterpolationPowerModel.kt | 44 ++++++++++++++++------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/main') 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 SPECpower benchmark. * - * @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 Machines used in the SPEC benchmark + * @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 = 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 { + val content = this::class + .java.classLoader + .getResourceAsStream(path) + val hardwareToAveragePowerValues: Map> = Yaml().load(content) + return hardwareToAveragePowerValues.getOrDefault(hardwareName, listOf()) + } } -- cgit v1.2.3