From 29ec804965fa71d19073195248fbd2bfedd735c5 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Thu, 20 Mar 2025 15:27:47 +0100 Subject: 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 --- .../simulator/compute/machine/SimMachine.java | 15 +- .../simulator/compute/workload/ChainWorkload.java | 42 +-- .../compute/workload/SimChainWorkload.java | 350 --------------------- .../simulator/compute/workload/VirtualMachine.java | 349 ++++++++++++++++++++ .../simulator/compute/workload/Workload.java | 6 +- .../compute/workload/trace/SimTraceWorkload.java | 5 +- .../compute/workload/trace/TraceWorkload.java | 50 +-- 7 files changed, 372 insertions(+), 445 deletions(-) delete mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java (limited to 'opendc-simulator/opendc-simulator-compute/src') 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 completion) { - return (SimChainWorkload) workload.startWorkload(this.cpuDistributor, this, completion); + public VirtualMachine startWorkload(ChainWorkload workload, Consumer 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 workloads; - private final long checkpointInterval; - private final long checkpointDuration; - private final double checkpointIntervalScaling; - - public ChainWorkload( - ArrayList workloads, - long checkpointInterval, - long checkpointDuration, - double checkpointIntervalScaling) { - this.workloads = workloads; - this.checkpointInterval = checkpointInterval; - this.checkpointDuration = checkpointDuration; - this.checkpointIntervalScaling = checkpointIntervalScaling; - } - - public ArrayList getWorkloads() { - return workloads; - } - - public long getCheckpointInterval() { - return checkpointInterval; - } - - public long getCheckpointDuration() { - return checkpointDuration; - } - - public double getCheckpointIntervalScaling() { - return checkpointIntervalScaling; - } +public record ChainWorkload( + ArrayList 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 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/SimChainWorkload.java deleted file mode 100644 index faab5c56..00000000 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2022 AtLarge Research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.opendc.simulator.compute.workload; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import org.opendc.simulator.compute.machine.PerformanceCounters; -import org.opendc.simulator.compute.machine.SimMachine; -import org.opendc.simulator.engine.graph.FlowEdge; -import org.opendc.simulator.engine.graph.FlowNode; -import org.opendc.simulator.engine.graph.FlowSupplier; - -/** - * A {@link SimChainWorkload} that composes multiple {@link SimWorkload}s. - */ -public final class SimChainWorkload extends SimWorkload implements FlowSupplier { - private final LinkedList 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; - private FlowEdge machineEdge; - - private double capacity = 0; - - private long checkpointInterval = 0; - private long checkpointDuration = 0; - private double checkpointIntervalScaling = 1.0; - private CheckpointModel checkpointModel; - - private ChainWorkload snapshot; - - private long lastUpdate; - private PerformanceCounters performanceCounters = new PerformanceCounters(); - private Consumer completion; - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Basic Getters and Setters - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public double getCapacity() { - return this.capacity; - } - - @Override - public ChainWorkload getSnapshot() { - return this.snapshot; - } - - @Override - public long getCheckpointInterval() { - return checkpointInterval; - } - - @Override - public long getCheckpointDuration() { - return checkpointDuration; - } - - @Override - public double getCheckpointIntervalScaling() { - return checkpointIntervalScaling; - } - - public PerformanceCounters getPerformanceCounters() { - return performanceCounters; - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Constructors - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - SimChainWorkload(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.lastUpdate = clock.millis(); - - if (checkpointInterval > 0) { - this.createCheckpointModel(); - } - - this.workloadIndex = -1; - - this.onStart(); - } - - SimChainWorkload( - FlowSupplier supplier, ChainWorkload workload, SimMachine machine, Consumer completion) { - this(supplier, workload); - - this.capacity = machine.getCpu().getFrequency(); - this.d = 1 / machine.getCpu().getFrequency(); - this.completion = completion; - } - - public Workload getNextWorkload() { - this.workloadIndex++; - return workloads.pop(); - } - - // TODO: Combine with Constructor - public void onStart() { - if (this.workloads.isEmpty()) { - return; - } - - // Create and start a checkpoint model if initiated - if (checkpointInterval > 0) { - this.checkpointModel.start(); - } - - this.activeWorkload = this.getNextWorkload().startWorkload(this); - } - - public void updateCounters(long now) { - long lastUpdate = this.lastUpdate; - this.lastUpdate = now; - long delta = now - lastUpdate; - - 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.addCpuStealTime(Math.round((this.cpuDemand - this.cpuSupply) * factor)); - } - - this.performanceCounters.setCpuDemand(this.cpuDemand); - this.performanceCounters.setCpuSupply(this.cpuSupply); - this.performanceCounters.setCpuCapacity(this.cpuCapacity); - } - - @Override - public long onUpdate(long now) { - return Long.MAX_VALUE; - } - - @Override - public void stopWorkload() { - this.stopWorkload(null); - } - - private Exception stopWorkloadCause = null; - - public void stopWorkload(Exception cause) { - if (cause != null) { - this.stopWorkloadCause = cause; - } - - if (this.checkpointModel != null) { - this.checkpointModel.close(); - this.checkpointModel = null; - } - - if (this.activeWorkload != null) { - this.activeWorkload.stopWorkload(); - this.activeWorkload = null; - } - - this.closeNode(); - - if (this.completion != null) { - this.completion.accept(stopWorkloadCause); - this.completion = null; - } - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Checkpoint related functionality - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void createCheckpointModel() { - this.checkpointModel = new CheckpointModel(this); - } - - @Override - public void makeSnapshot(long now) { - - this.snapshot.removeWorkloads(this.workloadIndex); - this.workloadIndex = 0; - - activeWorkload.makeSnapshot(now); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // FlowGraph Related functionality - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - /** - * Add connection to the active workload - * - * @param consumerEdge The edge to the workload - */ - @Override - public void addConsumerEdge(FlowEdge consumerEdge) { - this.workloadEdge = consumerEdge; - } - - /** - * Add Connection to the cpuMux - * - * @param supplierEdge The edge to the cpuMux - */ - @Override - public void addSupplierEdge(FlowEdge supplierEdge) { - this.machineEdge = supplierEdge; - this.capacity = supplierEdge.getCapacity(); - } - - /** - * Push demand to the cpuMux - * - * @param supplierEdge The edge to the cpuMux - * @param newDemand new demand to sent to the cpu - */ - @Override - public void pushOutgoingDemand(FlowEdge supplierEdge, double newDemand) { - - this.cpuDemand = newDemand; - this.machineEdge.pushDemand(newDemand); - } - - /** - * Push supply to the workload - * - * @param consumerEdge The edge to the cpuMux - * @param newSupply new supply to sent to the workload - */ - @Override - public void pushOutgoingSupply(FlowEdge consumerEdge, double newSupply) { - - this.cpuSupply = newSupply; - this.workloadEdge.pushSupply(newSupply); - } - - /** - * Handle new demand coming from the workload - * - * @param consumerEdge The edge to the workload - * @param newDemand new demand coming from the workload - */ - @Override - public void handleIncomingDemand(FlowEdge consumerEdge, double newDemand) { - updateCounters(this.clock.millis()); - - this.pushOutgoingDemand(this.machineEdge, newDemand); - } - - /** - * Handle new supply coming from the cpuMux - * - * @param supplierEdge The edge to the cpuMux - * @param newSupply The new supply that is sent to the workload - */ - @Override - public void handleIncomingSupply(FlowEdge supplierEdge, double newSupply) { - updateCounters(this.clock.millis()); - - this.pushOutgoingSupply(this.machineEdge, newSupply); - } - - /** - * Handle the removal of the workload. - * If there is a next workload available, start this workload - * Otherwise, close this SimChainWorkload - * - * @param consumerEdge The edge to the active workload - */ - @Override - public void removeConsumerEdge(FlowEdge consumerEdge) { - if (this.workloadEdge == null) { - return; - } - - // Remove the connection to the active workload - this.activeWorkload = null; - this.workloadEdge = null; - - // Start next workload - if (!this.workloads.isEmpty()) { - this.activeWorkload = getNextWorkload().startWorkload(this); - return; - } - - this.stopWorkload(); - } - - /** - * Handle the removal of the connection to the cpuMux - * When this happens, close the SimChainWorkload - * - * @param supplierEdge The edge to the cpuMux - */ - @Override - public void removeSupplierEdge(FlowEdge supplierEdge) { - if (this.machineEdge == null) { - return; - } - - this.stopWorkload(); - } - - @Override - public Map> getConnectedEdges() { - List consumerEdges = (this.machineEdge != null) ? List.of(this.machineEdge) : List.of(); - List supplierEdges = (this.workloadEdge != null) ? List.of(this.workloadEdge) : List.of(); - - return Map.of( - FlowEdge.NodeType.CONSUMING, consumerEdges, - FlowEdge.NodeType.SUPPLYING, supplierEdges); - } -} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java new file mode 100644 index 00000000..49326ba5 --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/VirtualMachine.java @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2022 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.simulator.compute.workload; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import org.opendc.simulator.compute.machine.PerformanceCounters; +import org.opendc.simulator.compute.machine.SimMachine; +import org.opendc.simulator.engine.graph.FlowEdge; +import org.opendc.simulator.engine.graph.FlowNode; +import org.opendc.simulator.engine.graph.FlowSupplier; + +/** + * A {@link VirtualMachine} that composes multiple {@link SimWorkload}s. + */ +public final class VirtualMachine extends SimWorkload implements FlowSupplier { + private final LinkedList workloads; + private int workloadIndex; + + private SimWorkload activeWorkload; + private double cpuDemand = 0.0f; + private double cpuSupply = 0.0f; + private double d = 0.0f; + + private FlowEdge workloadEdge; + private FlowEdge machineEdge; + + private double capacity = 0; + + private final long checkpointInterval; + private final long checkpointDuration; + private final double checkpointIntervalScaling; + private CheckpointModel checkpointModel; + + private final ChainWorkload snapshot; + + private long lastUpdate; + private final PerformanceCounters performanceCounters = new PerformanceCounters(); + private Consumer completion; + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Basic Getters and Setters + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public double getCapacity() { + return this.capacity; + } + + @Override + public ChainWorkload getSnapshot() { + return this.snapshot; + } + + @Override + public long getCheckpointInterval() { + return checkpointInterval; + } + + @Override + public long getCheckpointDuration() { + return checkpointDuration; + } + + @Override + public double getCheckpointIntervalScaling() { + return checkpointIntervalScaling; + } + + public PerformanceCounters getPerformanceCounters() { + return performanceCounters; + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Constructors + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + VirtualMachine(FlowSupplier supplier, ChainWorkload workload) { + super(((FlowNode) supplier).getEngine()); + + this.snapshot = workload; + + new FlowEdge(this, supplier); + + this.workloads = new LinkedList<>(workload.workloads()); + this.checkpointInterval = workload.checkpointInterval(); + this.checkpointDuration = workload.checkpointDuration(); + this.checkpointIntervalScaling = workload.checkpointIntervalScaling(); + + this.lastUpdate = clock.millis(); + + if (checkpointInterval > 0) { + this.createCheckpointModel(); + } + + this.workloadIndex = -1; + + this.onStart(); + } + + VirtualMachine(FlowSupplier supplier, ChainWorkload workload, SimMachine machine, Consumer completion) { + this(supplier, workload); + + this.capacity = machine.getCpu().getFrequency(); + this.d = 1 / machine.getCpu().getFrequency(); + this.completion = completion; + } + + public Workload getNextWorkload() { + this.workloadIndex++; + return workloads.pop(); + } + + // TODO: Combine with Constructor + public void onStart() { + if (this.workloads.isEmpty()) { + return; + } + + // Create and start a checkpoint model if initiated + if (checkpointInterval > 0) { + this.checkpointModel.start(); + } + + this.activeWorkload = this.getNextWorkload().startWorkload(this); + } + + public void updateCounters(long now) { + long lastUpdate = this.lastUpdate; + 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((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(cpuCapacity); + } + + @Override + public long onUpdate(long now) { + return Long.MAX_VALUE; + } + + @Override + public void stopWorkload() { + this.stopWorkload(null); + } + + private Exception stopWorkloadCause = null; + + public void stopWorkload(Exception cause) { + if (cause != null) { + this.stopWorkloadCause = cause; + } + + if (this.checkpointModel != null) { + this.checkpointModel.close(); + this.checkpointModel = null; + } + + if (this.activeWorkload != null) { + this.activeWorkload.stopWorkload(); + this.activeWorkload = null; + } + + this.closeNode(); + + if (this.completion != null) { + this.completion.accept(stopWorkloadCause); + this.completion = null; + } + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Checkpoint related functionality + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void createCheckpointModel() { + this.checkpointModel = new CheckpointModel(this); + } + + @Override + public void makeSnapshot(long now) { + + this.snapshot.removeWorkloads(this.workloadIndex); + this.workloadIndex = 0; + + activeWorkload.makeSnapshot(now); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // FlowGraph Related functionality + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Add connection to the active workload + * + * @param consumerEdge The edge to the workload + */ + @Override + public void addConsumerEdge(FlowEdge consumerEdge) { + this.workloadEdge = consumerEdge; + } + + /** + * Add Connection to the cpuMux + * + * @param supplierEdge The edge to the cpuMux + */ + @Override + public void addSupplierEdge(FlowEdge supplierEdge) { + this.machineEdge = supplierEdge; + this.capacity = supplierEdge.getCapacity(); + } + + /** + * Push demand to the cpuMux + * + * @param supplierEdge The edge to the cpuMux + * @param newDemand new demand to sent to the cpu + */ + @Override + public void pushOutgoingDemand(FlowEdge supplierEdge, double newDemand) { + + this.cpuDemand = newDemand; + this.machineEdge.pushDemand(newDemand); + } + + /** + * Push supply to the workload + * + * @param consumerEdge The edge to the cpuMux + * @param newSupply new supply to sent to the workload + */ + @Override + public void pushOutgoingSupply(FlowEdge consumerEdge, double newSupply) { + + this.cpuSupply = newSupply; + this.workloadEdge.pushSupply(newSupply); + } + + /** + * Handle new demand coming from the workload + * + * @param consumerEdge The edge to the workload + * @param newDemand new demand coming from the workload + */ + @Override + public void handleIncomingDemand(FlowEdge consumerEdge, double newDemand) { + updateCounters(this.clock.millis()); + + this.pushOutgoingDemand(this.machineEdge, newDemand); + } + + /** + * Handle new supply coming from the cpuMux + * + * @param supplierEdge The edge to the cpuMux + * @param newSupply The new supply that is sent to the workload + */ + @Override + public void handleIncomingSupply(FlowEdge supplierEdge, double newSupply) { + updateCounters(this.clock.millis()); + + this.pushOutgoingSupply(this.machineEdge, newSupply); + } + + /** + * Handle the removal of the workload. + * If there is a next workload available, start this workload + * Otherwise, close this SimChainWorkload + * + * @param consumerEdge The edge to the active workload + */ + @Override + public void removeConsumerEdge(FlowEdge consumerEdge) { + if (this.workloadEdge == null) { + return; + } + + // Remove the connection to the active workload + this.activeWorkload = null; + this.workloadEdge = null; + + // Start next workload + if (!this.workloads.isEmpty()) { + this.activeWorkload = getNextWorkload().startWorkload(this); + return; + } + + this.stopWorkload(); + } + + /** + * Handle the removal of the connection to the cpuMux + * When this happens, close the SimChainWorkload + * + * @param supplierEdge The edge to the cpuMux + */ + @Override + public void removeSupplierEdge(FlowEdge supplierEdge) { + if (this.machineEdge == null) { + return; + } + + this.stopWorkload(); + } + + @Override + public Map> getConnectedEdges() { + List consumerEdges = (this.machineEdge != null) ? List.of(this.machineEdge) : List.of(); + List supplierEdges = (this.workloadEdge != null) ? List.of(this.workloadEdge) : List.of(); + + return Map.of( + FlowEdge.NodeType.CONSUMING, consumerEdges, + FlowEdge.NodeType.SUPPLYING, supplierEdges); + } +} 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 fragments; + private final ArrayList 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 fragments) { - this(fragments, 0L, 0L, 1.0, new NoDelayScaling()); - } - public ArrayList 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 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 fragments; private final long checkpointInterval; -- cgit v1.2.3