diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-07 11:11:19 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-07 12:13:16 +0200 |
| commit | 3860d9e1c042eefacd5accb771cf47990090f649 (patch) | |
| tree | 6ea7f7480c3e75dc258176dfca904e98808d138c /simulator/opendc-simulator/opendc-simulator-compute/src/main | |
| parent | f3384ca33f84fc261aeb20ca7752ab052971dcf4 (diff) | |
simulator: Add tests for CPUFreq subsystem
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/main')
2 files changed, 8 insertions, 7 deletions
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 index 8f3eacea..d109e4d8 100644 --- 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 @@ -28,6 +28,7 @@ import org.opendc.simulator.compute.power.PowerModel import org.opendc.simulator.resources.SimResourceSource import java.util.* import kotlin.math.max +import kotlin.math.min /** * A [ScalingDriver] that scales the frequency of the processor based on a discrete set of frequencies. @@ -53,18 +54,18 @@ public class PStateScalingDriver(states: Map<Double, PowerModel>) : ScalingDrive } override fun computePower(): Double { - var freq = 0.0 + var targetFreq = 0.0 var totalSpeed = 0.0 - var totalFreq = 0.0 for (ctx in contexts) { - freq = max(ctx.target, freq) + targetFreq = max(ctx.target, targetFreq) totalSpeed += ctx.resource.speed.value - totalFreq += ctx.target } - val (_, model) = states.ceilingEntry(freq) - return model.computePower(totalSpeed / totalFreq) + val maxFreq = states.lastKey() + val (actualFreq, model) = states.ceilingEntry(min(maxFreq, targetFreq)) + val utilization = totalSpeed / (actualFreq * contexts.size) + return model.computePower(utilization) } override fun toString(): String = "PStateScalingDriver.Logic" 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 index 9c6eb9ed..c9aea580 100644 --- 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 @@ -47,7 +47,7 @@ public interface ScalingGovernor { public fun onStart() {} /** - * This method is invoked when + * This method is invoked when the governor should re-decide the frequency limits. */ public fun onLimit() {} } |
