From 709cd4909ccc1305c7acfdf666156168d66646eb Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 18 Aug 2021 21:54:09 +0200 Subject: feat(simulator): Add support for reporting interfered work This change adds support to the simulator for reporting the work lost due to performance interference. --- .../compute/kernel/SimFairShareHypervisor.kt | 4 ++- .../resources/SimResourceDistributorMaxMin.kt | 36 +++++++++++++++++++--- .../simulator/resources/SimResourceSwitchMaxMin.kt | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisor.kt index 17130d34..c31b1f6b 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisor.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisor.kt @@ -67,6 +67,7 @@ public class SimFairShareHypervisor( private var lastDemand = 0.0 private var lastActual = 0.0 private var lastOvercommit = 0.0 + private var lastInterference = 0.0 private var lastReport = Long.MIN_VALUE override fun onConverge(timestamp: Long) { @@ -79,7 +80,7 @@ public class SimFairShareHypervisor( (counters.demand - lastDemand).toLong(), (counters.actual - lastActual).toLong(), (counters.overcommit - lastOvercommit).toLong(), - 0L, + (counters.interference - lastInterference).toLong(), lastCpuUsage, lastCpuDemand ) @@ -91,6 +92,7 @@ public class SimFairShareHypervisor( lastDemand = counters.demand lastActual = counters.actual lastOvercommit = counters.overcommit + lastInterference = counters.interference val load = lastCpuDemand / ctx.cpus.sumOf { it.model.frequency } triggerGovernors(load) diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt index a985986d..6c1e134b 100644 --- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt +++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceDistributorMaxMin.kt @@ -22,9 +22,9 @@ package org.opendc.simulator.resources -import org.opendc.simulator.resources.impl.SimResourceCountersImpl import org.opendc.simulator.resources.interference.InterferenceDomain import org.opendc.simulator.resources.interference.InterferenceKey +import kotlin.math.max import kotlin.math.min /** @@ -71,9 +71,23 @@ public class SimResourceDistributorMaxMin( /** * The resource counters of this distributor. */ - public val counters: SimResourceCounters + public val counters: Counters get() = _counters - private val _counters = SimResourceCountersImpl() + private val _counters = object : Counters { + override var demand: Double = 0.0 + override var actual: Double = 0.0 + override var overcommit: Double = 0.0 + override var interference: Double = 0.0 + + override fun reset() { + demand = 0.0 + actual = 0.0 + overcommit = 0.0 + interference = 0.0 + } + + override fun toString(): String = "SimResourceDistributorMaxMin.Counters[demand=$demand,actual=$actual,overcommit=$overcommit,interference=$interference]" + } /* SimResourceDistributor */ override fun newOutput(key: InterferenceKey?): SimResourceCloseableProvider { @@ -110,6 +124,16 @@ public class SimResourceDistributorMaxMin( } } + /** + * Extended [SimResourceCounters] interface for the distributor. + */ + public interface Counters : SimResourceCounters { + /** + * The amount of work lost due to interference. + */ + public val interference: Double + } + /** * Update the counters of the distributor. */ @@ -326,7 +350,11 @@ public class SimResourceDistributorMaxMin( } // Compute the work that was actually granted to the output. - return (totalAllocatedWork - totalRemainingWork) * fraction * perfScore + val potentialConsumedWork = (totalAllocatedWork - totalRemainingWork) * fraction + + _counters.interference += potentialConsumedWork * max(0.0, 1 - perfScore) + + return potentialConsumedWork } /* Comparable */ diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSwitchMaxMin.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSwitchMaxMin.kt index d988b70d..e368609f 100644 --- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSwitchMaxMin.kt +++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimResourceSwitchMaxMin.kt @@ -53,7 +53,7 @@ public class SimResourceSwitchMaxMin( /** * The resource counters to track the execution metrics of all switch resources. */ - override val counters: SimResourceCounters + override val counters: SimResourceDistributorMaxMin.Counters get() = distributor.counters /** -- cgit v1.2.3