summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/main
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2025-03-20 15:27:47 +0100
committerGitHub <noreply@github.com>2025-03-20 15:27:47 +0100
commit29ec804965fa71d19073195248fbd2bfedd735c5 (patch)
tree2fdbdc68491a8f33bde76fe13b1cd541f428ff78 /opendc-simulator/opendc-simulator-compute/src/main
parent1e35c61cd31b8bfb33a6ccbb46b08c0466518e6c (diff)
Renamed SimChainWorkload to VirtualMachine (#320)
* Renamed SimChainWorkload.java to VirtualMachine.java * Renamed SimChainWorkload.java to VirtualMachine.java * Renamed SimChainWorkload.java to VirtualMachine.java * Renamed SimChainWorkload.java to VirtualMachine.java * Renamed SimChainWorkload.java to VirtualMachine.java
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main')
-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
6 files changed, 39 insertions, 112 deletions
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;