summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-13 14:39:38 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-17 17:14:14 +0200
commite26b81568db1b08c87dd43d416e129e32d5de26b (patch)
treea8145f6fd2968f443c1981b060ed7680b102f056 /opendc-simulator/opendc-simulator-compute
parentc1b9719aad10566c9d17f9eb757236c58a602b89 (diff)
fix(simulator): Support workload/machine CPU count mismatch
This change allows workloads that require more CPUs than available on the machine to still function properly.
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt6
1 files changed, 4 insertions, 2 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt
index 48be8e1a..5a4c4f44 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt
@@ -27,6 +27,7 @@ import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.resources.SimResourceCommand
import org.opendc.simulator.resources.SimResourceConsumer
import org.opendc.simulator.resources.SimResourceContext
+import kotlin.math.min
/**
* A [SimWorkload] that replays a workload trace consisting of multiple fragments, each indicating the resource
@@ -89,15 +90,16 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>, private val
return SimResourceCommand.Idle(timestamp)
}
+ val cores = min(cpu.node.coreCount, fragment.cores)
val usage = if (fragment.cores > 0)
- fragment.usage / fragment.cores
+ fragment.usage / cores
else
0.0
val deadline = timestamp + fragment.duration
val duration = deadline - now
val work = duration * usage / 1000
- return if (cpu.id < fragment.cores && work > 0.0)
+ return if (cpu.id < cores && work > 0.0)
SimResourceCommand.Consume(work, usage, deadline)
else
SimResourceCommand.Idle(deadline)