From e68046465d39611259fa13952add731e80ea7331 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 15 Apr 2021 14:13:14 +0200 Subject: exp: Prevent re-use of SimWorkload in experiment This change fixes and issue where a SimWorkload was being re-used across simulation runs. Given that SimWorkload is stateless, this may cause strange issues. --- .../kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'simulator/opendc-simulator') diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt index 694a928b..ffb332d1 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt @@ -34,12 +34,14 @@ import org.opendc.simulator.resources.consumer.SimConsumerBarrier * consumption for some period of time. */ public class SimTraceWorkload(public val trace: Sequence) : SimWorkload { - private var offset = 0L + private var offset = Long.MIN_VALUE private val iterator = trace.iterator() private var fragment: Fragment? = null private lateinit var barrier: SimConsumerBarrier override fun onStart(ctx: SimMachineContext) { + check(offset == Long.MIN_VALUE) { "Workload does not support re-use" } + barrier = SimConsumerBarrier(ctx.cpus.size) fragment = nextFragment() offset = ctx.clock.millis() -- cgit v1.2.3