summaryrefslogtreecommitdiff
path: root/simulator/opendc-simulator/opendc-simulator-compute/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src/main')
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractHypervisor.kt24
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt17
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt6
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimFairShareHypervisor.kt9
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineContext.kt13
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineModel.kt6
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisor.kt5
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/MemoryUnit.kt (renamed from simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimMemoryUnit.kt)9
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingNode.kt (renamed from simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingNode.kt)2
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingUnit.kt (renamed from simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingUnit.kt)11
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkload.kt4
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimRuntimeWorkload.kt4
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt40
-rw-r--r--simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkload.kt4
14 files changed, 69 insertions, 85 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractHypervisor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractHypervisor.kt
index 281d43ae..81d09f12 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractHypervisor.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractHypervisor.kt
@@ -27,8 +27,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import org.opendc.simulator.compute.interference.PerformanceInterferenceModel
-import org.opendc.simulator.compute.model.SimMemoryUnit
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.MemoryUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.resources.*
import java.time.Clock
@@ -45,7 +45,7 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
/**
* The resource switch to use.
*/
- private lateinit var switch: SimResourceSwitch<SimProcessingUnit>
+ private lateinit var switch: SimResourceSwitch
/**
* The virtual machines running on this hypervisor.
@@ -57,12 +57,12 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
/**
* Construct the [SimResourceSwitch] implementation that performs the actual scheduling of the CPUs.
*/
- public abstract fun createSwitch(ctx: SimMachineContext): SimResourceSwitch<SimProcessingUnit>
+ public abstract fun createSwitch(ctx: SimMachineContext): SimResourceSwitch
/**
* Check whether the specified machine model fits on this hypervisor.
*/
- public abstract fun canFit(model: SimMachineModel, switch: SimResourceSwitch<SimProcessingUnit>): Boolean
+ public abstract fun canFit(model: SimMachineModel, switch: SimResourceSwitch): Boolean
override fun canFit(model: SimMachineModel): Boolean {
return canFit(model, switch)
@@ -101,7 +101,7 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
/**
* The vCPUs of the machine.
*/
- private val cpus: Map<SimProcessingUnit, SimResourceProvider<SimProcessingUnit>> = model.cpus.associateWith { switch.addOutput(it) }
+ private val cpus: Map<ProcessingUnit, SimResourceProvider> = model.cpus.associateWith { switch.addOutput(it.frequency) }
/**
* Run the specified [SimWorkload] on this machine and suspend execution util the workload has finished.
@@ -111,10 +111,10 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
require(!isTerminated) { "Machine is terminated" }
val ctx = object : SimMachineContext {
- override val cpus: List<SimProcessingUnit>
+ override val cpus: List<ProcessingUnit>
get() = model.cpus
- override val memory: List<SimMemoryUnit>
+ override val memory: List<MemoryUnit>
get() = model.memory
override val clock: Clock
@@ -122,8 +122,8 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
override val meta: Map<String, Any> = meta
- override fun interrupt(resource: SimResource) {
- requireNotNull(this@VirtualMachine.cpus[resource]).interrupt()
+ override fun interrupt(cpu: ProcessingUnit) {
+ requireNotNull(this@VirtualMachine.cpus[cpu]).interrupt()
}
}
@@ -155,8 +155,8 @@ public abstract class SimAbstractHypervisor : SimHypervisor {
switch = createSwitch(ctx)
}
- override fun getConsumer(ctx: SimMachineContext, cpu: SimProcessingUnit): SimResourceConsumer<SimProcessingUnit> {
- val forwarder = SimResourceForwarder(cpu)
+ override fun getConsumer(ctx: SimMachineContext, cpu: ProcessingUnit): SimResourceConsumer {
+ val forwarder = SimResourceForwarder()
switch.addInput(forwarder)
return forwarder
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
index 44906c2b..52945354 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
@@ -27,10 +27,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
-import org.opendc.simulator.compute.model.SimMemoryUnit
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.MemoryUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.workload.SimWorkload
-import org.opendc.simulator.resources.SimResource
import org.opendc.simulator.resources.SimResourceProvider
import org.opendc.simulator.resources.SimResourceSource
import org.opendc.simulator.resources.consume
@@ -65,24 +64,24 @@ public abstract class SimAbstractMachine(private val clock: Clock) : SimMachine
/**
* The resources allocated for this machine.
*/
- protected abstract val resources: Map<SimProcessingUnit, SimResourceSource<SimProcessingUnit>>
+ protected abstract val resources: Map<ProcessingUnit, SimResourceSource>
/**
* The execution context in which the workload runs.
*/
private inner class Context(
- val sources: Map<SimProcessingUnit, SimResourceProvider<SimProcessingUnit>>,
+ val sources: Map<ProcessingUnit, SimResourceProvider>,
override val meta: Map<String, Any>
) : SimMachineContext {
override val clock: Clock
get() = this@SimAbstractMachine.clock
- override val cpus: List<SimProcessingUnit> = model.cpus
+ override val cpus: List<ProcessingUnit> = model.cpus
- override val memory: List<SimMemoryUnit> = model.memory
+ override val memory: List<MemoryUnit> = model.memory
- override fun interrupt(resource: SimResource) {
- checkNotNull(sources[resource]) { "Invalid resource" }.interrupt()
+ override fun interrupt(cpu: ProcessingUnit) {
+ checkNotNull(sources[cpu]) { "Invalid resource" }.interrupt()
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
index 79982ea8..19479719 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
@@ -23,7 +23,7 @@
package org.opendc.simulator.compute
import kotlinx.coroutines.*
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.resources.*
import org.opendc.utils.TimerScheduler
import java.time.Clock
@@ -57,8 +57,8 @@ public class SimBareMetalMachine(
*/
private val scheduler = TimerScheduler<Any>(this.context, clock)
- override val resources: Map<SimProcessingUnit, SimResourceSource<SimProcessingUnit>> =
- model.cpus.associateWith { SimResourceSource(it, clock, scheduler) }
+ override val resources: Map<ProcessingUnit, SimResourceSource> =
+ model.cpus.associateWith { SimResourceSource(it.frequency, clock, scheduler) }
override fun close() {
super.close()
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimFairShareHypervisor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimFairShareHypervisor.kt
index c629fbd9..fa677de9 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimFairShareHypervisor.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimFairShareHypervisor.kt
@@ -22,7 +22,6 @@
package org.opendc.simulator.compute
-import org.opendc.simulator.compute.model.SimProcessingUnit
import org.opendc.simulator.compute.workload.SimWorkload
import org.opendc.simulator.resources.*
@@ -34,14 +33,14 @@ import org.opendc.simulator.resources.*
*/
public class SimFairShareHypervisor(private val listener: SimHypervisor.Listener? = null) : SimAbstractHypervisor() {
- override fun canFit(model: SimMachineModel, switch: SimResourceSwitch<SimProcessingUnit>): Boolean = true
+ override fun canFit(model: SimMachineModel, switch: SimResourceSwitch): Boolean = true
- override fun createSwitch(ctx: SimMachineContext): SimResourceSwitch<SimProcessingUnit> {
+ override fun createSwitch(ctx: SimMachineContext): SimResourceSwitch {
return SimResourceSwitchMaxMin(
ctx.clock,
- object : SimResourceSwitchMaxMin.Listener<SimProcessingUnit> {
+ object : SimResourceSwitchMaxMin.Listener {
override fun onSliceFinish(
- switch: SimResourceSwitchMaxMin<SimProcessingUnit>,
+ switch: SimResourceSwitchMaxMin,
requestedWork: Long,
grantedWork: Long,
overcommittedWork: Long,
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineContext.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineContext.kt
index cff70826..85404e6e 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineContext.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineContext.kt
@@ -22,9 +22,8 @@
package org.opendc.simulator.compute
-import org.opendc.simulator.compute.model.SimMemoryUnit
-import org.opendc.simulator.compute.model.SimProcessingUnit
-import org.opendc.simulator.resources.SimResource
+import org.opendc.simulator.compute.model.MemoryUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import java.time.Clock
/**
@@ -46,17 +45,17 @@ public interface SimMachineContext {
/**
* The CPUs available on the machine.
*/
- public val cpus: List<SimProcessingUnit>
+ public val cpus: List<ProcessingUnit>
/**
* The memory available on the machine
*/
- public val memory: List<SimMemoryUnit>
+ public val memory: List<MemoryUnit>
/**
- * Interrupt the specified [resource].
+ * Interrupt the specified [cpu].
*
* @throws IllegalArgumentException if the resource does not belong to this execution context.
*/
- public fun interrupt(resource: SimResource)
+ public fun interrupt(cpu: ProcessingUnit)
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineModel.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineModel.kt
index d6bf0e99..2b414540 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineModel.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimMachineModel.kt
@@ -22,8 +22,8 @@
package org.opendc.simulator.compute
-import org.opendc.simulator.compute.model.SimMemoryUnit
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.MemoryUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
/**
* A description of the physical or virtual machine on which a bootable image runs.
@@ -31,4 +31,4 @@ import org.opendc.simulator.compute.model.SimProcessingUnit
* @property cpus The list of processing units available to the image.
* @property memory The list of memory units available to the image.
*/
-public data class SimMachineModel(public val cpus: List<SimProcessingUnit>, public val memory: List<SimMemoryUnit>)
+public data class SimMachineModel(public val cpus: List<ProcessingUnit>, public val memory: List<MemoryUnit>)
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisor.kt
index 5de69884..fd8e546f 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisor.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimSpaceSharedHypervisor.kt
@@ -22,18 +22,17 @@
package org.opendc.simulator.compute
-import org.opendc.simulator.compute.model.SimProcessingUnit
import org.opendc.simulator.resources.*
/**
* A [SimHypervisor] that allocates its sub-resources exclusively for the virtual machine that it hosts.
*/
public class SimSpaceSharedHypervisor : SimAbstractHypervisor() {
- override fun canFit(model: SimMachineModel, switch: SimResourceSwitch<SimProcessingUnit>): Boolean {
+ override fun canFit(model: SimMachineModel, switch: SimResourceSwitch): Boolean {
return switch.inputs.size - switch.outputs.size >= model.cpus.size
}
- override fun createSwitch(ctx: SimMachineContext): SimResourceSwitch<SimProcessingUnit> {
+ override fun createSwitch(ctx: SimMachineContext): SimResourceSwitch {
return SimResourceSwitchExclusive()
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimMemoryUnit.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/MemoryUnit.kt
index 49745868..bcbde5b1 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimMemoryUnit.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/MemoryUnit.kt
@@ -22,8 +22,6 @@
package org.opendc.simulator.compute.model
-import org.opendc.simulator.resources.SimResource
-
/**
* A memory unit of a compute resource, either virtual or physical.
*
@@ -32,12 +30,9 @@ import org.opendc.simulator.resources.SimResource
* @property speed The access speed of the memory in MHz.
* @property size The size of the memory unit in MBs.
*/
-public data class SimMemoryUnit(
+public data class MemoryUnit(
public val vendor: String,
public val modelName: String,
public val speed: Double,
public val size: Long
-) : SimResource {
- override val capacity: Double
- get() = speed
-}
+)
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingNode.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingNode.kt
index 4022ecb3..58ed816c 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingNode.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingNode.kt
@@ -30,7 +30,7 @@ package org.opendc.simulator.compute.model
* @property arch The micro-architecture of the processor node.
* @property coreCount The number of logical CPUs in the processor node.
*/
-public data class SimProcessingNode(
+public data class ProcessingNode(
public val vendor: String,
public val arch: String,
public val modelName: String,
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingUnit.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingUnit.kt
index 1c989254..415e95e6 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/SimProcessingUnit.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/model/ProcessingUnit.kt
@@ -22,8 +22,6 @@
package org.opendc.simulator.compute.model
-import org.opendc.simulator.resources.SimResource
-
/**
* A single logical compute unit of processor node, either virtual or physical.
*
@@ -31,11 +29,8 @@ import org.opendc.simulator.resources.SimResource
* @property id The identifier of the CPU core within the processing node.
* @property frequency The clock rate of the CPU in MHz.
*/
-public data class SimProcessingUnit(
- public val node: SimProcessingNode,
+public data class ProcessingUnit(
+ public val node: ProcessingNode,
public val id: Int,
public val frequency: Double
-) : SimResource {
- override val capacity: Double
- get() = frequency
-}
+)
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkload.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkload.kt
index f1079ee6..63c9d28c 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkload.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimFlopsWorkload.kt
@@ -23,7 +23,7 @@
package org.opendc.simulator.compute.workload
import org.opendc.simulator.compute.SimMachineContext
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.resources.SimResourceConsumer
import org.opendc.simulator.resources.consumer.SimWorkConsumer
@@ -45,7 +45,7 @@ public class SimFlopsWorkload(
override fun onStart(ctx: SimMachineContext) {}
- override fun getConsumer(ctx: SimMachineContext, cpu: SimProcessingUnit): SimResourceConsumer<SimProcessingUnit> {
+ override fun getConsumer(ctx: SimMachineContext, cpu: ProcessingUnit): SimResourceConsumer {
return SimWorkConsumer(flops.toDouble() / ctx.cpus.size, utilization)
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimRuntimeWorkload.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimRuntimeWorkload.kt
index d7aa8f80..a3420e32 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimRuntimeWorkload.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimRuntimeWorkload.kt
@@ -23,7 +23,7 @@
package org.opendc.simulator.compute.workload
import org.opendc.simulator.compute.SimMachineContext
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.resources.SimResourceConsumer
import org.opendc.simulator.resources.consumer.SimWorkConsumer
@@ -44,7 +44,7 @@ public class SimRuntimeWorkload(
override fun onStart(ctx: SimMachineContext) {}
- override fun getConsumer(ctx: SimMachineContext, cpu: SimProcessingUnit): SimResourceConsumer<SimProcessingUnit> {
+ override fun getConsumer(ctx: SimMachineContext, cpu: ProcessingUnit): SimResourceConsumer {
val limit = cpu.frequency * utilization
return SimWorkConsumer((limit / 1000) * duration, utilization)
}
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 e8050263..2442d748 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
@@ -23,7 +23,7 @@
package org.opendc.simulator.compute.workload
import org.opendc.simulator.compute.SimMachineContext
-import org.opendc.simulator.compute.model.SimProcessingUnit
+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
@@ -45,31 +45,29 @@ public class SimTraceWorkload(public val trace: Sequence<Fragment>) : SimWorkloa
offset = ctx.clock.millis()
}
- override fun getConsumer(ctx: SimMachineContext, cpu: SimProcessingUnit): SimResourceConsumer<SimProcessingUnit> {
- return CpuConsumer()
- }
+ override fun getConsumer(ctx: SimMachineContext, cpu: ProcessingUnit): SimResourceConsumer {
+ return object : SimResourceConsumer {
+ override fun onNext(ctx: SimResourceContext): SimResourceCommand {
+ val now = ctx.clock.millis()
+ val fragment = fragment ?: return SimResourceCommand.Exit
+ val work = (fragment.duration / 1000) * fragment.usage
+ val deadline = offset + fragment.duration
- private inner class CpuConsumer : SimResourceConsumer<SimProcessingUnit> {
- override fun onNext(ctx: SimResourceContext<SimProcessingUnit>): SimResourceCommand {
- val now = ctx.clock.millis()
- val fragment = fragment ?: return SimResourceCommand.Exit
- val work = (fragment.duration / 1000) * fragment.usage
- val deadline = offset + fragment.duration
+ assert(deadline >= now) { "Deadline already passed" }
- assert(deadline >= now) { "Deadline already passed" }
+ val cmd =
+ if (cpu.id < fragment.cores && work > 0.0)
+ SimResourceCommand.Consume(work, fragment.usage, deadline)
+ else
+ SimResourceCommand.Idle(deadline)
- val cmd =
- if (ctx.resource.id < fragment.cores && work > 0.0)
- SimResourceCommand.Consume(work, fragment.usage, deadline)
- else
- SimResourceCommand.Idle(deadline)
+ if (barrier.enter()) {
+ this@SimTraceWorkload.fragment = nextFragment()
+ this@SimTraceWorkload.offset += fragment.duration
+ }
- if (barrier.enter()) {
- this@SimTraceWorkload.fragment = nextFragment()
- this@SimTraceWorkload.offset += fragment.duration
+ return cmd
}
-
- return cmd
}
}
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkload.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkload.kt
index 60661e23..bdc12bb5 100644
--- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkload.kt
+++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkload.kt
@@ -23,7 +23,7 @@
package org.opendc.simulator.compute.workload
import org.opendc.simulator.compute.SimMachineContext
-import org.opendc.simulator.compute.model.SimProcessingUnit
+import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.resources.SimResourceConsumer
/**
@@ -41,5 +41,5 @@ public interface SimWorkload {
/**
* Obtain the resource consumer for the specified processing unit.
*/
- public fun getConsumer(ctx: SimMachineContext, cpu: SimProcessingUnit): SimResourceConsumer<SimProcessingUnit>
+ public fun getConsumer(ctx: SimMachineContext, cpu: ProcessingUnit): SimResourceConsumer
}