summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-01-11 13:53:07 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-18 16:53:52 +0100
commit841eaeb84a96cb1b20172b1ab293ebef0bb573a5 (patch)
tree1c744a0ad30d739de09bc5ffe7b1631cee925de3 /opendc-simulator/opendc-simulator-compute/src
parent2615c1c3e6c3f79bc14386398bb1d14d65c17512 (diff)
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.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt21
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt5
2 files changed, 24 insertions, 2 deletions
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()
}