summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/internal/Guest.kt65
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java15
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/ChainWorkload.java42
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java (renamed from opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java)33
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/Workload.java6
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/SimTraceWorkload.java5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/TraceWorkload.java50
8 files changed, 70 insertions, 148 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 37e26f6a..8d167322 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.simChainWorkload!!.getSnapshot() }
+ val snapshots = guests.map { it.virtualMachine!!.getSnapshot() }
val tasks = guests.map { it.task }
host.fail()
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 e2bdd960..8096a67a 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
@@ -30,10 +30,7 @@ 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.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
+import org.opendc.simulator.compute.workload.VirtualMachine
import java.time.Duration
import java.time.Instant
import java.time.InstantSource
@@ -58,9 +55,9 @@ public class Guest(
private set
/**
- * The [SimChainWorkload] on which the task is currently running
+ * The [VirtualMachine] on which the task is currently running
*/
- public var simChainWorkload: SimChainWorkload? = null
+ public var virtualMachine: VirtualMachine? = null
private var uptime = 0L
private var downtime = 0L
@@ -90,32 +87,30 @@ public class Guest(
* Launch the guest on the simulated Virtual machine
*/
private fun doStart() {
- assert(simChainWorkload == null) { "Concurrent job is already running" }
+ assert(virtualMachine == null) { "Concurrent job is already running" }
onStart()
- val scalingPolicy = NoDelayScaling()
-
// TODO: This is not being used at the moment
- val bootworkload =
- TraceWorkload(
- ArrayList(
- listOf(
- TraceFragment(
- 1000000L,
- 100000.0,
- 1,
- ),
- ),
- ),
- 0,
- 0,
- 0.0,
- scalingPolicy,
- )
+// val bootworkload =
+// TraceWorkload(s
+// ArrayList(
+// listOf(
+// TraceFragment(
+// 1000000L,
+// 100000.0,
+// 1,
+// ),
+// ),
+// ),
+// 0,
+// 0,
+// 0.0,
+// NoDelayScaling(),
+// )
if (task.workload is ChainWorkload) {
- simChainWorkload =
+ virtualMachine =
simMachine.startWorkload(task.workload as ChainWorkload) { cause ->
onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED)
}
@@ -123,12 +118,12 @@ public class Guest(
val newChainWorkload =
ChainWorkload(
ArrayList(listOf(task.workload)),
- task.workload.checkpointInterval,
- task.workload.checkpointDuration,
- task.workload.checkpointIntervalScaling,
+ task.workload.checkpointInterval(),
+ task.workload.checkpointDuration(),
+ task.workload.checkpointIntervalScaling(),
)
- simChainWorkload =
+ virtualMachine =
simMachine.startWorkload(newChainWorkload) { cause ->
onStop(if (cause != null) TaskState.FAILED else TaskState.COMPLETED)
}
@@ -160,15 +155,15 @@ public class Guest(
* Attempt to stop the task and put it into [target] state.
*/
private fun doStop(target: TaskState) {
- assert(simChainWorkload != null) { "Invalid job state" }
- val virtualMachine = this.simChainWorkload ?: return
+ assert(virtualMachine != null) { "Invalid job state" }
+ val virtualMachine = this.virtualMachine ?: return
if (target == TaskState.FAILED) {
virtualMachine.stopWorkload(Exception("Task has failed"))
} else {
virtualMachine.stopWorkload()
}
- this.simChainWorkload = null
+ this.virtualMachine = null
this.state = target
}
@@ -236,8 +231,8 @@ public class Guest(
* Obtain the CPU statistics of this guest.
*/
public fun getCpuStats(): GuestCpuStats {
- simChainWorkload!!.updateCounters(this.clock.millis())
- val counters = simChainWorkload!!.performanceCounters
+ virtualMachine!!.updateCounters(this.clock.millis())
+ val counters = virtualMachine!!.performanceCounters
return GuestCpuStats(
counters.cpuActiveTime / 1000L,
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java
index 55a5eb42..8baa7f34 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java
@@ -30,8 +30,8 @@ import org.opendc.simulator.compute.memory.Memory;
import org.opendc.simulator.compute.models.MachineModel;
import org.opendc.simulator.compute.power.SimPsu;
import org.opendc.simulator.compute.workload.ChainWorkload;
-import org.opendc.simulator.compute.workload.SimChainWorkload;
import org.opendc.simulator.compute.workload.SimWorkload;
+import org.opendc.simulator.compute.workload.VirtualMachine;
import org.opendc.simulator.engine.engine.FlowEngine;
import org.opendc.simulator.engine.graph.FlowDistributor;
import org.opendc.simulator.engine.graph.FlowEdge;
@@ -76,10 +76,6 @@ public class SimMachine {
return cpu;
}
- public FlowDistributor getCpuDistributor() {
- return cpuDistributor;
- }
-
public Memory getMemory() {
return memory;
}
@@ -180,11 +176,10 @@ public class SimMachine {
/**
* Create a Virtual Machine, and start the given workload on it.
*
- * @param workload
- * @param completion
- * @return
+ * @param workload The workload that needs to be executed
+ * @param completion The completion callback that needs to be called when the workload is done
*/
- public SimChainWorkload startWorkload(ChainWorkload workload, Consumer<Exception> completion) {
- return (SimChainWorkload) workload.startWorkload(this.cpuDistributor, this, completion);
+ public VirtualMachine startWorkload(ChainWorkload workload, Consumer<Exception> completion) {
+ return (VirtualMachine) workload.startWorkload(this.cpuDistributor, this, completion);
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/ChainWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/ChainWorkload.java
index 76a715f7..3cdde40a 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/ChainWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/ChainWorkload.java
@@ -27,38 +27,12 @@ import java.util.function.Consumer;
import org.opendc.simulator.compute.machine.SimMachine;
import org.opendc.simulator.engine.graph.FlowSupplier;
-public class ChainWorkload implements Workload {
- private ArrayList<Workload> workloads;
- private final long checkpointInterval;
- private final long checkpointDuration;
- private final double checkpointIntervalScaling;
-
- public ChainWorkload(
- ArrayList<Workload> workloads,
- long checkpointInterval,
- long checkpointDuration,
- double checkpointIntervalScaling) {
- this.workloads = workloads;
- this.checkpointInterval = checkpointInterval;
- this.checkpointDuration = checkpointDuration;
- this.checkpointIntervalScaling = checkpointIntervalScaling;
- }
-
- public ArrayList<Workload> getWorkloads() {
- return workloads;
- }
-
- public long getCheckpointInterval() {
- return checkpointInterval;
- }
-
- public long getCheckpointDuration() {
- return checkpointDuration;
- }
-
- public double getCheckpointIntervalScaling() {
- return checkpointIntervalScaling;
- }
+public record ChainWorkload(
+ ArrayList<Workload> workloads,
+ long checkpointInterval,
+ long checkpointDuration,
+ double checkpointIntervalScaling)
+ implements Workload {
public void removeWorkloads(int numberOfWorkloads) {
if (numberOfWorkloads <= 0) {
@@ -69,11 +43,11 @@ public class ChainWorkload implements Workload {
@Override
public SimWorkload startWorkload(FlowSupplier supplier) {
- return new SimChainWorkload(supplier, this);
+ return new VirtualMachine(supplier, this);
}
@Override
public SimWorkload startWorkload(FlowSupplier supplier, SimMachine machine, Consumer<Exception> completion) {
- return new SimChainWorkload(supplier, this, machine, completion);
+ return new VirtualMachine(supplier, this, machine, completion);
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java
index faab5c56..49326ba5 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java
@@ -33,16 +33,15 @@ import org.opendc.simulator.engine.graph.FlowNode;
import org.opendc.simulator.engine.graph.FlowSupplier;
/**
- * A {@link SimChainWorkload} that composes multiple {@link SimWorkload}s.
+ * A {@link VirtualMachine} that composes multiple {@link SimWorkload}s.
*/
-public final class SimChainWorkload extends SimWorkload implements FlowSupplier {
+public final class VirtualMachine extends SimWorkload implements FlowSupplier {
private final LinkedList<Workload> workloads;
private int workloadIndex;
private SimWorkload activeWorkload;
private double cpuDemand = 0.0f;
private double cpuSupply = 0.0f;
- private double cpuCapacity = 0.0f;
private double d = 0.0f;
private FlowEdge workloadEdge;
@@ -50,15 +49,15 @@ public final class SimChainWorkload extends SimWorkload implements FlowSupplier
private double capacity = 0;
- private long checkpointInterval = 0;
- private long checkpointDuration = 0;
- private double checkpointIntervalScaling = 1.0;
+ private final long checkpointInterval;
+ private final long checkpointDuration;
+ private final double checkpointIntervalScaling;
private CheckpointModel checkpointModel;
- private ChainWorkload snapshot;
+ private final ChainWorkload snapshot;
private long lastUpdate;
- private PerformanceCounters performanceCounters = new PerformanceCounters();
+ private final PerformanceCounters performanceCounters = new PerformanceCounters();
private Consumer<Exception> completion;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -98,17 +97,17 @@ public final class SimChainWorkload extends SimWorkload implements FlowSupplier
// Constructors
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- SimChainWorkload(FlowSupplier supplier, ChainWorkload workload) {
+ VirtualMachine(FlowSupplier supplier, ChainWorkload workload) {
super(((FlowNode) supplier).getEngine());
this.snapshot = workload;
new FlowEdge(this, supplier);
- this.workloads = new LinkedList<>(workload.getWorkloads());
- this.checkpointInterval = workload.getCheckpointInterval();
- this.checkpointDuration = workload.getCheckpointDuration();
- this.checkpointIntervalScaling = workload.getCheckpointIntervalScaling();
+ this.workloads = new LinkedList<>(workload.workloads());
+ this.checkpointInterval = workload.checkpointInterval();
+ this.checkpointDuration = workload.checkpointDuration();
+ this.checkpointIntervalScaling = workload.checkpointIntervalScaling();
this.lastUpdate = clock.millis();
@@ -121,8 +120,7 @@ public final class SimChainWorkload extends SimWorkload implements FlowSupplier
this.onStart();
}
- SimChainWorkload(
- FlowSupplier supplier, ChainWorkload workload, SimMachine machine, Consumer<Exception> completion) {
+ VirtualMachine(FlowSupplier supplier, ChainWorkload workload, SimMachine machine, Consumer<Exception> completion) {
this(supplier, workload);
this.capacity = machine.getCpu().getFrequency();
@@ -154,17 +152,18 @@ public final class SimChainWorkload extends SimWorkload implements FlowSupplier
this.lastUpdate = now;
long delta = now - lastUpdate;
+ double cpuCapacity = 0.0f;
if (delta > 0) {
final double factor = this.d * delta;
this.performanceCounters.addCpuActiveTime(Math.round(this.cpuSupply * factor));
- this.performanceCounters.setCpuIdleTime(Math.round((this.cpuCapacity - this.cpuSupply) * factor));
+ this.performanceCounters.setCpuIdleTime(Math.round((cpuCapacity - this.cpuSupply) * factor));
this.performanceCounters.addCpuStealTime(Math.round((this.cpuDemand - this.cpuSupply) * factor));
}
this.performanceCounters.setCpuDemand(this.cpuDemand);
this.performanceCounters.setCpuSupply(this.cpuSupply);
- this.performanceCounters.setCpuCapacity(this.cpuCapacity);
+ this.performanceCounters.setCpuCapacity(cpuCapacity);
}
@Override
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/Workload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/Workload.java
index 1d069bae..3ad7597d 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/Workload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/Workload.java
@@ -28,11 +28,11 @@ import org.opendc.simulator.engine.graph.FlowSupplier;
public interface Workload {
- long getCheckpointInterval();
+ long checkpointInterval();
- long getCheckpointDuration();
+ long checkpointDuration();
- double getCheckpointIntervalScaling();
+ double checkpointIntervalScaling();
SimWorkload startWorkload(FlowSupplier supplier);
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/SimTraceWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/SimTraceWorkload.java
index 9811f72d..457a0807 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/SimTraceWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/SimTraceWorkload.java
@@ -26,7 +26,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.opendc.simulator.compute.workload.SimWorkload;
-import org.opendc.simulator.compute.workload.trace.scaling.NoDelayScaling;
import org.opendc.simulator.compute.workload.trace.scaling.ScalingPolicy;
import org.opendc.simulator.engine.graph.FlowConsumer;
import org.opendc.simulator.engine.graph.FlowEdge;
@@ -51,7 +50,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer {
private final TraceWorkload snapshot;
- private ScalingPolicy scalingPolicy = new NoDelayScaling();
+ private final ScalingPolicy scalingPolicy;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Basic Getters and Setters
@@ -88,7 +87,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer {
super(((FlowNode) supplier).getEngine());
this.snapshot = workload;
- this.checkpointDuration = workload.getCheckpointDuration();
+ this.checkpointDuration = workload.checkpointDuration();
this.scalingPolicy = workload.getScalingPolicy();
this.remainingFragments = new LinkedList<>(workload.getFragments());
this.fragmentIndex = 0;
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/TraceWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/TraceWorkload.java
index 80687b88..4a06d019 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/TraceWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/trace/TraceWorkload.java
@@ -24,17 +24,15 @@ package org.opendc.simulator.compute.workload.trace;
import java.util.ArrayList;
import java.util.Comparator;
-import java.util.List;
import java.util.function.Consumer;
import org.opendc.simulator.compute.machine.SimMachine;
import org.opendc.simulator.compute.workload.SimWorkload;
import org.opendc.simulator.compute.workload.Workload;
-import org.opendc.simulator.compute.workload.trace.scaling.NoDelayScaling;
import org.opendc.simulator.compute.workload.trace.scaling.ScalingPolicy;
import org.opendc.simulator.engine.graph.FlowSupplier;
public class TraceWorkload implements Workload {
- private ArrayList<TraceFragment> fragments;
+ private final ArrayList<TraceFragment> fragments;
private final long checkpointInterval;
private final long checkpointDuration;
private final double checkpointIntervalScaling;
@@ -70,26 +68,22 @@ public class TraceWorkload implements Workload {
.coreCount();
}
- public TraceWorkload(ArrayList<TraceFragment> fragments) {
- this(fragments, 0L, 0L, 1.0, new NoDelayScaling());
- }
-
public ArrayList<TraceFragment> getFragments() {
return fragments;
}
@Override
- public long getCheckpointInterval() {
+ public long checkpointInterval() {
return checkpointInterval;
}
@Override
- public long getCheckpointDuration() {
+ public long checkpointDuration() {
return checkpointDuration;
}
@Override
- public double getCheckpointIntervalScaling() {
+ public double checkpointIntervalScaling() {
return checkpointIntervalScaling;
}
@@ -109,7 +103,7 @@ public class TraceWorkload implements Workload {
}
public void addFirst(TraceFragment fragment) {
- this.fragments.add(0, fragment);
+ this.fragments.addFirst(fragment);
}
@Override
@@ -122,10 +116,6 @@ public class TraceWorkload implements Workload {
return this.startWorkload(supplier);
}
- public static Builder builder() {
- return builder(0L, 0L, 0.0, new NoDelayScaling());
- }
-
public static Builder builder(
long checkpointInterval,
long checkpointDuration,
@@ -134,36 +124,6 @@ public class TraceWorkload implements Workload {
return new Builder(checkpointInterval, checkpointDuration, checkpointIntervalScaling, scalingPolicy);
}
- /**
- * Construct a {@link TraceWorkload} from the specified fragments.
- *
- * @param fragments The array of fragments to construct the trace from.
- */
- public static TraceWorkload ofFragments(TraceFragment... fragments) {
- final Builder builder = builder();
-
- for (TraceFragment fragment : fragments) {
- builder.add(fragment.duration(), fragment.cpuUsage(), fragment.coreCount());
- }
-
- return builder.build();
- }
-
- /**
- * Construct a {@link TraceWorkload} from the specified fragments.
- *
- * @param fragments The fragments to construct the trace from.
- */
- public static TraceWorkload ofFragments(List<TraceFragment> fragments) {
- final Builder builder = builder();
-
- for (TraceFragment fragment : fragments) {
- builder.add(fragment.duration(), fragment.cpuUsage(), fragment.coreCount());
- }
-
- return builder.build();
- }
-
public static final class Builder {
private final ArrayList<TraceFragment> fragments;
private final long checkpointInterval;