diff options
3 files changed, 21 insertions, 49 deletions
diff --git a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt index 12c2325a..7ed04994 100644 --- a/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt +++ b/opendc-compute/opendc-compute-workload/src/main/kotlin/org/opendc/compute/workload/ComputeWorkloadLoader.kt @@ -223,6 +223,11 @@ public class ComputeWorkloadLoader(private val baseDir: File) { private val builder = SimTrace.builder() /** + * The deadline of the previous fragment. + */ + private var previousDeadline = Long.MIN_VALUE + + /** * Add a fragment to the trace. * * @param timestamp Timestamp at which the fragment starts (in epoch millis). @@ -233,7 +238,14 @@ public class ComputeWorkloadLoader(private val baseDir: File) { fun add(timestamp: Long, deadline: Long, usage: Double, cores: Int) { val duration = max(0, deadline - timestamp) totalLoad += (usage * duration) / 1000.0 // avg MHz * duration = MFLOPs - builder.add(timestamp, deadline, usage, cores) + + if (timestamp != previousDeadline) { + // There is a gap between the previous and current fragment; fill the gap + builder.add(timestamp, 0.0, cores) + } + + builder.add(deadline, usage, cores) + previousDeadline = deadline } /** diff --git a/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt b/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt index f257ebb3..fbcc99c3 100644 --- a/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt +++ b/opendc-simulator/opendc-simulator-compute/src/jmh/kotlin/org/opendc/simulator/compute/SimMachineBenchmarks.kt @@ -22,7 +22,6 @@ package org.opendc.simulator.compute -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.opendc.simulator.compute.kernel.SimFairShareHypervisor @@ -63,7 +62,7 @@ class SimMachineBenchmarks { repeat(10000) { val timestamp = it.toLong() val deadline = timestamp + 1000 - builder.add(timestamp, deadline, random.nextDouble(0.0, 4500.0), 1) + builder.add(deadline, random.nextDouble(0.0, 4500.0), 1) } trace = builder.build() } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt index 6b820e5d..e66227b5 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt @@ -31,14 +31,12 @@ import kotlin.math.min * A workload trace that describes the resource utilization over time in a collection of [SimTraceFragment]s. * * @param usageCol The column containing the CPU usage of each fragment (in MHz). - * @param timestampCol The column containing the starting timestamp for each fragment (in epoch millis). * @param deadlineCol The column containing the ending timestamp for each fragment (in epoch millis). * @param coresCol The column containing the utilized cores. * @param size The number of fragments in the trace. */ public class SimTrace( private val usageCol: DoubleArray, - private val timestampCol: LongArray, private val deadlineCol: LongArray, private val coresCol: IntArray, private val size: Int, @@ -46,7 +44,6 @@ public class SimTrace( init { require(size >= 0) { "Invalid trace size" } require(usageCol.size >= size) { "Invalid number of usage entries" } - require(timestampCol.size >= size) { "Invalid number of timestamp entries" } require(deadlineCol.size >= size) { "Invalid number of deadline entries" } require(coresCol.size >= size) { "Invalid number of core entries" } } @@ -59,19 +56,17 @@ public class SimTrace( public fun ofFragments(fragments: List<SimTraceFragment>): SimTrace { val size = fragments.size val usageCol = DoubleArray(size) - val timestampCol = LongArray(size) val deadlineCol = LongArray(size) val coresCol = IntArray(size) for (i in fragments.indices) { val fragment = fragments[i] usageCol[i] = fragment.usage - timestampCol[i] = fragment.timestamp deadlineCol[i] = fragment.timestamp + fragment.duration coresCol[i] = fragment.cores } - return SimTrace(usageCol, timestampCol, deadlineCol, coresCol, size) + return SimTrace(usageCol, deadlineCol, coresCol, size) } /** @@ -81,19 +76,17 @@ public class SimTrace( public fun ofFragments(vararg fragments: SimTraceFragment): SimTrace { val size = fragments.size val usageCol = DoubleArray(size) - val timestampCol = LongArray(size) val deadlineCol = LongArray(size) val coresCol = IntArray(size) for (i in fragments.indices) { val fragment = fragments[i] usageCol[i] = fragment.usage - timestampCol[i] = fragment.timestamp deadlineCol[i] = fragment.timestamp + fragment.duration coresCol[i] = fragment.cores } - return SimTrace(usageCol, timestampCol, deadlineCol, coresCol, size) + return SimTrace(usageCol, deadlineCol, coresCol, size) } /** @@ -108,25 +101,9 @@ public class SimTrace( * * @param cpu The [ProcessingUnit] for which to create the source. * @param offset The time offset to use for the trace. - * @param fillMode The [FillMode] for filling missing data. */ - public fun newSource(cpu: ProcessingUnit, offset: Long, fillMode: FillMode = FillMode.None): FlowSource { - return CpuConsumer(cpu, offset, fillMode, usageCol, timestampCol, deadlineCol, coresCol, size) - } - - /** - * An enumeration describing the modes for filling missing data. - */ - public enum class FillMode { - /** - * When a gap in the trace data occurs, the CPU usage will be set to zero. - */ - None, - - /** - * When a gap in the trace data occurs, the previous CPU usage will be used. - */ - Previous + public fun newSource(cpu: ProcessingUnit, offset: Long): FlowSource { + return CpuConsumer(cpu, offset, usageCol, deadlineCol, coresCol, size) } /** @@ -137,7 +114,6 @@ public class SimTrace( * The columns of the trace. */ private var usageCol: DoubleArray = DoubleArray(16) - private var timestampCol: LongArray = LongArray(16) private var deadlineCol: LongArray = LongArray(16) private var coresCol: IntArray = IntArray(16) @@ -150,25 +126,23 @@ public class SimTrace( * Add the specified [SimTraceFragment] to the trace. */ public fun add(fragment: SimTraceFragment) { - add(fragment.timestamp, fragment.timestamp + fragment.duration, fragment.usage, fragment.cores) + add(fragment.timestamp + fragment.duration, fragment.usage, fragment.cores) } /** * Add a fragment to the trace. * - * @param timestamp Timestamp at which the fragment starts (in epoch millis). * @param deadline Timestamp at which the fragment ends (in epoch millis). * @param usage CPU usage of this fragment. * @param cores Number of cores used. */ - public fun add(timestamp: Long, deadline: Long, usage: Double, cores: Int) { + public fun add(deadline: Long, usage: Double, cores: Int) { val size = size if (size == usageCol.size) { grow() } - timestampCol[size] = timestamp deadlineCol[size] = deadline usageCol[size] = usage coresCol[size] = cores @@ -184,7 +158,6 @@ public class SimTrace( val newSize = arraySize + (arraySize shr 1) usageCol = usageCol.copyOf(newSize) - timestampCol = timestampCol.copyOf(newSize) deadlineCol = deadlineCol.copyOf(newSize) coresCol = coresCol.copyOf(newSize) } @@ -193,7 +166,7 @@ public class SimTrace( * Construct the immutable [SimTrace]. */ public fun build(): SimTrace { - return SimTrace(usageCol, timestampCol, deadlineCol, coresCol, size) + return SimTrace(usageCol, deadlineCol, coresCol, size) } } @@ -203,9 +176,7 @@ public class SimTrace( private class CpuConsumer( cpu: ProcessingUnit, private val offset: Long, - private val fillMode: FillMode, private val usageCol: DoubleArray, - private val timestampCol: LongArray, private val deadlineCol: LongArray, private val coresCol: IntArray, private val size: Int @@ -236,16 +207,6 @@ public class SimTrace( } _idx = idx - val timestamp = timestampCol[idx] - - // There is a gap in the trace, since the next fragment starts in the future. - if (timestamp > nowOffset) { - when (fillMode) { - FillMode.None -> conn.push(0.0) // Reset rate to zero - FillMode.Previous -> {} // Keep previous rate - } - return timestamp - nowOffset - } val cores = min(coreCount, coresCol[idx]) val usage = usageCol[idx] |
