From 841eaeb84a96cb1b20172b1ab293ebef0bb573a5 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 11 Jan 2022 13:53:07 +0100 Subject: fix(simulator): Flush results before accessing counters This change updates the simulator implementation to flush the active progress when accessing the hypervisor counters. Previously, if the counters were accessed, while the mux or consumer was in progress, its counter values were not accurate. --- .../compute/kernel/SimAbstractHypervisor.kt | 21 +++++++++++++++++++-- .../compute/kernel/SimHypervisorCounters.kt | 5 +++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'opendc-simulator/opendc-simulator-compute') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt index 07465126..b7f70749 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt @@ -137,7 +137,9 @@ public abstract class SimAbstractHypervisor( /* FlowConvergenceListener */ override fun onConverge(now: Long, delta: Long) { - _counters.record() + if (delta > 0) { + _counters.record() + } val load = cpuDemand / cpuCapacity for (governor in governors) { @@ -274,6 +276,10 @@ public abstract class SimAbstractHypervisor( fun close() { switch.removeInput(source) } + + fun flush() { + switch.flushCounters(source) + } } /** @@ -337,6 +343,11 @@ public abstract class SimAbstractHypervisor( cpuTime[2] += ((demandDelta - actualDelta) * d).roundToLong() cpuTime[3] += (interferenceDelta * d).roundToLong() } + + override fun flush() { + hv.mux.flushCounters() + record() + } } /** @@ -348,10 +359,16 @@ public abstract class SimAbstractHypervisor( override val cpuActiveTime: Long get() = (cpus.sumOf { it.counters.actual } * d).roundToLong() override val cpuIdleTime: Long - get() = (cpus.sumOf { it.counters.actual + it.counters.remaining } * d).roundToLong() + get() = (cpus.sumOf { it.counters.remaining } * d).roundToLong() override val cpuStealTime: Long get() = (cpus.sumOf { it.counters.demand - it.counters.actual } * d).roundToLong() override val cpuLostTime: Long get() = (cpus.sumOf { it.counters.interference } * d).roundToLong() + + override fun flush() { + for (cpu in cpus) { + cpu.flush() + } + } } } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt index 030d9c5f..63fee507 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt @@ -45,4 +45,9 @@ public interface SimHypervisorCounters { * The amount of CPU time (in milliseconds) that was lost due to interference between virtual machines. */ public val cpuLostTime: Long + + /** + * Flush the counter values. + */ + public fun flush() } -- cgit v1.2.3 From 5a0821e19eed87e91054289051213cb60b4235b4 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 12 Jan 2022 23:17:33 +0100 Subject: refactor(simulator): Remove delta parameter from flow callbacks This change removes the delta parameter from the callbacks of the flow framework. This parameter was used to indicate the duration in time between the last call and the current call. However, its usefulness was limited since the actual delta values needed by implementors of this method had to be bridged across different flow callbacks. --- .../org/opendc/simulator/compute/SimAbstractMachine.kt | 5 ++--- .../org/opendc/simulator/compute/SimBareMetalMachine.kt | 2 +- .../kotlin/org/opendc/simulator/compute/device/SimPsu.kt | 6 +++--- .../opendc/simulator/compute/kernel/SimAbstractHypervisor.kt | 9 +++++++-- .../kotlin/org/opendc/simulator/compute/workload/SimTrace.kt | 2 +- .../simulator/compute/workload/SimWorkloadLifecycle.kt | 12 ++++++------ 6 files changed, 20 insertions(+), 16 deletions(-) (limited to 'opendc-simulator/opendc-simulator-compute') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt index 6a4c594d..e14ea507 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt @@ -22,7 +22,6 @@ package org.opendc.simulator.compute -import kotlinx.coroutines.* import mu.KotlinLogging import org.opendc.simulator.compute.device.SimNetworkAdapter import org.opendc.simulator.compute.device.SimPeripheral @@ -87,8 +86,8 @@ public abstract class SimAbstractMachine( _ctx?.close() } - override fun onConverge(now: Long, delta: Long) { - parent?.onConverge(now, delta) + override fun onConverge(now: Long) { + parent?.onConverge(now) } /** diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt index 5df03d45..68792c72 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt @@ -81,7 +81,7 @@ public class SimBareMetalMachine( private var _lastConverge = Long.MAX_VALUE - override fun onConverge(now: Long, delta: Long) { + override fun onConverge(now: Long) { // Update the PSU stage psu.update() diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt index 09defbb5..caff4dc3 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt @@ -86,17 +86,17 @@ public class SimPsu( conn.shouldSourceConverge = true } - override fun onStop(conn: FlowConnection, now: Long, delta: Long) { + override fun onStop(conn: FlowConnection, now: Long) { _ctx = null } - override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long { + override fun onPull(conn: FlowConnection, now: Long): Long { val powerDraw = computePowerDraw(_driver?.computePower() ?: 0.0) conn.push(powerDraw) return Long.MAX_VALUE } - override fun onConverge(conn: FlowConnection, now: Long, delta: Long) { + override fun onConverge(conn: FlowConnection, now: Long) { _powerDraw = conn.rate } } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt index b7f70749..8e925bdf 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt @@ -134,9 +134,14 @@ public abstract class SimAbstractHypervisor( private var _cpuCount = 0 private var _cpuCapacity = 0.0 + private var _lastConverge = engine.clock.millis() /* FlowConvergenceListener */ - override fun onConverge(now: Long, delta: Long) { + override fun onConverge(now: Long) { + val lastConverge = _lastConverge + _lastConverge = now + val delta = now - lastConverge + if (delta > 0) { _counters.record() } @@ -146,7 +151,7 @@ public abstract class SimAbstractHypervisor( governor.onLimit(load) } - listener?.onConverge(now, delta) + listener?.onConverge(now) } /** diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt index 4cf60605..207e8579 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt @@ -217,7 +217,7 @@ public class SimTrace( */ private var _idx = 0 - override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long { + override fun onPull(conn: FlowConnection, now: Long): Long { val size = size val nowOffset = now - offset diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt index 742470a1..46113bb0 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt @@ -61,17 +61,17 @@ public class SimWorkloadLifecycle(private val ctx: SimMachineContext) { delegate.onStart(conn, now) } - override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long { - return delegate.onPull(conn, now, delta) + override fun onPull(conn: FlowConnection, now: Long): Long { + return delegate.onPull(conn, now) } - override fun onConverge(conn: FlowConnection, now: Long, delta: Long) { - delegate.onConverge(conn, now, delta) + override fun onConverge(conn: FlowConnection, now: Long) { + delegate.onConverge(conn, now) } - override fun onStop(conn: FlowConnection, now: Long, delta: Long) { + override fun onStop(conn: FlowConnection, now: Long) { try { - delegate.onStop(conn, now, delta) + delegate.onStop(conn, now) } finally { complete(this) } -- cgit v1.2.3