diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-08-18 21:54:09 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-08-24 11:48:43 +0200 |
| commit | 709cd4909ccc1305c7acfdf666156168d66646eb (patch) | |
| tree | a9c95f0f0c320943dda287c4d8c96c7fb4336471 /opendc-simulator/opendc-simulator-resources | |
| parent | 97a28129e4638f601864a08f483908907b9026e6 (diff) | |
feat(simulator): Add support for reporting interfered work
This change adds support to the simulator for reporting the work lost
due to performance interference.
Diffstat (limited to 'opendc-simulator/opendc-simulator-resources')
2 files changed, 33 insertions, 5 deletions
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 { @@ -111,6 +125,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. */ private fun updateCounters(ctx: SimResourceControllableContext, work: Double, willOvercommit: Boolean) { @@ -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 /** |
