summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-06 11:45:35 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-05-06 22:13:43 +0200
commitdd280852800824748544444212842a322fe2e1dc (patch)
tree02a787e63aaef820eb742320a3d432786528bd36
parent203dd5dc4815aa59977b3f932f80cb37be006bfb (diff)
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.
-rw-r--r--opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt3
1 files changed, 2 insertions, 1 deletions
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
}