From eff68d2f292f1c614b49af56fbe35b0ca322a578 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 8 Apr 2021 10:11:56 +0200 Subject: simulator: Perform usage propagation only on change This change updates the logic in SimAbstractMachine to only propagate usages when the value has changed. --- .../kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'simulator/opendc-simulator') 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) } -- cgit v1.2.3