summaryrefslogtreecommitdiff
path: root/simulator
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-08 10:11:56 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-04-08 10:15:12 +0200
commiteff68d2f292f1c614b49af56fbe35b0ca322a578 (patch)
tree6cccfad6d3a305a1c9736f48f6acf8449d202ac8 /simulator
parent5d3b759b18fb0a4278b43dea6a9db478b07804a5 (diff)
simulator: Perform usage propagation only on change
This change updates the logic in SimAbstractMachine to only propagate usages when the value has changed.
Diffstat (limited to 'simulator')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt8
1 files changed, 7 insertions, 1 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
index 1f26c9c9..252a40ec 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
@@ -101,11 +101,17 @@ public abstract class SimAbstractMachine(private val clock: Clock) : SimMachine
for ((cpu, source) in resources) {
val consumer = workload.getConsumer(ctx, cpu)
val adapter = SimSpeedConsumerAdapter(consumer) { newSpeed ->
+ val _speed = _speed
+ val _usage = _usage
+
val oldSpeed = _speed[cpu.id]
_speed[cpu.id] = newSpeed
totalSpeed = totalSpeed - oldSpeed + newSpeed
- updateUsage(totalSpeed / totalCapacity)
+ val newUsage = totalSpeed / totalCapacity
+ if (_usage.value != newUsage) {
+ updateUsage(totalSpeed / totalCapacity)
+ }
}
launch { source.consume(adapter) }