diff options
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt | 8 |
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) } |
