From 089c449762950b4322c04f73ef7fe0e10af615df Mon Sep 17 00:00:00 2001 From: Niels Thiele Date: Tue, 15 Jul 2025 16:59:02 +0200 Subject: Implements Virtualization overhead modelling (#357) --- .../org/opendc/simulator/compute/gpu/SimGpu.java | 42 +++++++++-- .../simulator/compute/machine/SimMachine.java | 3 +- .../opendc/simulator/compute/models/GpuModel.java | 31 +++++++- .../ConstantVirtualizationOverhead.java | 54 +++++++++++++ .../OverheadModels/NoVirtualizationOverHead.java | 36 +++++++++ .../ShareBasedVirtualizationOverhead.java | 38 ++++++++++ .../VirtualizationOverheadModel.java | 33 ++++++++ .../VirtualizationOverheadModelFactory.java | 88 ++++++++++++++++++++++ .../simulator/engine/graph/FlowDistributor.java | 4 +- .../opendc/simulator/engine/graph/FlowEdge.java | 10 +++ .../simulator/engine/graph/FlowSupplier.java | 6 ++ 11 files changed, 332 insertions(+), 13 deletions(-) create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ConstantVirtualizationOverhead.java create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/NoVirtualizationOverHead.java create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ShareBasedVirtualizationOverhead.java create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModel.java create mode 100644 opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModelFactory.java (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/gpu/SimGpu.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/gpu/SimGpu.java index c5778dc0..99317a08 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/gpu/SimGpu.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/gpu/SimGpu.java @@ -29,6 +29,7 @@ import org.opendc.simulator.compute.ComputeResource; import org.opendc.simulator.compute.machine.PerformanceCounters; import org.opendc.simulator.compute.models.GpuModel; import org.opendc.simulator.compute.power.PowerModel; +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModel; import org.opendc.simulator.engine.engine.FlowEngine; import org.opendc.simulator.engine.graph.FlowConsumer; import org.opendc.simulator.engine.graph.FlowEdge; @@ -47,12 +48,12 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer private final PowerModel gpuPowerModel; - private double currentGpuDemand = 0.0f; // cpu capacity demanded by the mux + private double currentGpuDemand = 0.0f; // gpu capacity demanded by the mux private double currentGpuUtilization = 0.0f; - private double currentGpuSupplied = 0.0f; // cpu capacity supplied to the mux + private double currentGpuSupplied = 0.0f; // gpu capacity supplied to the mux private double currentPowerDemand; // power demanded of the psu - private double currentPowerSupplied = 0.0f; // cpu capacity supplied by the psu + private double currentPowerSupplied = 0.0f; // gpu capacity supplied by the psu private double maxCapacity; @@ -60,6 +61,9 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer private long lastCounterUpdate; private final double gpuFrequencyInv; + private final VirtualizationOverheadModel virtualizationOverheadModel; + private int consumerCount = 0; // Number of consumers connected to this GPU + private FlowEdge distributorEdge; private FlowEdge psuEdge; @@ -110,7 +114,12 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer // Constructors //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public SimGpu(FlowEngine engine, GpuModel gpuModel, PowerModel powerModel, int id) { + public SimGpu( + FlowEngine engine, + GpuModel gpuModel, + PowerModel powerModel, + int id, + VirtualizationOverheadModel overheadModel) { super(engine); this.id = id; this.gpuModel = gpuModel; @@ -123,6 +132,7 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer this.gpuFrequencyInv = 1 / this.maxCapacity; this.currentPowerDemand = this.gpuPowerModel.computePower(this.currentGpuUtilization); + this.virtualizationOverheadModel = overheadModel; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -139,8 +149,8 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer return Long.MAX_VALUE; } - - this.currentGpuSupplied = Math.min(this.currentGpuDemand, this.maxCapacity); + this.currentGpuSupplied = virtualizationOverheadModel.getSupply( + Math.min(this.currentGpuDemand, this.maxCapacity), this.consumerCount); this.pushOutgoingSupply(this.distributorEdge, this.currentGpuSupplied); return Long.MAX_VALUE; @@ -213,13 +223,31 @@ public final class SimGpu extends FlowNode implements FlowSupplier, FlowConsumer this.distributorEdge.pushSupply(newGpuSupply, true, resourceType); } + @Override + public void handleIncomingDemand(FlowEdge consumerEdge, double newGpuDemand) { + updateCounters(); + this.currentGpuDemand = newGpuDemand; + + this.currentGpuUtilization = Math.min(this.currentGpuDemand / this.maxCapacity, 1.0); + + // Calculate Power Demand and send to PSU + this.currentPowerDemand = this.gpuPowerModel.computePower(this.currentGpuUtilization); + + this.invalidate(); + } + /** * Handle new demand coming in from the mux */ @Override - public void handleIncomingDemand(FlowEdge consumerEdge, double newGpuDemand) { + public void handleIncomingDemand( + FlowEdge consumerEdge, double newGpuDemand, ResourceType resourceType, int consumerCount) { + if (resourceType != ResourceType.GPU) { + throw new IllegalArgumentException("Resource type must be GPU"); + } updateCounters(); this.currentGpuDemand = newGpuDemand; + this.consumerCount = consumerCount; this.currentGpuUtilization = Math.min(this.currentGpuDemand / this.maxCapacity, 1.0); 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 5f4a4fcd..7158356a 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 @@ -242,7 +242,8 @@ public class SimMachine { for (GpuModel gpuModel : machineModel.getGpuModels()) { // create a new GPU - SimGpu gpu = new SimGpu(engine, gpuModel, gpuPowerModel, gpuModel.getId()); + SimGpu gpu = new SimGpu( + engine, gpuModel, gpuPowerModel, gpuModel.getId(), gpuModel.getVirtualizationOverheadModel()); gpus.add(gpu); // Connect the GPU to the distributor new FlowEdge( diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/GpuModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/GpuModel.java index b804b061..e62c93da 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/GpuModel.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/GpuModel.java @@ -23,6 +23,9 @@ package org.opendc.simulator.compute.models; import java.util.Objects; +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModel; +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModelFactory; +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModelFactory.VirtualizationOverheadModelEnum; /** * A single logical compute unit of processor node, either virtual or physical. @@ -37,6 +40,7 @@ public final class GpuModel { private final String vendor; private final String modelName; private final String arch; + private VirtualizationOverheadModel virtualizationOverheadModel; /** * Construct a {@link GpuModel} instance. @@ -49,6 +53,7 @@ public final class GpuModel { * @param vendor The vendor of the GPU * @param modelName The name of the GPU * @param arch The architecture of the GPU + * @param virtualizationOverheadModel The virtualization overhead model of this GPU. */ public GpuModel( int id, @@ -58,7 +63,8 @@ public final class GpuModel { long memorySize, String vendor, String modelName, - String arch) { + String arch, + VirtualizationOverheadModelEnum virtualizationOverheadModel) { this.id = id; this.coreCount = coreCount; this.coreSpeed = coreSpeed; @@ -68,6 +74,8 @@ public final class GpuModel { this.vendor = vendor; this.modelName = modelName; this.arch = arch; + this.virtualizationOverheadModel = + VirtualizationOverheadModelFactory.getVirtualizationOverheadModel(virtualizationOverheadModel); } /** @@ -78,11 +86,20 @@ public final class GpuModel { * @param coreSpeed The speed of a single core */ public GpuModel(int id, int coreCount, double coreSpeed) { - this(id, coreCount, coreSpeed, 0, 0, "unkown", "unkown", "unkown"); + this(id, coreCount, coreSpeed, 0, 0, "unkown", "unkown", "unkown", VirtualizationOverheadModelEnum.NONE); } public GpuModel(int id, int coreCount, double coreSpeed, double memoryBandwidth, long memorySize) { - this(id, coreCount, coreSpeed, memoryBandwidth, memorySize, "unkown", "unkown", "unkown"); + this( + id, + coreCount, + coreSpeed, + memoryBandwidth, + memorySize, + "unkown", + "unkown", + "unkown", + VirtualizationOverheadModelEnum.NONE); } /** @@ -148,6 +165,14 @@ public final class GpuModel { return arch; } + /** + * Return the virtualization overhead model of this GPU. + * @return The virtualization overhead model of this GPU. + */ + public VirtualizationOverheadModel getVirtualizationOverheadModel() { + return this.virtualizationOverheadModel; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ConstantVirtualizationOverhead.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ConstantVirtualizationOverhead.java new file mode 100644 index 00000000..e30133a5 --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ConstantVirtualizationOverhead.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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.virtualization.OverheadModels; + +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModel; + +/** + * A VirtualizationOverheadModel that applies a constant percentage overhead to the current GPU demand. + * This model is useful for scenarios where a fixed overhead is expected regardless of the number of consumers. + */ +public class ConstantVirtualizationOverhead implements VirtualizationOverheadModel { + + private double percentageOverhead = 0.0; + + public double getPercentageOverhead() { + return percentageOverhead; + } + + /** + * Creates a new instance of ConstantVirtualizationOverhead with the specified percentage overhead. + * + * @param percentageOverhead The percentage overhead to apply to the current GPU demand. + * If set to -1.0, a default value of 0.05 (5%) is used. + */ + public ConstantVirtualizationOverhead(double percentageOverhead) { + + this.percentageOverhead = (percentageOverhead == -1.0) ? 0.05 : percentageOverhead; + } + + @Override + public double getSupply(double currentGpuDemand, int consumerCount) { + return currentGpuDemand * (1 - percentageOverhead); + } +} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/NoVirtualizationOverHead.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/NoVirtualizationOverHead.java new file mode 100644 index 00000000..114962ef --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/NoVirtualizationOverHead.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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.virtualization.OverheadModels; + +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModel; + +/** + * A VirtualizationOverheadModel that does not introduce any overhead. + * It simply returns the current GPU demand as the supply. + */ +public class NoVirtualizationOverHead implements VirtualizationOverheadModel { + @Override + public double getSupply(double currentGpuDemand, int consumerCount) { + return currentGpuDemand; // No overhead, so supply is equal to demand + } +} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ShareBasedVirtualizationOverhead.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ShareBasedVirtualizationOverhead.java new file mode 100644 index 00000000..e1562c38 --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/OverheadModels/ShareBasedVirtualizationOverhead.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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.virtualization.OverheadModels; + +import org.opendc.simulator.compute.virtualization.VirtualizationOverheadModel; + +/** + * A VirtualizationOverheadModel that divides the current GPU demand by the number of consumers. + * This model assumes that the supply is shared among all consumers, effectively reducing the + * supply available to each consumer based on the number of consumers. + */ +public class ShareBasedVirtualizationOverhead implements VirtualizationOverheadModel { + @Override + public double getSupply(double currentGpuDemand, int consumerCount) { + // Supply is divided by the number of consumers to account for sharing + return currentGpuDemand / (consumerCount == 0 ? 1 : consumerCount); + } +} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModel.java new file mode 100644 index 00000000..149780f8 --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModel.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 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.virtualization; + +/** + * An interface for modeling the overhead introduced by virtualization in a compute environment. + * This model is used to determine the effective supply of resources available to consumers based + * on the current demand and the number of consumers. + */ +public interface VirtualizationOverheadModel { + + public double getSupply(double currentGpuDemand, int consumerCount); +} diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModelFactory.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModelFactory.java new file mode 100644 index 00000000..8eee2b01 --- /dev/null +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/virtualization/VirtualizationOverheadModelFactory.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2025 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.virtualization; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.opendc.simulator.compute.virtualization.OverheadModels.ConstantVirtualizationOverhead; +import org.opendc.simulator.compute.virtualization.OverheadModels.NoVirtualizationOverHead; +import org.opendc.simulator.compute.virtualization.OverheadModels.ShareBasedVirtualizationOverhead; + +/** + * A factory class for creating instances of VirtualizationOverheadModel based on the specified type. + * This factory supports different virtualization overhead models, including no overhead, constant overhead, + * and share-based overhead. + */ +public class VirtualizationOverheadModelFactory { + + public enum VirtualizationOverheadModelEnum { + NONE, + // General virtualization models -> Passthrough vs Full/Para virtualization + CONSTANT, + // Hardware assisted virtualization models + SHARE_BASED; + + private final Map properties = new HashMap<>(); + + public void setProperty(String key, Object value) { + properties.put(key, value); + } + + public Object getProperty(String key) { + return properties.get(key); + } + + public T getProperty(String key, Class type) { + return type.cast(properties.get(key)); + } + + public Set getPropertyNames() { + return properties.keySet(); + } + } + + /** + * Factory method to create a VirtualizationOverheadModel based on the specified type. + * + * @param virtualizationOverheadModelType The type of virtualization overhead model to create. + * @return An instance of the specified VirtualizationOverheadModel. + */ + public static VirtualizationOverheadModel getVirtualizationOverheadModel( + VirtualizationOverheadModelEnum virtualizationOverheadModelType) { + return switch (virtualizationOverheadModelType) { + case NONE -> new NoVirtualizationOverHead(); + case CONSTANT -> { + double percentageOverhead = -1.0; // Default value if not set + if (virtualizationOverheadModelType.getPropertyNames().contains("percentageOverhead")) { + percentageOverhead = + virtualizationOverheadModelType.getProperty("percentageOverhead", Double.class); + } + yield new ConstantVirtualizationOverhead(percentageOverhead); + } + case SHARE_BASED -> new ShareBasedVirtualizationOverhead(); + default -> throw new IllegalArgumentException( + "Unknown virtualization overhead model type: " + virtualizationOverheadModelType); + }; + } +} diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java index cae3e8a1..c388293b 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java @@ -102,7 +102,6 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, protected abstract void updateOutgoingDemand(); - // TODO: This should probably be moved to the distribution strategy protected abstract void updateOutgoingSupplies(); public abstract double[] distributeSupply( @@ -120,6 +119,7 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, this.incomingDemands.add(0.0); this.outgoingSupplies.add(0.0); this.consumerResourceType = consumerEdge.getConsumerResourceType(); + this.outgoingDemandUpdateNeeded = true; } @Override @@ -233,7 +233,7 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, @Override public void pushOutgoingDemand(FlowEdge supplierEdge, double newDemand) { - supplierEdge.pushDemand(newDemand, false, this.getSupplierResourceType()); + supplierEdge.pushDemand(newDemand, false, this.getSupplierResourceType(), this.consumerEdges.size()); } @Override diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowEdge.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowEdge.java index db2a2944..1e65998b 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowEdge.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowEdge.java @@ -177,6 +177,16 @@ public class FlowEdge { this.supplierIndex = supplierIndex; } + public void pushDemand(double newDemand, boolean forceThrough, ResourceType resourceType, int consumerCount) { + // or store last resource type in the edge + if ((newDemand == this.demand) && !forceThrough) { + return; + } + + this.demand = newDemand; + this.supplier.handleIncomingDemand(this, newDemand, resourceType, consumerCount); + } + public void pushDemand(double newDemand, boolean forceThrough, ResourceType resourceType) { // or store last resource type in the edge if ((newDemand == this.demand) && !forceThrough) { diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowSupplier.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowSupplier.java index eb665b8c..2f5f80ef 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowSupplier.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowSupplier.java @@ -32,6 +32,12 @@ public interface FlowSupplier { handleIncomingDemand(consumerEdge, newDemand); } + default void handleIncomingDemand( + FlowEdge consumerEdge, double newDemand, ResourceType resourceType, int consumerCount) { + handleIncomingDemand(consumerEdge, newDemand); + } + ; + void pushOutgoingSupply(FlowEdge consumerEdge, double newSupply); default void pushOutgoingSupply(FlowEdge consumerEdge, double newSupply, ResourceType resourceType) { -- cgit v1.2.3