diff options
Diffstat (limited to 'opendc-simulator')
15 files changed, 152 insertions, 295 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java index 60c877e9..ac3bff74 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java @@ -38,17 +38,17 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer private final CpuPowerModel cpuPowerModel; - private float currentCpuDemand = 0.0f; // cpu capacity demanded by the mux - private float currentCpuUtilization = 0.0f; - private float currentPowerDemand = 0.0f; // power demanded of the psu - private float currentCpuSupplied = 0.0f; // cpu capacity supplied to the mux - private float currentPowerSupplied = 0.0f; // cpu capacity supplied by the psu + private double currentCpuDemand = 0.0f; // cpu capacity demanded by the mux + private double currentCpuUtilization = 0.0f; + private double currentPowerDemand = 0.0f; // power demanded of the psu + private double currentCpuSupplied = 0.0f; // cpu capacity supplied to the mux + private double currentPowerSupplied = 0.0f; // cpu capacity supplied by the psu - private float maxCapacity; + private double maxCapacity; private PerformanceCounters performanceCounters = new PerformanceCounters(); private long lastCounterUpdate; - private final float cpuFrequencyInv; + private final double cpuFrequencyInv; private FlowEdge muxEdge; private FlowEdge psuEdge; @@ -68,7 +68,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public float getCapacity() { + public double getCapacity() { return maxCapacity; } @@ -123,8 +123,8 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer updateCounters(now); // Calculate Power Demand and send to PSU - // TODO: look at the float / double thing - float powerDemand = (float) this.cpuPowerModel.computePower((double) this.currentCpuUtilization); + // TODO: look at the double / double thing + double powerDemand = (double) this.cpuPowerModel.computePower((double) this.currentCpuUtilization); if (powerDemand != this.currentPowerDemand) { this.pushDemand(this.psuEdge, powerDemand); @@ -133,7 +133,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer // Calculate the amount of cpu this can provide // TODO: This should be based on the provided power - float cpuSupply = this.currentCpuDemand; + double cpuSupply = this.currentCpuDemand; if (cpuSupply != this.currentCpuSupplied) { this.pushSupply(this.muxEdge, cpuSupply); @@ -158,11 +158,11 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer long delta = now - lastUpdate; if (delta > 0) { - float demand = this.currentCpuDemand; - float rate = this.currentCpuSupplied; - float capacity = this.maxCapacity; + double demand = this.currentCpuDemand; + double rate = this.currentCpuSupplied; + double capacity = this.maxCapacity; - final float factor = this.cpuFrequencyInv * delta; + final double factor = this.cpuFrequencyInv * delta; this.performanceCounters.addCpuActiveTime(Math.round(rate * factor)); this.performanceCounters.addCpuIdleTime(Math.round((capacity - rate) * factor)); @@ -182,7 +182,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer * Push new demand to the psu */ @Override - public void pushDemand(FlowEdge supplierEdge, float newPowerDemand) { + public void pushDemand(FlowEdge supplierEdge, double newPowerDemand) { this.psuEdge.pushDemand(newPowerDemand); } @@ -190,7 +190,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer * Push updated supply to the mux */ @Override - public void pushSupply(FlowEdge consumerEdge, float newCpuSupply) { + public void pushSupply(FlowEdge consumerEdge, double newCpuSupply) { updateCounters(); this.currentCpuSupplied = newCpuSupply; this.muxEdge.pushSupply(newCpuSupply); @@ -200,7 +200,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer * Handle new demand coming in from the mux */ @Override - public void handleDemand(FlowEdge consumerEdge, float newCpuDemand) { + public void handleDemand(FlowEdge consumerEdge, double newCpuDemand) { if (newCpuDemand == this.currentCpuDemand) { return; } @@ -216,7 +216,7 @@ public final class SimCpu extends FlowNode implements FlowSupplier, FlowConsumer * Handle updated supply from the psu */ @Override - public void handleSupply(FlowEdge supplierEdge, float newPowerSupply) { + public void handleSupply(FlowEdge supplierEdge, double newPowerSupply) { // TODO: Implement this updateCounters(); this.currentPowerSupplied = newPowerSupply; diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/PerformanceCounters.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/PerformanceCounters.java index b1e30e5c..f5b8d27d 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/PerformanceCounters.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/PerformanceCounters.java @@ -28,9 +28,9 @@ public class PerformanceCounters { private long cpuStealTime = 0; private long cpuLostTime = 0; - private float cpuCapacity = 0.0f; - private float cpuDemand = 0.0f; - private float cpuSupply = 0.0f; + private double cpuCapacity = 0.0f; + private double cpuDemand = 0.0f; + private double cpuSupply = 0.0f; public long getCpuActiveTime() { return cpuActiveTime; @@ -76,27 +76,27 @@ public class PerformanceCounters { this.cpuLostTime = cpuLostTime; } - public float getCpuCapacity() { + public double getCpuCapacity() { return cpuCapacity; } - public void setCpuCapacity(float cpuCapacity) { + public void setCpuCapacity(double cpuCapacity) { this.cpuCapacity = cpuCapacity; } - public float getCpuDemand() { + public double getCpuDemand() { return cpuDemand; } - public void setCpuDemand(float cpuDemand) { + public void setCpuDemand(double cpuDemand) { this.cpuDemand = cpuDemand; } - public float getCpuSupply() { + public double getCpuSupply() { return cpuSupply; } - public void setCpuSupply(float cpuSupply) { + public void setCpuSupply(double cpuSupply) { this.cpuSupply = cpuSupply; } } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java index 3bc3d2b4..21f59cf6 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java @@ -46,9 +46,9 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli private FlowEdge cpuEdge; // The edge to the cpu private FlowEdge workloadEdge; // The edge to the workload - private float cpuDemand; - private float cpuSupply; - private float cpuCapacity; + private double cpuDemand; + private double cpuSupply; + private double cpuCapacity; private PerformanceCounters performanceCounters = new PerformanceCounters(); @@ -66,19 +66,19 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli return activeWorkload; } - public float getDemand() { + public double getDemand() { return cpuDemand; } - public void setDemand(float demand) { + public void setDemand(double demand) { this.cpuDemand = demand; } - public float getCpuCapacity() { + public double getCpuCapacity() { return cpuCapacity; } - public void setCpuCapacity(float cpuCapacity) { + public void setCpuCapacity(double cpuCapacity) { this.cpuCapacity = cpuCapacity; } @@ -185,7 +185,7 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli * Push demand to the cpuMux if the demand has changed **/ @Override - public void pushDemand(FlowEdge supplierEdge, float newDemand) { + public void pushDemand(FlowEdge supplierEdge, double newDemand) { this.cpuEdge.pushDemand(newDemand); } @@ -193,15 +193,15 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli * Push supply to the workload if the supply has changed **/ @Override - public void pushSupply(FlowEdge consumerEdge, float newSupply) { - this.workloadEdge.pushDemand(newSupply); + public void pushSupply(FlowEdge consumerEdge, double newSupply) { + this.workloadEdge.pushSupply(newSupply); } /** * Handle new demand from the workload by sending it through to the cpuMux **/ @Override - public void handleDemand(FlowEdge consumerEdge, float newDemand) { + public void handleDemand(FlowEdge consumerEdge, double newDemand) { if (this.cpuDemand == newDemand) { return; } @@ -216,7 +216,7 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli * Handle a new supply pushed by the cpuMux by sending it through to the workload **/ @Override - public void handleSupply(FlowEdge supplierEdge, float newCpuSupply) { + public void handleSupply(FlowEdge supplierEdge, double newCpuSupply) { if (newCpuSupply == this.cpuSupply) { return; } @@ -234,7 +234,7 @@ public class VirtualMachine extends FlowNode implements FlowConsumer, FlowSuppli } @Override - public float getCapacity() { + public double getCapacity() { return this.cpuCapacity; } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/CpuModel.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/CpuModel.java index 88e17941..ab829bc4 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/CpuModel.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/models/CpuModel.java @@ -30,8 +30,8 @@ import java.util.Objects; public final class CpuModel { private final int id; private final int coreCount; - private final float coreSpeed; - private final float totalCapacity; + private final double coreSpeed; + private final double totalCapacity; private final String vendor; private final String modelName; @@ -47,7 +47,7 @@ public final class CpuModel { * @param modelName The name of the CPU * @param arch The architecture of the CPU */ - public CpuModel(int id, int coreCount, float coreSpeed, String vendor, String modelName, String arch) { + public CpuModel(int id, int coreCount, double coreSpeed, String vendor, String modelName, String arch) { this.id = id; this.coreCount = coreCount; this.coreSpeed = coreSpeed; @@ -57,7 +57,7 @@ public final class CpuModel { this.arch = arch; } - public CpuModel(int id, int coreCount, float coreSpeed) { + public CpuModel(int id, int coreCount, double coreSpeed) { this(id, coreCount, coreSpeed, "unkown", "unkown", "unkown"); } @@ -78,14 +78,14 @@ public final class CpuModel { /** * Return the clock rate of a single core of the CPU MHz. */ - public float getCoreSpeed() { + public double getCoreSpeed() { return coreSpeed; } /** * Return the clock rate of the CPU in MHz. */ - public float getTotalCapacity() { + public double getTotalCapacity() { return totalCapacity; } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java index 9b4d6a33..58a6b847 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java @@ -37,13 +37,13 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { private long lastUpdate; - private float powerDemand = 0.0f; - private float powerSupplied = 0.0f; - private float totalEnergyUsage = 0.0f; + private double powerDemand = 0.0f; + private double powerSupplied = 0.0f; + private double totalEnergyUsage = 0.0f; private FlowEdge cpuEdge; - private float capacity = Long.MAX_VALUE; + private double capacity = Long.MAX_VALUE; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Basic Getters and Setters @@ -70,20 +70,20 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { /** * Return the instantaneous power usage of the machine (in W) measured at the InPort of the power supply. */ - public float getPowerDraw() { + public double getPowerDraw() { return this.powerSupplied; } /** * Return the cumulated energy usage of the machine (in J) measured at the InPort of the powers supply. */ - public float getEnergyUsage() { + public double getEnergyUsage() { updateCounters(); return totalEnergyUsage; } @Override - public float getCapacity() { + public double getCapacity() { return this.capacity; } @@ -106,7 +106,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { @Override public long onUpdate(long now) { updateCounters(); - float powerSupply = this.powerDemand; + double powerSupply = this.powerDemand; if (powerSupply != this.powerSupplied) { this.pushSupply(this.cpuEdge, powerSupply); @@ -129,7 +129,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { long duration = now - lastUpdate; if (duration > 0) { // Compute the energy usage of the machine - this.totalEnergyUsage += (float) (this.powerSupplied * duration * 0.001); + this.totalEnergyUsage += (double) (this.powerSupplied * duration * 0.001); } } @@ -138,7 +138,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override - public void handleDemand(FlowEdge consumerEdge, float newPowerDemand) { + public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) { if (newPowerDemand == this.powerDemand) { return; } @@ -148,7 +148,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier { } @Override - public void pushSupply(FlowEdge consumerEdge, float newSupply) { + public void pushSupply(FlowEdge consumerEdge, double newSupply) { if (newSupply == this.powerSupplied) { return; } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java index 8f0fb130..381a8754 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java @@ -35,14 +35,14 @@ import org.opendc.simulator.engine.FlowSupplier; public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer { private long lastUpdate; - private float powerDemand = 0.0f; - private float powerSupplied = 0.0f; - private float totalEnergyUsage = 0.0f; + private double powerDemand = 0.0; + private double powerSupplied = 0.0; + private double totalEnergyUsage = 0.0; private FlowEdge cpuEdge; private FlowEdge powerEdge; - private float capacity = Long.MAX_VALUE; + private double capacity = Long.MAX_VALUE; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Basic Getters and Setters @@ -69,20 +69,20 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer /** * Return the instantaneous power usage of the machine (in W) measured at the InPort of the power supply. */ - public float getPowerDraw() { + public double getPowerDraw() { return this.powerSupplied; } /** * Return the cumulated energy usage of the machine (in J) measured at the InPort of the powers supply. */ - public float getEnergyUsage() { + public double getEnergyUsage() { updateCounters(); return totalEnergyUsage; } @Override - public float getCapacity() { + public double getCapacity() { return this.capacity; } @@ -103,7 +103,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer @Override public long onUpdate(long now) { updateCounters(); - float powerSupply = this.powerDemand; + double powerSupply = this.powerDemand; if (powerSupply != this.powerSupplied) { this.pushSupply(this.cpuEdge, powerSupply); @@ -126,7 +126,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer long duration = now - lastUpdate; if (duration > 0) { // Compute the energy usage of the psu - this.totalEnergyUsage += (float) (this.powerSupplied * duration * 0.001); + this.totalEnergyUsage += (double) (this.powerSupplied * duration * 0.001); } } @@ -135,7 +135,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override - public void pushDemand(FlowEdge supplierEdge, float newDemand) { + public void pushDemand(FlowEdge supplierEdge, double newDemand) { if (newDemand == this.powerDemand) { return; } @@ -145,7 +145,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public void pushSupply(FlowEdge consumerEdge, float newSupply) { + public void pushSupply(FlowEdge consumerEdge, double newSupply) { if (newSupply == this.powerSupplied) { return; } @@ -155,7 +155,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public void handleDemand(FlowEdge consumerEdge, float newPowerDemand) { + public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) { if (newPowerDemand == this.powerDemand) { return; } @@ -165,7 +165,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public void handleSupply(FlowEdge supplierEdge, float newPowerSupply) { + public void handleSupply(FlowEdge supplierEdge, double newPowerSupply) { if (newPowerSupply == this.powerSupplied) { return; } 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 index 7f1cf060..f91c363d 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/SimChainWorkload.java @@ -35,13 +35,13 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { private int workloadIndex; private SimWorkload activeWorkload; - private float demand = 0.0f; - private float supply = 0.0f; + private double demand = 0.0f; + private double supply = 0.0f; private FlowEdge workloadEdge; private FlowEdge machineEdge; - private float capacity = 0; + private double capacity = 0; private long checkpointInterval = 0; private long checkpointDuration = 0; @@ -55,7 +55,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @Override - public float getCapacity() { + public double getCapacity() { return this.capacity; } @@ -194,7 +194,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * @param newDemand */ @Override - public void pushDemand(FlowEdge supplierEdge, float newDemand) { + public void pushDemand(FlowEdge supplierEdge, double newDemand) { this.machineEdge.pushDemand(newDemand); } @@ -205,7 +205,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * @param newSupply */ @Override - public void pushSupply(FlowEdge consumerEdge, float newSupply) { + public void pushSupply(FlowEdge consumerEdge, double newSupply) { this.workloadEdge.pushSupply(newSupply); } @@ -216,7 +216,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * @param newDemand */ @Override - public void handleDemand(FlowEdge consumerEdge, float newDemand) { + public void handleDemand(FlowEdge consumerEdge, double newDemand) { if (newDemand == this.demand) { return; } @@ -232,7 +232,7 @@ final class SimChainWorkload extends SimWorkload implements FlowSupplier { * @param newSupply */ @Override - public void handleSupply(FlowEdge supplierEdge, float newSupply) { + public void handleSupply(FlowEdge supplierEdge, double newSupply) { if (newSupply == this.supply) { return; } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java index b6f98344..59e38ce1 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java @@ -37,8 +37,8 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { private long startOfFragment; private FlowEdge machineEdge; - private float currentDemand; - private float currentSupply; + private double currentDemand; + private double currentSupply; private long checkpointInterval; private long checkpointDuration; @@ -98,7 +98,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { graph.addEdge(this, supplier); this.currentFragment = this.getNextFragment(); - pushDemand(machineEdge, (float) this.currentFragment.cpuUsage()); + pushDemand(machineEdge, (double) this.currentFragment.cpuUsage()); this.startOfFragment = now; } @@ -135,7 +135,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { this.startOfFragment = now - passedTime; // Change the cpu Usage to the new Fragment - pushDemand(machineEdge, (float) this.currentFragment.cpuUsage()); + pushDemand(machineEdge, (double) this.currentFragment.cpuUsage()); // Return the time when the current fragment will complete return this.startOfFragment + duration; @@ -190,7 +190,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { this.fragmentIndex = -1; this.currentFragment = getNextFragment(); - pushDemand(this.machineEdge, (float) this.currentFragment.cpuUsage()); + pushDemand(this.machineEdge, (double) this.currentFragment.cpuUsage()); this.startOfFragment = now; this.invalidate(); @@ -206,7 +206,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { // Start the first Fragment this.currentFragment = this.remainingFragments.pop(); - pushDemand(this.machineEdge, (float) this.currentFragment.cpuUsage()); + pushDemand(this.machineEdge, (double) this.currentFragment.cpuUsage()); this.startOfFragment = offset; this.invalidate(); @@ -223,7 +223,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { * @param newSupply */ @Override - public void handleSupply(FlowEdge supplierEdge, float newSupply) { + public void handleSupply(FlowEdge supplierEdge, double newSupply) { if (newSupply == this.currentSupply) { return; } @@ -238,7 +238,7 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer { * @param newDemand */ @Override - public void pushDemand(FlowEdge supplierEdge, float newDemand) { + public void pushDemand(FlowEdge supplierEdge, double newDemand) { if (newDemand == this.currentDemand) { return; } diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/TraceWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/TraceWorkload.java index 115689df..8e068e1f 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/TraceWorkload.java +++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/TraceWorkload.java @@ -79,7 +79,7 @@ public class TraceWorkload implements Workload { } public static Builder builder() { - return builder(0L, 0L, 0L); + return builder(0L, 0L, 0.0); } public static Builder builder(long checkpointInterval, long checkpointDuration, double checkpointIntervalScaling) { diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt index 2b6a922e..173c60e7 100644 --- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt +++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt @@ -22,18 +22,10 @@ package org.opendc.simulator.compute -import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.opendc.simulator.compute.cpu.CpuPowerModels -import org.opendc.simulator.compute.machine.SimMachine import org.opendc.simulator.compute.models.CpuModel import org.opendc.simulator.compute.models.MachineModel import org.opendc.simulator.compute.models.MemoryUnit -import org.opendc.simulator.compute.workload.TraceWorkload -import org.opendc.simulator.engine.FlowEngine -import org.opendc.simulator.kotlin.runSimulation -import java.util.concurrent.ThreadLocalRandom /** * Test suite for the [SimBareMetalMachine] class. @@ -48,7 +40,7 @@ class SimMachineTest { CpuModel( 0, 2, - 1000.0f, + 1000.0, "Intel", "Xeon", "amd64", @@ -75,33 +67,33 @@ class SimMachineTest { // assertEquals(1000, timeSource.millis()) // } - @Test - fun testTraceWorkload() = - runSimulation { - val random = ThreadLocalRandom.current() - val builder = TraceWorkload.builder() - repeat(100) { - builder.add(1000, random.nextDouble(0.0, 4500.0), 1) - } - val traceWorkload = builder.build() - - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val simMachine = - SimMachine( - graph, - machineModel, - CpuPowerModels.constant(0.0), - ) { cause -> - } - - val virtualMachine = - simMachine.startWorkload(traceWorkload) { cause -> - assertEquals(100000, timeSource.millis()) - } - - // Two cores execute 1000 MFlOps per second (1000 ms) - } +// @Test +// fun testTraceWorkload() = +// runSimulation { +// val random = ThreadLocalRandom.current() +// val builder = TraceWorkload.builder() +// repeat(100) { +// builder.add(1000, random.nextDouble(0.0, 4500.0), 1) +// } +// val traceWorkload = builder.build() +// +// val engine = FlowEngine.create(dispatcher) +// val graph = engine.newGraph() +// val simMachine = +// SimMachine( +// graph, +// machineModel, +// CpuPowerModels.constant(0.0), +// ) { cause -> +// } +// +// val virtualMachine = +// simMachine.startWorkload(traceWorkload) { cause -> +// assertEquals(100000, timeSource.millis()) +// } +// +// // Two cores execute 1000 MFlOps per second (1000 ms) +// } // @Test // fun testDualSocketMachine() = diff --git a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow2/FlowBenchmarks.kt b/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow2/FlowBenchmarks.kt deleted file mode 100644 index 0ab051a4..00000000 --- a/opendc-simulator/opendc-simulator-flow/src/jmh/kotlin/org/opendc/simulator/flow2/FlowBenchmarks.kt +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2021 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.flow2 - -import kotlinx.coroutines.launch -import org.opendc.simulator.flow2.mux.MaxMinFlowMultiplexer -import org.opendc.simulator.flow2.sink.SimpleFlowSink -import org.opendc.simulator.flow2.source.TraceFlowSource -import org.opendc.simulator.flow2.util.FlowTransformer -import org.opendc.simulator.flow2.util.FlowTransforms -import org.opendc.simulator.kotlin.runSimulation -import org.openjdk.jmh.annotations.Benchmark -import org.openjdk.jmh.annotations.Fork -import org.openjdk.jmh.annotations.Measurement -import org.openjdk.jmh.annotations.Scope -import org.openjdk.jmh.annotations.Setup -import org.openjdk.jmh.annotations.State -import org.openjdk.jmh.annotations.Warmup -import java.util.concurrent.ThreadLocalRandom -import java.util.concurrent.TimeUnit - -@State(Scope.Thread) -@Fork(1) -@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS) -@Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) -class FlowBenchmarks { - private lateinit var trace: TraceFlowSource.Trace - - @Setup - fun setUp() { - val random = ThreadLocalRandom.current() - val traceSize = 10_000_000 - trace = - TraceFlowSource.Trace( - LongArray(traceSize) { (it + 1) * 1000L }, - FloatArray(traceSize) { random.nextFloat(0.0f, 4500.0f) }, - traceSize, - ) - } - - @Benchmark - fun benchmarkSink() { - return runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimpleFlowSink(graph, 4200.0f) - val source = TraceFlowSource(graph, trace) - graph.connect(source.output, sink.input) - } - } - - @Benchmark - fun benchmarkForward() { - return runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val sink = SimpleFlowSink(graph, 4200.0f) - val source = TraceFlowSource(graph, trace) - val forwarder = FlowTransformer(graph, FlowTransforms.noop()) - - graph.connect(source.output, forwarder.input) - graph.connect(forwarder.output, sink.input) - } - } - - @Benchmark - fun benchmarkMuxMaxMinSingleSource() { - return runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val switch = MaxMinFlowMultiplexer(graph) - - val sinkA = SimpleFlowSink(graph, 3000.0f) - val sinkB = SimpleFlowSink(graph, 3000.0f) - - graph.connect(switch.newOutPort(), sinkA.input) - graph.connect(switch.newOutPort(), sinkB.input) - - val source = TraceFlowSource(graph, trace) - graph.connect(source.output, switch.newInput()) - } - } - - @Benchmark - fun benchmarkMuxMaxMinTripleSource() { - return runSimulation { - val engine = FlowEngine.create(dispatcher) - val graph = engine.newGraph() - val switch = MaxMinFlowMultiplexer(graph) - - val sinkA = SimpleFlowSink(graph, 3000.0f) - val sinkB = SimpleFlowSink(graph, 3000.0f) - - graph.connect(switch.newOutPort(), sinkA.input) - graph.connect(switch.newOutPort(), sinkB.input) - - repeat(3) { - launch { - val source = TraceFlowSource(graph, trace) - graph.connect(source.output, switch.newInput()) - } - } - } - } -} diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java index 0af2499a..a87ded8d 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java @@ -34,26 +34,26 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer private ArrayList<FlowEdge> consumerEdges = new ArrayList<>(); private FlowEdge supplierEdge; - private ArrayList<Float> demands = new ArrayList<>(); // What is demanded by the consumers - private ArrayList<Float> supplies = new ArrayList<>(); // What is supplied to the consumers + private ArrayList<Double> demands = new ArrayList<>(); // What is demanded by the consumers + private ArrayList<Double> supplies = new ArrayList<>(); // What is supplied to the consumers - private float totalDemand; // The total demand of all the consumers - private float totalSupply; // The total supply from the supplier - private float capacity; // What is the max capacity + private double totalDemand; // The total demand of all the consumers + private double totalSupply; // The total supply from the supplier + private double capacity; // What is the max capacity public Multiplexer(FlowGraph graph) { super(graph); } - public float getTotalDemand() { + public double getTotalDemand() { return totalDemand; } - public float getTotalSupply() { + public double getTotalSupply() { return totalSupply; } - public float getCapacity() { + public double getCapacity() { return capacity; } @@ -67,7 +67,7 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer } } - float totalSupply = 0; + double totalSupply = 0; for (int i = 0; i < this.consumerEdges.size(); i++) { this.pushSupply(this.consumerEdges.get(i), this.supplies.get(i)); totalSupply += this.supplies.get(i); @@ -83,8 +83,8 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer return Long.MAX_VALUE; } - private static float redistributeSupply( - ArrayList<FlowEdge> consumerEdges, ArrayList<Float> supplies, float capacity) { + private static double redistributeSupply( + ArrayList<FlowEdge> consumerEdges, ArrayList<Double> supplies, double capacity) { final long[] consumers = new long[consumerEdges.size()]; for (int i = 0; i < consumers.length; i++) { @@ -94,24 +94,24 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer break; } - consumers[i] = ((long) Float.floatToRawIntBits(consumer.getDemand()) << 32) | (i & 0xFFFFFFFFL); + consumers[i] = (Double.doubleToRawLongBits(consumer.getDemand()) << 32) | (i & 0xFFFFFFFFL); } Arrays.sort(consumers); - float availableCapacity = capacity; + double availableCapacity = capacity; int inputSize = consumers.length; for (int i = 0; i < inputSize; i++) { long v = consumers[i]; int slot = (int) v; - float d = Float.intBitsToFloat((int) (v >> 32)); + double d = Double.longBitsToDouble((int) (v >> 32)); if (d == 0.0) { continue; } - float availableShare = availableCapacity / (inputSize - i); - float r = Math.min(d, availableShare); + double availableShare = availableCapacity / (inputSize - i); + double r = Math.min(d, availableShare); supplies.set(slot, r); // Update the rates availableCapacity -= r; @@ -128,8 +128,8 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer @Override public void addConsumerEdge(FlowEdge consumerEdge) { this.consumerEdges.add(consumerEdge); - this.demands.add(0f); - this.supplies.add(0f); + this.demands.add(0.0); + this.supplies.add(0.0); } @Override @@ -164,7 +164,7 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public void handleDemand(FlowEdge consumerEdge, float newDemand) { + public void handleDemand(FlowEdge consumerEdge, double newDemand) { int idx = consumerEdges.indexOf(consumerEdge); if (idx == -1) { @@ -172,14 +172,14 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer return; } - float prevDemand = demands.get(idx); + double prevDemand = demands.get(idx); demands.set(idx, newDemand); this.totalDemand += (newDemand - prevDemand); } @Override - public void handleSupply(FlowEdge supplierEdge, float newSupply) { + public void handleSupply(FlowEdge supplierEdge, double newSupply) { if (newSupply == this.totalSupply) { return; } @@ -188,22 +188,18 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer } @Override - public void pushDemand(FlowEdge supplierEdge, float newDemand) { + public void pushDemand(FlowEdge supplierEdge, double newDemand) { this.supplierEdge.pushDemand(newDemand); } @Override - public void pushSupply(FlowEdge consumerEdge, float newSupply) { + public void pushSupply(FlowEdge consumerEdge, double newSupply) { int idx = consumerEdges.indexOf(consumerEdge); if (idx == -1) { System.out.println("Error (Multiplexer): pushing supply to an unknown consumer"); } - if (newSupply == supplies.get(idx)) { - return; - } - supplies.set(idx, newSupply); consumerEdge.pushSupply(newSupply); } diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowConsumer.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowConsumer.java index 7ba5dea7..ddb40794 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowConsumer.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowConsumer.java @@ -24,9 +24,9 @@ package org.opendc.simulator.engine; public interface FlowConsumer { - void handleSupply(FlowEdge supplierEdge, float newSupply); + void handleSupply(FlowEdge supplierEdge, double newSupply); - void pushDemand(FlowEdge supplierEdge, float newDemand); + void pushDemand(FlowEdge supplierEdge, double newDemand); void addSupplierEdge(FlowEdge supplierEdge); diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowEdge.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowEdge.java index 0edc9e68..d89740a2 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowEdge.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowEdge.java @@ -32,10 +32,10 @@ public class FlowEdge { private FlowConsumer consumer; private FlowSupplier supplier; - private float demand = 0.0f; - private float supply = 0.0f; + private double demand = 0.0; + private double supply = 0.0; - private float capacity; + private double capacity; public FlowEdge(FlowConsumer consumer, FlowSupplier supplier) { if (!(consumer instanceof FlowNode)) { @@ -74,25 +74,22 @@ public class FlowEdge { return supplier; } - public float getCapacity() { + public double getCapacity() { return capacity; } - public float getDemand() { + public double getDemand() { return this.demand; } - public float getSupply() { + public double getSupply() { return this.supply; } /** * Push new demand from the Consumer to the Supplier */ - public void pushDemand(float newDemand) { - if (newDemand == this.demand) { - return; - } + public void pushDemand(double newDemand) { this.demand = newDemand; this.supplier.handleDemand(this, newDemand); @@ -102,10 +99,7 @@ public class FlowEdge { /** * Push new supply from the Supplier to the Consumer */ - public void pushSupply(float newSupply) { - if (newSupply == this.supply) { - return; - } + public void pushSupply(double newSupply) { this.supply = newSupply; this.consumer.handleSupply(this, newSupply); diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowSupplier.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowSupplier.java index 87729fca..955f4943 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowSupplier.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/FlowSupplier.java @@ -24,13 +24,13 @@ package org.opendc.simulator.engine; public interface FlowSupplier { - void handleDemand(FlowEdge consumerEdge, float newDemand); + void handleDemand(FlowEdge consumerEdge, double newDemand); - void pushSupply(FlowEdge consumerEdge, float newSupply); + void pushSupply(FlowEdge consumerEdge, double newSupply); void addConsumerEdge(FlowEdge consumerEdge); void removeConsumerEdge(FlowEdge consumerEdge); - float getCapacity(); + double getCapacity(); } |
