summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt6
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt12
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt2
3 files changed, 10 insertions, 10 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
index 0a7dc40f..34ac4418 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
@@ -83,13 +83,13 @@ public class SimPsu(
}
override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer {
- override fun onNext(ctx: SimResourceContext): SimResourceCommand {
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
val powerDraw = computePowerDraw(_driver?.computePower() ?: 0.0)
return if (powerDraw > 0.0)
- SimResourceCommand.Consume(Double.POSITIVE_INFINITY, powerDraw, Long.MAX_VALUE)
+ SimResourceCommand.Consume(powerDraw, Long.MAX_VALUE)
else
- SimResourceCommand.Idle()
+ SimResourceCommand.Consume(0.0)
}
override fun onEvent(ctx: SimResourceContext, event: SimResourceEvent) {
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 5a4c4f44..527619bd 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
@@ -80,14 +80,13 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>, private val
}
private inner class Consumer(val cpu: ProcessingUnit) : SimResourceConsumer {
- override fun onNext(ctx: SimResourceContext): SimResourceCommand {
- val now = ctx.clock.millis()
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
val fragment = pullFragment(now) ?: return SimResourceCommand.Exit
val timestamp = fragment.timestamp + offset
// Fragment is in the future
if (timestamp > now) {
- return SimResourceCommand.Idle(timestamp)
+ return SimResourceCommand.Consume(0.0, timestamp - now)
}
val cores = min(cpu.node.coreCount, fragment.cores)
@@ -97,12 +96,11 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>, private val
0.0
val deadline = timestamp + fragment.duration
val duration = deadline - now
- val work = duration * usage / 1000
- return if (cpu.id < cores && work > 0.0)
- SimResourceCommand.Consume(work, usage, deadline)
+ return if (cpu.id < cores && usage > 0.0)
+ SimResourceCommand.Consume(usage, duration)
else
- SimResourceCommand.Idle(deadline)
+ SimResourceCommand.Consume(0.0, duration)
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
index 3d3feb2a..55d6d7c4 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
@@ -155,6 +155,8 @@ internal class SimSpaceSharedHypervisorTest {
vm.run(SimRuntimeWorkload(duration))
vm.close()
+ yield()
+
val vm2 = hypervisor.createMachine(machineModel)
vm2.run(SimRuntimeWorkload(duration))
vm2.close()