summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/hostfault/StartStopHostFault.kt2
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt6
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt36
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt26
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt23
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt12
6 files changed, 52 insertions, 53 deletions
diff --git a/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/hostfault/StartStopHostFault.kt b/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/hostfault/StartStopHostFault.kt
index 06fad3e6..37e26f6a 100644
--- a/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/hostfault/StartStopHostFault.kt
+++ b/opendc-compute/opendc-compute-failure/src/main/kotlin/org/opendc/compute/failure/hostfault/StartStopHostFault.kt
@@ -41,7 +41,7 @@ public class StartStopHostFault(
for (host in victims) {
val guests = host.getGuests()
- val snapshots = guests.map { it.virtualMachine!!.getActiveWorkload().getSnapshot() }
+ val snapshots = guests.map { it.simChainWorkload!!.getSnapshot() }
val tasks = guests.map { it.task }
host.fail()
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt
index 132ad227..53fafe5f 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/host/SimHost.kt
@@ -35,8 +35,8 @@ import org.opendc.simulator.compute.cpu.CpuPowerModel
import org.opendc.simulator.compute.machine.SimMachine
import org.opendc.simulator.compute.models.MachineModel
import org.opendc.simulator.compute.models.MemoryUnit
+import org.opendc.simulator.engine.engine.FlowEngine
import org.opendc.simulator.engine.graph.FlowDistributor
-import org.opendc.simulator.engine.graph.FlowGraph
import java.time.Duration
import java.time.Instant
import java.time.InstantSource
@@ -56,7 +56,7 @@ public class SimHost(
private val name: String,
private val clusterName: String,
private val clock: InstantSource,
- private val graph: FlowGraph,
+ private val engine: FlowEngine,
private val machineModel: MachineModel,
private val cpuPowerModel: CpuPowerModel,
private val powerDistributor: FlowDistributor,
@@ -126,7 +126,7 @@ public class SimHost(
this.simMachine =
SimMachine(
- this.graph,
+ this.engine,
this.machineModel,
this.powerDistributor,
this.cpuPowerModel,
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
index 83968d35..e2bdd960 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/internal/Guest.kt
@@ -29,8 +29,8 @@ import org.opendc.compute.simulator.service.ServiceTask
import org.opendc.compute.simulator.telemetry.GuestCpuStats
import org.opendc.compute.simulator.telemetry.GuestSystemStats
import org.opendc.simulator.compute.machine.SimMachine
-import org.opendc.simulator.compute.machine.VirtualMachine
import org.opendc.simulator.compute.workload.ChainWorkload
+import org.opendc.simulator.compute.workload.SimChainWorkload
import org.opendc.simulator.compute.workload.trace.TraceFragment
import org.opendc.simulator.compute.workload.trace.TraceWorkload
import org.opendc.simulator.compute.workload.trace.scaling.NoDelayScaling
@@ -58,9 +58,9 @@ public class Guest(
private set
/**
- * The [VirtualMachine] on which the task is currently running
+ * The [SimChainWorkload] on which the task is currently running
*/
- public var virtualMachine: VirtualMachine? = null
+ public var simChainWorkload: SimChainWorkload? = null
private var uptime = 0L
private var downtime = 0L
@@ -90,7 +90,7 @@ public class Guest(
* Launch the guest on the simulated Virtual machine
*/
private fun doStart() {
- assert(virtualMachine == null) { "Concurrent job is already running" }
+ assert(simChainWorkload == null) { "Concurrent job is already running" }
onStart()
@@ -114,7 +114,12 @@ public class Guest(
scalingPolicy,
)
- if (task.workload is TraceWorkload) {
+ if (task.workload is ChainWorkload) {
+ simChainWorkload =
+ simMachine.startWorkload(task.workload as ChainWorkload) { cause ->
+ onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED)
+ }
+ } else {
val newChainWorkload =
ChainWorkload(
ArrayList(listOf(task.workload)),
@@ -123,15 +128,10 @@ public class Guest(
task.workload.checkpointIntervalScaling,
)
- virtualMachine =
+ simChainWorkload =
simMachine.startWorkload(newChainWorkload) { cause ->
onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED)
}
- } else {
- virtualMachine =
- simMachine.startWorkload(task.workload) { cause ->
- onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED)
- }
}
}
@@ -160,15 +160,15 @@ public class Guest(
* Attempt to stop the task and put it into [target] state.
*/
private fun doStop(target: TaskState) {
- assert(virtualMachine != null) { "Invalid job state" }
- val virtualMachine = this.virtualMachine ?: return
+ assert(simChainWorkload != null) { "Invalid job state" }
+ val virtualMachine = this.simChainWorkload ?: return
if (target == TaskState.FAILED) {
- virtualMachine.shutdown(Exception("Task has failed"))
+ virtualMachine.stopWorkload(Exception("Task has failed"))
} else {
- virtualMachine.shutdown()
+ virtualMachine.stopWorkload()
}
- this.virtualMachine = null
+ this.simChainWorkload = null
this.state = target
}
@@ -236,8 +236,8 @@ public class Guest(
* Obtain the CPU statistics of this guest.
*/
public fun getCpuStats(): GuestCpuStats {
- virtualMachine!!.updateCounters(this.clock.millis())
- val counters = virtualMachine!!.performanceCounters
+ simChainWorkload!!.updateCounters(this.clock.millis())
+ val counters = simChainWorkload!!.performanceCounters
return GuestCpuStats(
counters.cpuActiveTime / 1000L,
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
index 211f33fe..68e263f8 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
@@ -34,6 +34,7 @@ import org.opendc.simulator.compute.power.batteries.BatteryAggregator
import org.opendc.simulator.compute.power.batteries.SimBattery
import org.opendc.simulator.engine.engine.FlowEngine
import org.opendc.simulator.engine.graph.FlowDistributor
+import org.opendc.simulator.engine.graph.FlowEdge
/**
* A [ProvisioningStep] that provisions a list of hosts for a [ComputeService].
@@ -56,36 +57,35 @@ public class HostsProvisioningStep internal constructor(
val simPowerSources = mutableListOf<SimPowerSource>()
val engine = FlowEngine.create(ctx.dispatcher)
- val graph = engine.newGraph()
for (cluster in clusterSpecs) {
// Create the Power Source to which hosts are connected
// Create Power Source
- val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), cluster.powerSource.name, cluster.name)
+ val simPowerSource = SimPowerSource(engine, cluster.powerSource.totalPower.toDouble(), cluster.powerSource.name, cluster.name)
simPowerSources.add(simPowerSource)
service.addPowerSource(simPowerSource)
- val hostDistributor = FlowDistributor(graph)
+ val hostDistributor = FlowDistributor(engine)
val carbonFragments = getCarbonFragments(cluster.powerSource.carbonTracePath)
var carbonModel: CarbonModel? = null
// Create Carbon Model
if (carbonFragments != null) {
- carbonModel = CarbonModel(graph, carbonFragments, startTime)
+ carbonModel = CarbonModel(engine, carbonFragments, startTime)
carbonModel.addReceiver(simPowerSource)
}
if (cluster.battery != null) {
// Create Battery Distributor
- val batteryDistributor = FlowDistributor(graph)
- graph.addEdge(batteryDistributor, simPowerSource)
+ val batteryDistributor = FlowDistributor(engine)
+ FlowEdge(batteryDistributor, simPowerSource)
// Create Battery
val battery =
SimBattery(
- graph,
+ engine,
cluster.battery!!.capacity,
cluster.battery!!.chargingSpeed,
cluster.battery!!.initialCharge,
@@ -94,26 +94,26 @@ public class HostsProvisioningStep internal constructor(
cluster.battery!!.embodiedCarbon,
cluster.battery!!.expectedLifetime,
)
- graph.addEdge(battery, batteryDistributor)
+ FlowEdge(battery, batteryDistributor)
// Create Aggregator
- val batteryAggregator = BatteryAggregator(graph, battery, batteryDistributor)
+ val batteryAggregator = BatteryAggregator(engine, battery, batteryDistributor)
val batteryPolicy =
createSimBatteryPolicy(
cluster.battery!!.batteryPolicy,
- graph,
+ engine,
battery,
batteryAggregator,
)
carbonModel?.addReceiver(batteryPolicy)
- graph.addEdge(hostDistributor, batteryAggregator)
+ FlowEdge(hostDistributor, batteryAggregator)
service.addBattery(battery)
} else {
- graph.addEdge(hostDistributor, simPowerSource)
+ FlowEdge(hostDistributor, simPowerSource)
}
// Create hosts, they are connected to the powerMux when SimMachine is created
@@ -123,7 +123,7 @@ public class HostsProvisioningStep internal constructor(
hostSpec.name,
cluster.name,
ctx.dispatcher.timeSource,
- graph,
+ engine,
hostSpec.model,
hostSpec.cpuPowerModel,
hostDistributor,
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
index a20bc2c2..cc2c4b4e 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt
@@ -44,10 +44,10 @@ import java.io.InputStream
private val reader = TopologyReader()
// Lists used to make sure all cluster, host, power source and battery have unique names
-private val clusterNames: ArrayList<String> = ArrayList()
-private val hostNames: ArrayList<String> = ArrayList()
-private val powerSourceNames: ArrayList<String> = ArrayList()
-private val batteryNames: ArrayList<String> = ArrayList()
+private val clusterNames: HashMap<String, Int> = HashMap()
+private val hostNames: HashMap<String, Int> = HashMap()
+private val powerSourceNames: HashMap<String, Int> = HashMap()
+private val batteryNames: HashMap<String, Int> = HashMap()
/**
* Create a unique name for the specified [name] that is not already in the [names] list.
@@ -57,20 +57,19 @@ private val batteryNames: ArrayList<String> = ArrayList()
*/
private fun createUniqueName(
name: String,
- names: ArrayList<String>,
+ names: MutableMap<String, Int>,
): String {
if (name !in names) {
- names.add(name)
+ names[name] = 0
return name
}
- var i = 0
- var newName = "$name-$i"
- while (newName in names) {
- newName = "$name-${++i}"
- }
+ val latestValue = names[name]
+
+ val newName = "$name-$latestValue"
+
+ names[name] = latestValue!! + 1
- names.add(newName)
return newName
}
diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
index 3d8b63dc..920d8373 100644
--- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
+++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt
@@ -34,7 +34,7 @@ import org.opendc.simulator.compute.power.batteries.policy.DoubleThresholdBatter
import org.opendc.simulator.compute.power.batteries.policy.RunningMeanBatteryPolicy
import org.opendc.simulator.compute.power.batteries.policy.RunningMeanPlusBatteryPolicy
import org.opendc.simulator.compute.power.batteries.policy.SingleThresholdBatteryPolicy
-import org.opendc.simulator.engine.graph.FlowGraph
+import org.opendc.simulator.engine.engine.FlowEngine
/**
* Definition of a Topology modeled in the simulation.
@@ -236,21 +236,21 @@ public data class RunningQuartilesPolicyJSONSpec(
public fun createSimBatteryPolicy(
batterySpec: BatteryPolicyJSONSpec,
- graph: FlowGraph,
+ engine: FlowEngine,
battery: SimBattery,
batteryAggregator: BatteryAggregator,
): BatteryPolicy {
return when (batterySpec) {
is SingleBatteryPolicyJSONSpec ->
SingleThresholdBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.carbonThreshold,
)
is DoubleBatteryPolicyJSONSpec ->
DoubleThresholdBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.lowerThreshold,
@@ -258,7 +258,7 @@ public fun createSimBatteryPolicy(
)
is RunningMeanPolicyJSONSpec ->
RunningMeanBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.startingThreshold,
@@ -266,7 +266,7 @@ public fun createSimBatteryPolicy(
)
is RunningMeanPlusPolicyJSONSpec ->
RunningMeanPlusBatteryPolicy(
- graph,
+ engine,
battery,
batteryAggregator,
batterySpec.startingThreshold,