From e38e6b9341907e28d029054995cf43cbd5e8bb4d Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 30 Mar 2021 22:20:13 +0200 Subject: simulator: Add initial design of CPUFreq model This change adds a model implementing Dynamic Voltage Frequency Scaling (DVFS) to OpenDC. --- .../kotlin/org/opendc/compute/simulator/SimHost.kt | 8 +- .../capelin/trace/Sc20RawParquetTraceReader.kt | 9 +++ .../org/opendc/format/environment/MachineDef.kt | 4 +- .../serverless/simulator/SimFunctionDeployer.kt | 5 +- .../simulator/compute/SimMachineBenchmarks.kt | 23 +++++- .../simulator/compute/SimBareMetalMachine.kt | 38 ++++++++-- .../compute/cpufreq/DemandScalingGovernor.kt | 36 +++++++++ .../compute/cpufreq/PStateScalingDriver.kt | 87 ++++++++++++++++++++++ .../compute/cpufreq/PerformanceScalingGovernor.kt | 36 +++++++++ .../simulator/compute/cpufreq/ScalingContext.kt | 52 +++++++++++++ .../simulator/compute/cpufreq/ScalingDriver.kt | 54 ++++++++++++++ .../simulator/compute/cpufreq/ScalingGovernor.kt | 54 ++++++++++++++ .../compute/cpufreq/SimpleScalingDriver.kt | 52 +++++++++++++ .../simulator/compute/power/ConstantPowerModel.kt | 4 +- .../simulator/compute/power/CubicPowerModel.kt | 8 +- .../compute/power/InterpolationPowerModel.kt | 16 ++-- .../simulator/compute/power/LinearPowerModel.kt | 8 +- .../simulator/compute/power/MachinePowerModel.kt | 18 ----- .../opendc/simulator/compute/power/PowerModel.kt | 16 ++++ .../simulator/compute/power/SqrtPowerModel.kt | 8 +- .../simulator/compute/power/SquarePowerModel.kt | 8 +- .../compute/power/ZeroIdlePowerDecorator.kt | 8 +- .../opendc/simulator/compute/SimHypervisorTest.kt | 10 ++- .../org/opendc/simulator/compute/SimMachineTest.kt | 7 +- .../compute/SimSpaceSharedHypervisorTest.kt | 34 +++++++-- .../compute/power/MachinePowerModelTest.kt | 28 +++---- 26 files changed, 540 insertions(+), 91 deletions(-) create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernor.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriver.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernor.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingContext.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingDriver.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingGovernor.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/SimpleScalingDriver.kt delete mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/MachinePowerModel.kt create mode 100644 simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt (limited to 'simulator') diff --git a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt index 6d81aa7d..8e1aab44 100644 --- a/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt +++ b/simulator/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt @@ -31,11 +31,13 @@ import org.opendc.compute.api.Server import org.opendc.compute.api.ServerState import org.opendc.compute.service.driver.* import org.opendc.simulator.compute.* +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver import org.opendc.simulator.compute.interference.IMAGE_PERF_INTERFERENCE_MODEL import org.opendc.simulator.compute.interference.PerformanceInterferenceModel import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.power.ConstantPowerModel -import org.opendc.simulator.compute.power.MachinePowerModel +import org.opendc.simulator.compute.power.PowerModel import org.opendc.simulator.failures.FailureDomain import java.time.Clock import java.util.* @@ -54,7 +56,7 @@ public class SimHost( clock: Clock, meter: Meter, hypervisor: SimHypervisorProvider, - powerModel: MachinePowerModel = ConstantPowerModel(0.0), + powerModel: PowerModel = ConstantPowerModel(0.0), private val mapper: SimWorkloadMapper = SimMetaWorkloadMapper(), ) : Host, FailureDomain, AutoCloseable { /** @@ -80,7 +82,7 @@ public class SimHost( /** * The machine to run on. */ - public val machine: SimBareMetalMachine = SimBareMetalMachine(context, clock, model, powerModel) + public val machine: SimBareMetalMachine = SimBareMetalMachine(context, clock, model, PerformanceScalingGovernor(), SimpleScalingDriver(powerModel)) /** * The hypervisor to run multiple workloads. diff --git a/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/trace/Sc20RawParquetTraceReader.kt b/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/trace/Sc20RawParquetTraceReader.kt index 7ea5efe5..ffbf46d4 100644 --- a/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/trace/Sc20RawParquetTraceReader.kt +++ b/simulator/opendc-experiments/opendc-experiments-capelin/src/main/kotlin/org/opendc/experiments/capelin/trace/Sc20RawParquetTraceReader.kt @@ -145,4 +145,13 @@ public class Sc20RawParquetTraceReader(private val path: File) { * Read the entries in the trace. */ public fun read(): List> = entries + + /** + * Create a [TraceReader] instance. + */ + public fun createReader(): TraceReader { + return object : TraceReader, Iterator> by entries.iterator() { + override fun close() {} + } + } } diff --git a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt index c7f7c4dc..9b799cc2 100644 --- a/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt +++ b/simulator/opendc-format/src/main/kotlin/org/opendc/format/environment/MachineDef.kt @@ -23,7 +23,7 @@ package org.opendc.format.environment import org.opendc.simulator.compute.SimMachineModel -import org.opendc.simulator.compute.power.MachinePowerModel +import org.opendc.simulator.compute.power.PowerModel import java.util.* public data class MachineDef( @@ -31,5 +31,5 @@ public data class MachineDef( val name: String, val meta: Map, val model: SimMachineModel, - val powerModel: MachinePowerModel + val powerModel: PowerModel ) diff --git a/simulator/opendc-serverless/opendc-serverless-simulator/src/main/kotlin/org/opendc/serverless/simulator/SimFunctionDeployer.kt b/simulator/opendc-serverless/opendc-serverless-simulator/src/main/kotlin/org/opendc/serverless/simulator/SimFunctionDeployer.kt index 7a48609c..f28a926b 100644 --- a/simulator/opendc-serverless/opendc-serverless-simulator/src/main/kotlin/org/opendc/serverless/simulator/SimFunctionDeployer.kt +++ b/simulator/opendc-serverless/opendc-serverless-simulator/src/main/kotlin/org/opendc/serverless/simulator/SimFunctionDeployer.kt @@ -32,6 +32,9 @@ import org.opendc.serverless.simulator.workload.SimServerlessWorkloadMapper import org.opendc.simulator.compute.SimBareMetalMachine import org.opendc.simulator.compute.SimMachine import org.opendc.simulator.compute.SimMachineModel +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver +import org.opendc.simulator.compute.power.ConstantPowerModel import java.time.Clock import java.util.ArrayDeque import kotlin.coroutines.Continuation @@ -66,7 +69,7 @@ public class SimFunctionDeployer( /** * The machine that will execute the workloads. */ - public val machine: SimMachine = SimBareMetalMachine(scope.coroutineContext, clock, model) + public val machine: SimMachine = SimBareMetalMachine(scope.coroutineContext, clock, model, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) /** * The job associated with the lifecycle of the instance. diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt index eb22c855..c2a29f5b 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt @@ -27,9 +27,12 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.runBlockingTest +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimWorkload import org.opendc.simulator.utils.DelayControllerClockAdapter import org.opendc.utils.TimerScheduler @@ -75,7 +78,10 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkBareMetal(state: Workload) { return scope.runBlockingTest { - val machine = SimBareMetalMachine(scope.coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) return@runBlockingTest machine.run(state.workloads[0]) } } @@ -83,7 +89,10 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkSpaceSharedHypervisor(state: Workload) { return scope.runBlockingTest { - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } @@ -102,7 +111,10 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkFairShareHypervisorSingle(state: Workload) { return scope.runBlockingTest { - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimFairShareHypervisor() launch { machine.run(hypervisor) } @@ -121,7 +133,10 @@ class SimMachineBenchmarks { @Benchmark fun benchmarkFairShareHypervisorDouble(state: Workload) { return scope.runBlockingTest { - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimFairShareHypervisor() launch { machine.run(hypervisor) } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt index 830ff70e..51b807d2 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt @@ -24,9 +24,9 @@ package org.opendc.simulator.compute import kotlinx.coroutines.* import kotlinx.coroutines.flow.* +import org.opendc.simulator.compute.cpufreq.ScalingDriver +import org.opendc.simulator.compute.cpufreq.ScalingGovernor import org.opendc.simulator.compute.model.ProcessingUnit -import org.opendc.simulator.compute.power.ConstantPowerModel -import org.opendc.simulator.compute.power.MachinePowerModel import org.opendc.simulator.resources.* import org.opendc.utils.TimerScheduler import java.time.Clock @@ -47,18 +47,14 @@ public class SimBareMetalMachine( context: CoroutineContext, private val clock: Clock, override val model: SimMachineModel, - private val powerModel: MachinePowerModel = ConstantPowerModel(0.0) + scalingGovernor: ScalingGovernor, + scalingDriver: ScalingDriver ) : SimAbstractMachine(clock) { /** * The [Job] associated with this machine. */ private val scope = CoroutineScope(context + Job()) - /** - * The power draw of the machine. - */ - public val powerDraw: StateFlow = usage.map { powerModel.computeCpuPower(it) }.stateIn(scope, SharingStarted.Eagerly, 0.0) - override val context: CoroutineContext = scope.coroutineContext /** @@ -69,6 +65,32 @@ public class SimBareMetalMachine( override val resources: Map = model.cpus.associateWith { SimResourceSource(it.frequency, clock, scheduler) } + /** + * Construct the [ScalingDriver.Logic] for this machine. + */ + private val scalingDriver = scalingDriver.createLogic(this) + + /** + * The scaling contexts associated with each CPU. + */ + private val scalingGovernors = resources.map { (cpu, resource) -> + scalingGovernor.createLogic(this.scalingDriver.createContext(cpu, resource)) + } + + init { + scalingGovernors.forEach { it.onStart() } + } + + /** + * The power draw of the machine. + */ + public val powerDraw: StateFlow = usage + .map { + this.scalingGovernors.forEach { it.onLimit() } + this.scalingDriver.computePower() + } + .stateIn(scope, SharingStarted.Eagerly, 0.0) + override fun close() { super.close() diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernor.kt new file mode 100644 index 00000000..b4bbf9fb --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/DemandScalingGovernor.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +/** + * A CPUFreq [ScalingGovernor] that requests the frequency based on the utilization of the machine. + */ +public class DemandScalingGovernor : ScalingGovernor { + override fun createLogic(ctx: ScalingContext): ScalingGovernor.Logic = object : ScalingGovernor.Logic { + override fun onLimit() { + ctx.setTarget(ctx.resource.speed.value) + } + + override fun toString(): String = "DemandScalingGovernor.Logic" + } +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriver.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriver.kt new file mode 100644 index 00000000..8f3eacea --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PStateScalingDriver.kt @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +import org.opendc.simulator.compute.SimMachine +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.PowerModel +import org.opendc.simulator.resources.SimResourceSource +import java.util.* +import kotlin.math.max + +/** + * A [ScalingDriver] that scales the frequency of the processor based on a discrete set of frequencies. + * + * @param states A map describing the states of the driver. + */ +public class PStateScalingDriver(states: Map) : ScalingDriver { + /** + * The P-States defined by the user and ordered by key. + */ + private val states = TreeMap(states) + + override fun createLogic(machine: SimMachine): ScalingDriver.Logic = object : ScalingDriver.Logic { + /** + * The scaling contexts. + */ + private val contexts = mutableListOf() + + override fun createContext(cpu: ProcessingUnit, resource: SimResourceSource): ScalingContext { + val ctx = ScalingContextImpl(machine, cpu, resource) + contexts.add(ctx) + return ctx + } + + override fun computePower(): Double { + var freq = 0.0 + var totalSpeed = 0.0 + var totalFreq = 0.0 + + for (ctx in contexts) { + freq = max(ctx.target, freq) + totalSpeed += ctx.resource.speed.value + totalFreq += ctx.target + } + + val (_, model) = states.ceilingEntry(freq) + return model.computePower(totalSpeed / totalFreq) + } + + override fun toString(): String = "PStateScalingDriver.Logic" + } + + private class ScalingContextImpl( + override val machine: SimMachine, + override val cpu: ProcessingUnit, + override val resource: SimResourceSource + ) : ScalingContext { + var target = cpu.frequency + private set + + override fun setTarget(freq: Double) { + target = freq + } + + override fun toString(): String = "PStateScalingDriver.Context" + } +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernor.kt new file mode 100644 index 00000000..c574d5d1 --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/PerformanceScalingGovernor.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +/** + * A CPUFreq [ScalingGovernor] that causes the highest possible frequency to be requested from the resource. + */ +public class PerformanceScalingGovernor : ScalingGovernor { + override fun createLogic(ctx: ScalingContext): ScalingGovernor.Logic = object : ScalingGovernor.Logic { + override fun onLimit() { + ctx.setTarget(ctx.resource.capacity) + } + + override fun toString(): String = "PerformanceScalingGovernor.Logic" + } +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingContext.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingContext.kt new file mode 100644 index 00000000..44cd0168 --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingContext.kt @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +import org.opendc.simulator.compute.SimMachine +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.resources.SimResourceSource + +/** + * A [ScalingContext] is used to communicate frequency scaling changes between the [ScalingGovernor] and driver. + */ +public interface ScalingContext { + /** + * The machine the processing unit belongs to. + */ + public val machine: SimMachine + + /** + * The processing unit associated with this context. + */ + public val cpu: ProcessingUnit + + /** + * The resource associated with this context. + */ + public val resource: SimResourceSource + + /** + * Target the processor to run at the specified target [frequency][freq]. + */ + public fun setTarget(freq: Double) +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingDriver.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingDriver.kt new file mode 100644 index 00000000..2414eabb --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingDriver.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +import org.opendc.simulator.compute.SimMachine +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.resources.SimResourceSource + +/** + * A [ScalingDriver] is responsible for switching the processor to the correct frequency. + */ +public interface ScalingDriver { + /** + * Create the scaling logic for the specified [machine] + */ + public fun createLogic(machine: SimMachine): Logic + + /** + * The logic of the scaling driver. + */ + public interface Logic { + /** + * Create the [ScalingContext] for the specified [cpu] and [resource] instance. + */ + public fun createContext(cpu: ProcessingUnit, resource: SimResourceSource): ScalingContext + + /** + * Compute the power consumption of the processor. + * + * @return The power consumption of the processor in W. + */ + public fun computePower(): Double + } +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingGovernor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingGovernor.kt new file mode 100644 index 00000000..9c6eb9ed --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/ScalingGovernor.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +/** + * A [ScalingGovernor] in the CPUFreq subsystem of OpenDC is responsible for scaling the frequency of simulated CPUs + * independent of the particular implementation of the CPU. + * + * Each of the scaling governors implements a single, possibly parametrized, performance scaling algorithm. + * + * For more information, see the documentation of the Linux CPUFreq subsystem: + * https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html + */ +public interface ScalingGovernor { + /** + * Create the scaling logic for the specified [context] + */ + public fun createLogic(ctx: ScalingContext): Logic + + /** + * The logic of the scaling governor. + */ + public interface Logic { + /** + * This method is invoked when the governor is started. + */ + public fun onStart() {} + + /** + * This method is invoked when + */ + public fun onLimit() {} + } +} diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/SimpleScalingDriver.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/SimpleScalingDriver.kt new file mode 100644 index 00000000..b4b564ce --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/cpufreq/SimpleScalingDriver.kt @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.cpufreq + +import org.opendc.simulator.compute.SimMachine +import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.PowerModel +import org.opendc.simulator.resources.SimResourceSource + +/** + * A [ScalingDriver] that ignores the instructions of the [ScalingGovernor] and directly computes the power consumption + * based on the specified [power model][model]. + */ +public class SimpleScalingDriver(private val model: PowerModel) : ScalingDriver { + override fun createLogic(machine: SimMachine): ScalingDriver.Logic = object : ScalingDriver.Logic { + override fun createContext(cpu: ProcessingUnit, resource: SimResourceSource): ScalingContext { + return object : ScalingContext { + override val machine: SimMachine = machine + + override val cpu: ProcessingUnit = cpu + + override val resource: SimResourceSource = resource + + override fun setTarget(freq: Double) {} + } + } + + override fun computePower(): Double = model.computePower(machine.usage.value) + + override fun toString(): String = "SimpleScalingDriver.Logic" + } +} 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 5d7ae8ad..1b9733d1 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 @@ -3,6 +3,6 @@ package org.opendc.simulator.compute.power /** * A power model which produces a constant value [constant]. */ -public class ConstantPowerModel(private val constant: Double) : MachinePowerModel { - public override fun computeCpuPower(cpuUtil: Double): Double = constant +public class ConstantPowerModel(private val constant: Double) : PowerModel { + public override fun computePower(utilization: Double): Double = constant } 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 8e47f571..e5bc013c 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 @@ -14,12 +14,12 @@ import kotlin.math.pow public class CubicPowerModel( private var maxPower: Double, staticPowerPercent: Double -) : MachinePowerModel { +) : PowerModel { private var staticPower: Double = staticPowerPercent * maxPower private var constPower: Double = (maxPower - staticPower) / 100.0.pow(3) - public override fun computeCpuPower(cpuUtil: Double): Double { - require(cpuUtil in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * (cpuUtil * 100).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) } } 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 69fc0514..ce9b8197 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 @@ -16,22 +16,22 @@ import kotlin.math.floor */ public class InterpolationPowerModel( hardwareName: String, -) : MachinePowerModel { +) : PowerModel { 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]" } + public override fun computePower(utilization: Double): Double { + require(utilization 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 cpuUtilFlr = floor(utilization * 10).toInt() + val cpuUtilCil = ceil(utilization * 10).toInt() val powerFlr: Double = getAveragePowerValue(cpuUtilFlr) val powerCil: Double = getAveragePowerValue(cpuUtilCil) val delta = (powerCil - powerFlr) / 10 - return if (cpuUtil % 0.1 == 0.0) - getAveragePowerValue((cpuUtil * 10).toInt()) + return if (utilization % 0.1 == 0.0) + getAveragePowerValue((utilization * 10).toInt()) else - powerFlr + delta * (cpuUtil - cpuUtilFlr.toDouble() / 10) * 100 + powerFlr + delta * (utilization - cpuUtilFlr.toDouble() / 10) * 100 } /** 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 14443aff..56a75bb6 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 @@ -12,12 +12,12 @@ package org.opendc.simulator.compute.power public class LinearPowerModel( private var maxPower: Double, staticPowerPercent: Double -) : MachinePowerModel { +) : PowerModel { private var staticPower: Double = staticPowerPercent * maxPower private var constPower: Double = (maxPower - staticPower) / 100 - public override fun computeCpuPower(cpuUtil: Double): Double { - require(cpuUtil in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * cpuUtil * 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 } } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/MachinePowerModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/MachinePowerModel.kt deleted file mode 100644 index 9bf03b87..00000000 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/MachinePowerModel.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.opendc.simulator.compute.power - -import org.opendc.simulator.compute.SimMachine - -/** - * A model for estimating the power usage of a [SimMachine]. - */ -public interface MachinePowerModel { - /** - * Computes CPU power consumption for each host. - * - * @param cpuUtil The CPU utilization percentage. - * @return A [Double] value of CPU power consumption. - * @throws IllegalArgumentException Will throw an error if [cpuUtil] is out of range. - */ - @Throws(IllegalArgumentException::class) - public fun computeCpuPower(cpuUtil: Double): Double -} 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 new file mode 100644 index 00000000..19dff88c --- /dev/null +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/power/PowerModel.kt @@ -0,0 +1,16 @@ +package org.opendc.simulator.compute.power + +import org.opendc.simulator.compute.SimMachine + +/** + * A model for estimating the power usage of a [SimMachine]. + */ +public interface PowerModel { + /** + * Compute the power consumption of the CPU based on its utilization. + * + * @param utilization The CPU utilization percentage in [0, 1]. + * @return The power consumption of the CPU in terms of watts (W). + */ + 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 bf177aff..b78421d8 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 @@ -14,12 +14,12 @@ import kotlin.math.sqrt public class SqrtPowerModel( private var maxPower: Double, staticPowerPercent: Double -) : MachinePowerModel { +) : PowerModel { private var staticPower: Double = staticPowerPercent * maxPower private var constPower: Double = (maxPower - staticPower) / sqrt(100.0) - override fun computeCpuPower(cpuUtil: Double): Double { - require(cpuUtil in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * sqrt(cpuUtil * 100) + 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) } } 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 cbfad530..b5953daa 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 @@ -14,12 +14,12 @@ import kotlin.math.pow public class SquarePowerModel( private var maxPower: Double, staticPowerPercent: Double -) : MachinePowerModel { +) : PowerModel { private var staticPower: Double = staticPowerPercent * maxPower private var constPower: Double = (maxPower - staticPower) / 100.0.pow(2) - override fun computeCpuPower(cpuUtil: Double): Double { - require(cpuUtil in 0.0..1.0) { "CPU utilization must be in [0, 1]" } - return staticPower + constPower * (cpuUtil * 100).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) } } 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 01deac5b..50f04a4f 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 @@ -3,10 +3,10 @@ package org.opendc.simulator.compute.power /** * A decorator for ignoring the idle power when computing energy consumption of components. * - * @param delegate The [MachinePowerModel] to delegate to. + * @param delegate The [PowerModel] to delegate to. */ -public class ZeroIdlePowerDecorator(private val delegate: MachinePowerModel) : MachinePowerModel { - override fun computeCpuPower(cpuUtil: Double): Double { - return if (cpuUtil == 0.0) 0.0 else delegate.computeCpuPower(cpuUtil) +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) } } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt index 5773b325..67295dfd 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimHypervisorTest.kt @@ -32,9 +32,12 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimTraceWorkload import org.opendc.simulator.utils.DelayControllerClockAdapter @@ -91,7 +94,7 @@ internal class SimHypervisorTest { ), ) - val machine = SimBareMetalMachine(coroutineContext, clock, model) + val machine = SimBareMetalMachine(coroutineContext, clock, model, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) val hypervisor = SimFairShareHypervisor(listener) launch { @@ -163,7 +166,10 @@ internal class SimHypervisorTest { ) ) - val machine = SimBareMetalMachine(coroutineContext, clock, model) + val machine = SimBareMetalMachine( + coroutineContext, clock, model, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimFairShareHypervisor(listener) launch { diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt index 071bdf77..13f7f9ea 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt @@ -28,9 +28,12 @@ import kotlinx.coroutines.test.runBlockingTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimFlopsWorkload import org.opendc.simulator.utils.DelayControllerClockAdapter @@ -54,7 +57,7 @@ class SimMachineTest { @Test fun testFlopsWorkload() = runBlockingTest { val clock = DelayControllerClockAdapter(this) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) try { machine.run(SimFlopsWorkload(2_000, utilization = 1.0)) @@ -69,7 +72,7 @@ class SimMachineTest { @Test fun testUsage() = runBlockingTest { val clock = DelayControllerClockAdapter(this) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine(coroutineContext, clock, machineModel, PerformanceScalingGovernor(), SimpleScalingDriver(ConstantPowerModel(0.0))) val res = mutableListOf() val job = launch { machine.usage.toList(res) } diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt index fb0523af..51e4305a 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisorTest.kt @@ -31,9 +31,12 @@ import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.opendc.simulator.compute.cpufreq.PerformanceScalingGovernor +import org.opendc.simulator.compute.cpufreq.SimpleScalingDriver import org.opendc.simulator.compute.model.MemoryUnit import org.opendc.simulator.compute.model.ProcessingNode import org.opendc.simulator.compute.model.ProcessingUnit +import org.opendc.simulator.compute.power.ConstantPowerModel import org.opendc.simulator.compute.workload.SimFlopsWorkload import org.opendc.simulator.compute.workload.SimRuntimeWorkload import org.opendc.simulator.compute.workload.SimTraceWorkload @@ -75,7 +78,10 @@ internal class SimSpaceSharedHypervisorTest { ), ) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() val colA = launch { machine.usage.toList(usagePm) } @@ -109,7 +115,10 @@ internal class SimSpaceSharedHypervisorTest { val clock = DelayControllerClockAdapter(this) val duration = 5 * 60L * 1000 val workload = SimRuntimeWorkload(duration) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } @@ -131,7 +140,10 @@ internal class SimSpaceSharedHypervisorTest { val duration = 5 * 60L * 1000 val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } @@ -150,7 +162,10 @@ internal class SimSpaceSharedHypervisorTest { fun testTwoWorkloads() = runBlockingTest { val clock = DelayControllerClockAdapter(this) val duration = 5 * 60L * 1000 - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } @@ -174,8 +189,10 @@ internal class SimSpaceSharedHypervisorTest { @Test fun testConcurrentWorkloadFails() = runBlockingTest { val clock = DelayControllerClockAdapter(this) - - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } @@ -197,7 +214,10 @@ internal class SimSpaceSharedHypervisorTest { @Test fun testConcurrentWorkloadSucceeds() = runBlockingTest { val clock = DelayControllerClockAdapter(this) - val machine = SimBareMetalMachine(coroutineContext, clock, machineModel) + val machine = SimBareMetalMachine( + coroutineContext, clock, machineModel, PerformanceScalingGovernor(), + SimpleScalingDriver(ConstantPowerModel(0.0)) + ) val hypervisor = SimSpaceSharedHypervisor() launch { machine.run(hypervisor) } 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 13bb3668..f42e2e73 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 @@ -19,21 +19,21 @@ internal class MachinePowerModelTest { @ParameterizedTest @MethodSource("MachinePowerModelArgs") fun `compute power consumption given CPU loads`( - powerModel: MachinePowerModel, + powerModel: PowerModel, expectedPowerConsumption: Double ) { - val computedPowerConsumption = powerModel.computeCpuPower(cpuUtil) + val computedPowerConsumption = powerModel.computePower(cpuUtil) assertEquals(expectedPowerConsumption, computedPowerConsumption, epsilon) } @ParameterizedTest @MethodSource("MachinePowerModelArgs") fun `ignore idle power when computing power consumptions`( - powerModel: MachinePowerModel, + powerModel: PowerModel, expectedPowerConsumption: Double ) { val zeroPowerModel = ZeroIdlePowerDecorator(powerModel) - val computedPowerConsumption = zeroPowerModel.computeCpuPower(0.0) + val computedPowerConsumption = zeroPowerModel.computePower(0.0) assertEquals(0.0, computedPowerConsumption) } @@ -42,19 +42,19 @@ internal class MachinePowerModelTest { val powerModel = InterpolationPowerModel("IBMx3550M3_XeonX5675") assertAll( - { assertThrows { powerModel.computeCpuPower(-1.3) } }, - { assertThrows { powerModel.computeCpuPower(1.3) } }, + { assertThrows { powerModel.computePower(-1.3) } }, + { assertThrows { powerModel.computePower(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)) }, + { assertEquals(58.4, powerModel.computePower(0.0)) }, + { assertEquals(58.4 + (98 - 58.4) / 5, powerModel.computePower(0.02)) }, + { assertEquals(98.0, powerModel.computePower(0.1)) }, + { assertEquals(140.0, powerModel.computePower(0.5)) }, + { assertEquals(189.0, powerModel.computePower(0.8)) }, + { assertEquals(189.0 + 0.7 * 10 * (205 - 189) / 10, powerModel.computePower(0.87)) }, + { assertEquals(205.0, powerModel.computePower(0.9)) }, + { assertEquals(222.0, powerModel.computePower(1.0)) }, ) } -- cgit v1.2.3