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.kt10
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt21
2 files changed, 16 insertions, 15 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 34ac4418..6e6e590f 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
@@ -24,7 +24,6 @@ package org.opendc.simulator.compute.device
import org.opendc.simulator.compute.power.PowerDriver
import org.opendc.simulator.power.SimPowerInlet
-import org.opendc.simulator.resources.SimResourceCommand
import org.opendc.simulator.resources.SimResourceConsumer
import org.opendc.simulator.resources.SimResourceContext
import org.opendc.simulator.resources.SimResourceEvent
@@ -83,13 +82,10 @@ public class SimPsu(
}
override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer {
- override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): Long {
val powerDraw = computePowerDraw(_driver?.computePower() ?: 0.0)
-
- return if (powerDraw > 0.0)
- SimResourceCommand.Consume(powerDraw, Long.MAX_VALUE)
- else
- SimResourceCommand.Consume(0.0)
+ ctx.push(powerDraw)
+ return Long.MAX_VALUE
}
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 527619bd..dd582bb2 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
@@ -24,7 +24,6 @@ package org.opendc.simulator.compute.workload
import org.opendc.simulator.compute.SimMachineContext
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
@@ -80,13 +79,20 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>, private val
}
private inner class Consumer(val cpu: ProcessingUnit) : SimResourceConsumer {
- override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
- val fragment = pullFragment(now) ?: return SimResourceCommand.Exit
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): Long {
+ val fragment = pullFragment(now)
+
+ if (fragment == null) {
+ ctx.close()
+ return Long.MAX_VALUE
+ }
+
val timestamp = fragment.timestamp + offset
// Fragment is in the future
if (timestamp > now) {
- return SimResourceCommand.Consume(0.0, timestamp - now)
+ ctx.push(0.0)
+ return timestamp - now
}
val cores = min(cpu.node.coreCount, fragment.cores)
@@ -97,10 +103,9 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>, private val
val deadline = timestamp + fragment.duration
val duration = deadline - now
- return if (cpu.id < cores && usage > 0.0)
- SimResourceCommand.Consume(usage, duration)
- else
- SimResourceCommand.Consume(0.0, duration)
+ ctx.push(if (cpu.id < cores && usage > 0.0) usage else 0.0)
+
+ return duration
}
}