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/kernel/SimAbstractHypervisor.kt12
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisor.kt5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt7
3 files changed, 11 insertions, 13 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
index b98647e7..b3898004 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
@@ -93,9 +93,9 @@ public abstract class SimAbstractHypervisor(
private val governors = mutableListOf<ScalingGovernor.Logic>()
/* SimHypervisor */
- override fun newMachine(model: MachineModel, interferenceId: String?): SimVirtualMachine {
+ override fun newMachine(model: MachineModel, interferenceKey: VmInterferenceKey?): SimVirtualMachine {
require(canFit(model)) { "Machine does not fit" }
- val vm = VirtualMachine(model, interferenceId)
+ val vm = VirtualMachine(model, interferenceKey)
_vms.add(vm)
return vm
}
@@ -159,10 +159,11 @@ public abstract class SimAbstractHypervisor(
* A virtual machine running on the hypervisor.
*
* @param model The machine model of the virtual machine.
+ * @param interferenceKey The interference key of this virtual machine.
*/
private inner class VirtualMachine(
model: MachineModel,
- interferenceId: String? = null
+ private val interferenceKey: VmInterferenceKey? = null
) : SimAbstractMachine(engine, model), SimVirtualMachine, AutoCloseable {
/**
* A flag to indicate that the machine is closed.
@@ -170,11 +171,6 @@ public abstract class SimAbstractHypervisor(
private var isClosed = false
/**
- * The interference key of this virtual machine.
- */
- private val interferenceKey: VmInterferenceKey? = interferenceId?.let { interferenceDomain?.createKey(it) }
-
- /**
* The vCPUs of the machine.
*/
override val cpus = model.cpus.map { cpu -> VCpu(mux, mux.newInput(cpu.frequency), cpu) }
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisor.kt
index a69f419f..229e569c 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisor.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisor.kt
@@ -23,6 +23,7 @@
package org.opendc.simulator.compute.kernel
import org.opendc.simulator.compute.SimMachine
+import org.opendc.simulator.compute.kernel.interference.VmInterferenceKey
import org.opendc.simulator.compute.model.MachineModel
import org.opendc.simulator.compute.workload.SimWorkload
@@ -65,9 +66,9 @@ public interface SimHypervisor : SimWorkload {
* Create a [SimMachine] instance on which users may run a [SimWorkload].
*
* @param model The machine to create.
- * @param interferenceId An identifier for the interference model.
+ * @param interferenceKey The key of the machine in the interference model.
*/
- public fun newMachine(model: MachineModel, interferenceId: String? = null): SimVirtualMachine
+ public fun newMachine(model: MachineModel, interferenceKey: VmInterferenceKey? = null): SimVirtualMachine
/**
* Remove the specified [machine] from the hypervisor.
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
index 5f3c3b17..ab2a6d76 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimFairShareHypervisorTest.kt
@@ -191,12 +191,13 @@ internal class SimFairShareHypervisorTest {
.addGroup(targetLoad = 0.0, score = 0.6, members = setOf("a", "c"))
.addGroup(targetLoad = 0.1, score = 0.8, members = setOf("a", "n"))
.build()
+ val interferenceDomain = interferenceModel.newDomain()
val platform = FlowEngine(coroutineContext, clock)
val machine = SimBareMetalMachine(
platform, model, SimplePowerDriver(ConstantPowerModel(0.0))
)
- val hypervisor = SimFairShareHypervisor(platform, null, interferenceModel.newDomain())
+ val hypervisor = SimFairShareHypervisor(platform, null, interferenceDomain)
val duration = 5 * 60L
val workloadA =
@@ -224,11 +225,11 @@ internal class SimFairShareHypervisorTest {
coroutineScope {
launch {
- val vm = hypervisor.newMachine(model, "a")
+ val vm = hypervisor.newMachine(model, interferenceDomain.createKey("a"))
vm.runWorkload(workloadA)
hypervisor.removeMachine(vm)
}
- val vm = hypervisor.newMachine(model, "b")
+ val vm = hypervisor.newMachine(model, interferenceDomain.createKey("b"))
vm.runWorkload(workloadB)
hypervisor.removeMachine(vm)
}