From f3384ca33f84fc261aeb20ca7752ab052971dcf4 Mon Sep 17 00:00:00 2001 From: Hongyu Date: Mon, 5 Apr 2021 12:50:19 +0200 Subject: simulator: Polish power models This change updates the power models by fixing some of the documentation and adding toString() methods. --- .../simulator/compute/power/ConstantPowerModel.kt | 8 +- .../simulator/compute/power/CubicPowerModel.kt | 20 ++--- .../compute/power/InterpolationPowerModel.kt | 30 +++---- .../simulator/compute/power/LinearPowerModel.kt | 23 +++--- .../simulator/compute/power/PStatePowerModel.kt | 96 ---------------------- .../opendc/simulator/compute/power/PowerModel.kt | 6 +- .../simulator/compute/power/SqrtPowerModel.kt | 20 ++--- .../simulator/compute/power/SquarePowerModel.kt | 20 ++--- .../compute/power/ZeroIdlePowerDecorator.kt | 7 +- 9 files changed, 61 insertions(+), 169 deletions(-) delete mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PStatePowerModel.kt (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/ConstantPowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ConstantPowerModel.kt index 1b9733d1..b8cb8412 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ConstantPowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ConstantPowerModel.kt @@ -1,8 +1,10 @@ package org.opendc.simulator.compute.power /** - * A power model which produces a constant value [constant]. + * A power model which produces a constant value [power]. */ -public class ConstantPowerModel(private val constant: Double) : PowerModel { - public override fun computePower(utilization: Double): Double = constant +public class ConstantPowerModel(private val power: Double) : PowerModel { + public override fun computePower(utilization: Double): Double = power + + override fun toString(): String = "ConstantPowerModel[power=$power]" } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/CubicPowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/CubicPowerModel.kt index e5bc013c..48edace6 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/CubicPowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/CubicPowerModel.kt @@ -5,21 +5,15 @@ import kotlin.math.pow /** * The cubic power model partially adapted from CloudSim. * - * @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 maxPower The maximum power draw of the server in W. + * @param idlePower The power draw of the server in idle state in W. */ -public class CubicPowerModel( - private var maxPower: Double, - staticPowerPercent: Double -) : PowerModel { - private var staticPower: Double = staticPowerPercent * maxPower - private var constPower: Double = (maxPower - staticPower) / 100.0.pow(3) +public class CubicPowerModel(private val maxPower: Double, private val idlePower: Double) : PowerModel { + private val factor: Double = (maxPower - idlePower) / 100.0.pow(3) public override fun computePower(utilization: Double): Double { - require(utilization in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * (utilization * 100).pow(3) + return idlePower + factor * (utilization * 100).pow(3) } + + override fun toString(): String = "CubicPowerModel[max=$maxPower,idle=$idlePower]" } 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 ce9b8197..85613a57 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 @@ -3,6 +3,8 @@ package org.opendc.simulator.compute.power import org.yaml.snakeyaml.Yaml import kotlin.math.ceil import kotlin.math.floor +import kotlin.math.max +import kotlin.math.min /** * The linear interpolation power model partially adapted from CloudSim. @@ -10,30 +12,30 @@ import kotlin.math.floor * * @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 class InterpolationPowerModel( - hardwareName: String, -) : PowerModel { +public class InterpolationPowerModel(hardwareName: String) : PowerModel { + /** + * 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). + */ private val averagePowerValues: List = loadAveragePowerValue(hardwareName) public override fun computePower(utilization: Double): Double { - require(utilization in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - - val cpuUtilFlr = floor(utilization * 10).toInt() - val cpuUtilCil = ceil(utilization * 10).toInt() - val powerFlr: Double = getAveragePowerValue(cpuUtilFlr) - val powerCil: Double = getAveragePowerValue(cpuUtilCil) + val clampedUtilization = min(1.0, max(0.0, utilization)) + val utilizationFlr = floor(clampedUtilization * 10).toInt() + val utilizationCil = ceil(clampedUtilization * 10).toInt() + val powerFlr: Double = getAveragePowerValue(utilizationFlr) + val powerCil: Double = getAveragePowerValue(utilizationCil) val delta = (powerCil - powerFlr) / 10 return if (utilization % 0.1 == 0.0) - getAveragePowerValue((utilization * 10).toInt()) + getAveragePowerValue((clampedUtilization * 10).toInt()) else - powerFlr + delta * (utilization - cpuUtilFlr.toDouble() / 10) * 100 + powerFlr + delta * (clampedUtilization - utilizationFlr.toDouble() / 10) * 100 } + override fun toString(): String = "InterpolationPowerModel[entries=${averagePowerValues.size}]" + /** * Gets the power consumption for a given utilization percentage. * diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/LinearPowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/LinearPowerModel.kt index 56a75bb6..1a0cc07b 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/LinearPowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/LinearPowerModel.kt @@ -3,21 +3,18 @@ package org.opendc.simulator.compute.power /** * The linear power model partially adapted from CloudSim. * - * @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 maxPower The maximum power draw of the server in W. + * @param idlePower The power draw of the server in idle state in W. */ -public class LinearPowerModel( - private var maxPower: Double, - staticPowerPercent: Double -) : PowerModel { - private var staticPower: Double = staticPowerPercent * maxPower - private var constPower: Double = (maxPower - staticPower) / 100 +public class LinearPowerModel(private val maxPower: Double, private val idlePower: Double) : PowerModel { + /** + * The linear interpolation factor of the model. + */ + private val factor: Double = (maxPower - idlePower) / 100 public override fun computePower(utilization: Double): Double { - require(utilization in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * utilization * 100 + return idlePower + factor * utilization * 100 } + + override fun toString(): String = "LinearPowerModel[max=$maxPower,idle=$idlePower]" } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PStatePowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PStatePowerModel.kt deleted file mode 100644 index 722f478d..00000000 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PStatePowerModel.kt +++ /dev/null @@ -1,96 +0,0 @@ -package org.opendc.simulator.compute.power - -import org.opendc.simulator.compute.SimBareMetalMachine -import java.time.Clock -import java.util.* - -/** - * The CPU power model derived from the iCanCloud simulator. - * - * @param machine The [SimBareMetalMachine] that the model is measuring. - * @param clock The virtual [Clock] to track the time spent at each p-state. - * @property cpuPowerMeter A [MutableMap] that contains CPU frequencies ([Double]) in GHz - * as keys and the time ([Long]) spent in that frequency range in seconds. - * @property pStatesToPower A [TreeMap] that contains the frequency ([Double]) of corresponding p-state in GHz - * as keys and the energy ([Double]) consumption of that state in Watts. - * @property pStatesRange A [Pair] in which the fist and second elements are the lower and upper bounds of the - * consumption values of the p-states respectively. - * @property lastMeasureTime The last update time of the [cpuPowerMeter]. - * @property currPState The p-state that the model is currently in. - */ -public class PStatePowerModel( - private val machine: SimBareMetalMachine, - private val clock: Clock, -) { - // TODO: Extract the power meter out of the model. - private val cpuPowerMeter = mutableMapOf() - private val pStatesToPower = TreeMap() - private val pStatesRange: Pair - private var lastMeasureTime: Long - private var currPState: Double - - init { - loadPStates(this) - pStatesRange = Pair(pStatesToPower.keys.first(), pStatesToPower.keys.last()) - pStatesToPower.keys.forEach { cpuPowerMeter[it] = 0L } - currPState = pStatesRange.first - lastMeasureTime = getClockInstant() - updateCpuPowerMeter() - } - - /** Recorde the elapsed time to the corresponding p-state. */ - public fun updateCpuPowerMeter() { - val newMeasureTime = getClockInstant() - val newMaxFreq: Double = getMaxCpuSpeedInGHz() - assert(newMaxFreq in pStatesRange.first..pStatesRange.second) { - "The maximum frequency $newMaxFreq is not in the range of the P-state frequency " + - "from ${pStatesRange.first} to ${pStatesRange.second}." - } - - // Update the current p-state level on which the CPU is running. - val newPState = pStatesToPower.ceilingKey(newMaxFreq) - - // Add the time elapsed to the previous state. - cpuPowerMeter.merge(currPState, newMeasureTime - lastMeasureTime, Long::plus) - - // Update the current states. - currPState = newPState - lastMeasureTime = newMeasureTime - } - - /** Get the power value of the energy consumption level at which the CPU is working. */ - public fun getInstantCpuPower(): Double = - pStatesToPower.getOrDefault(currPState, 0.0) - - /** Get the accumulated power consumption up until now. */ - public fun getAccumulatedCpuPower(): Double = - pStatesToPower.keys - .map { - pStatesToPower.getOrDefault(it, 0.0) * - cpuPowerMeter.getOrDefault(it, 0.0).toDouble() - }.sum() - - private fun getClockInstant() = clock.millis() / 1000 - - /** Get the maximum frequency of the CPUs in GHz as that of the package. - * @see - * on page 34. - */ - private fun getMaxCpuSpeedInGHz() = (machine.speed.maxOrNull() ?: 0.0) / 1000 - - public companion object PStatesLoader { - private fun loadPStates(pStatePowerModel: PStatePowerModel) { - // TODO: Dynamically load configuration. - // See P4 of https://www.intel.com/content/dam/support/us/en/documents/motherboards/server/sb/power_management_of_intel_architecture_servers.pdf - pStatePowerModel.pStatesToPower.putAll( - sortedMapOf( - 3.6 to 103.0, - 3.4 to 94.0, - 3.2 to 85.0, - 3.0 to 76.0, - 2.8 to 8.0, - ) - ) - } - } -} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt index 19dff88c..1387e65a 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt @@ -7,10 +7,10 @@ import org.opendc.simulator.compute.SimMachine */ public interface PowerModel { /** - * Compute the power consumption of the CPU based on its utilization. + * Computes CPU power consumption for each host. * - * @param utilization The CPU utilization percentage in [0, 1]. - * @return The power consumption of the CPU in terms of watts (W). + * @param utilization The CPU utilization percentage. + * @return A [Double] value of CPU power consumption. */ public fun computePower(utilization: Double): Double } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SqrtPowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SqrtPowerModel.kt index b78421d8..da40ca85 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SqrtPowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SqrtPowerModel.kt @@ -5,21 +5,15 @@ import kotlin.math.sqrt /** * The square root power model partially adapted from CloudSim. * - * @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 maxPower The maximum power draw of the server in W. + * @param idlePower The power draw of the server in idle state in W. */ -public class SqrtPowerModel( - private var maxPower: Double, - staticPowerPercent: Double -) : PowerModel { - private var staticPower: Double = staticPowerPercent * maxPower - private var constPower: Double = (maxPower - staticPower) / sqrt(100.0) +public class SqrtPowerModel(private val maxPower: Double, private val idlePower: Double) : PowerModel { + private val factor: Double = (maxPower - idlePower) / sqrt(100.0) override fun computePower(utilization: Double): Double { - require(utilization in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * sqrt(utilization * 100) + return idlePower + factor * sqrt(utilization * 100) } + + override fun toString(): String = "SqrtPowerModel[max=$maxPower,idle=$idlePower]" } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SquarePowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SquarePowerModel.kt index b5953daa..4f914ddf 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SquarePowerModel.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/SquarePowerModel.kt @@ -5,21 +5,15 @@ import kotlin.math.pow /** * The square power model partially adapted from CloudSim. * - * @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 maxPower The maximum power draw of the server in W. + * @param idlePower The power draw of the server in idle state in W. */ -public class SquarePowerModel( - private var maxPower: Double, - staticPowerPercent: Double -) : PowerModel { - private var staticPower: Double = staticPowerPercent * maxPower - private var constPower: Double = (maxPower - staticPower) / 100.0.pow(2) +public class SquarePowerModel(private val maxPower: Double, private val idlePower: Double) : PowerModel { + private val factor: Double = (maxPower - idlePower) / 100.0.pow(2) override fun computePower(utilization: Double): Double { - require(utilization in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * (utilization * 100).pow(2) + return idlePower + factor * (utilization * 100).pow(2) } + + override fun toString(): String = "SquarePowerModel[max=$maxPower,idle=$idlePower]" } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ZeroIdlePowerDecorator.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ZeroIdlePowerDecorator.kt index 50f04a4f..19dfcadd 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ZeroIdlePowerDecorator.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/ZeroIdlePowerDecorator.kt @@ -7,6 +7,11 @@ package org.opendc.simulator.compute.power */ public class ZeroIdlePowerDecorator(private val delegate: PowerModel) : PowerModel { override fun computePower(utilization: Double): Double { - return if (utilization == 0.0) 0.0 else delegate.computePower(utilization) + return if (utilization == 0.0) + 0.0 + else + delegate.computePower(utilization) } + + override fun toString(): String = "ZeroIdlePowerDecorator[delegate=$delegate]" } -- cgit v1.2.3