From dd280852800824748544444212842a322fe2e1dc Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Fri, 6 May 2022 11:45:35 +0200 Subject: fix(exp/tf20): Fix infinite loop due to invalid rounding This change fixes an issue with the `SimTFDevice` implementation where very small amounts of FLOPs would cause the device to enter an infinite loop. We now round the value up to ensure that the device always consumes FLOPs. --- .../src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'opendc-experiments/opendc-experiments-tf20') diff --git a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt index d2105196..90350142 100644 --- a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt +++ b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt @@ -39,6 +39,7 @@ import java.util.* import kotlin.coroutines.Continuation import kotlin.coroutines.CoroutineContext import kotlin.coroutines.resume +import kotlin.math.ceil import kotlin.math.roundToLong /** @@ -137,7 +138,7 @@ public class SimTFDevice( if (activeWork.consume(consumedWork)) { this.activeWork = null } else { - val duration = (activeWork.flops / conn.capacity * 1000).roundToLong() + val duration = ceil(activeWork.flops / conn.capacity * 1000).toLong() conn.push(conn.capacity) return duration } -- cgit v1.2.3