summaryrefslogtreecommitdiff
path: root/opendc-simulator
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-10-30 17:35:06 +0100
committerGitHub <noreply@github.com>2024-10-30 17:35:06 +0100
commit7511fb768fab68d542adf5bbfb15e32300156c7e (patch)
tree959736689bff655be4ea7e6cc92aaec60ca74f1a /opendc-simulator
parent2325c62377e7c94e768a22807e107a9714626bfc (diff)
Added power sources to OpenDC (#258)
* Added power sources to OpenDC. In the current form each Cluster has a single power source that is connected to all hosts in that cluster * Added power sources to OpenDC. In the current form each Cluster has a single power source that is connected to all hosts in that cluster * Ran spotless Kotlin and Java
Diffstat (limited to 'opendc-simulator')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java9
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java17
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java26
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTraceWorkload.java16
4 files changed, 25 insertions, 43 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/SimMachine.java
index 00a69efe..4602223c 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
@@ -112,13 +112,20 @@ public class SimMachine {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public SimMachine(
- FlowGraph graph, MachineModel machineModel, CpuPowerModel cpuPowerModel, Consumer<Exception> completion) {
+ FlowGraph graph,
+ MachineModel machineModel,
+ CpuPowerModel cpuPowerModel,
+ Multiplexer powerMux,
+ Consumer<Exception> completion) {
this.graph = graph;
this.machineModel = machineModel;
this.clock = graph.getEngine().getClock();
// Create the psu and cpu and connect them
this.psu = new SimPsu(graph);
+
+ graph.addEdge(this.psu, powerMux);
+
this.cpu = new SimCpu(graph, this.machineModel.getCpu(), 0);
graph.addEdge(this.cpu, this.psu);
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 58a6b847..79ff93c0 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
@@ -22,7 +22,6 @@
package org.opendc.simulator.compute.power;
-import java.time.InstantSource;
import org.opendc.simulator.compute.cpu.SimCpu;
import org.opendc.simulator.engine.FlowEdge;
import org.opendc.simulator.engine.FlowGraph;
@@ -33,15 +32,13 @@ import org.opendc.simulator.engine.FlowSupplier;
* A {@link SimPsu} implementation that estimates the power consumption based on CPU usage.
*/
public final class SimPowerSource extends FlowNode implements FlowSupplier {
- private final InstantSource clock;
-
private long lastUpdate;
private double powerDemand = 0.0f;
private double powerSupplied = 0.0f;
private double totalEnergyUsage = 0.0f;
- private FlowEdge cpuEdge;
+ private FlowEdge muxEdge;
private double capacity = Long.MAX_VALUE;
@@ -55,7 +52,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier {
* @return <code>true</code> if the InPort is connected to an OutPort, <code>false</code> otherwise.
*/
public boolean isConnected() {
- return cpuEdge != null;
+ return muxEdge != null;
}
/**
@@ -94,9 +91,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier {
public SimPowerSource(FlowGraph graph) {
super(graph);
- this.clock = graph.getEngine().getClock();
-
- lastUpdate = graph.getEngine().getClock().millis();
+ lastUpdate = this.clock.millis();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -109,7 +104,7 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier {
double powerSupply = this.powerDemand;
if (powerSupply != this.powerSupplied) {
- this.pushSupply(this.cpuEdge, powerSupply);
+ this.pushSupply(this.muxEdge, powerSupply);
}
return Long.MAX_VALUE;
@@ -159,11 +154,11 @@ public final class SimPowerSource extends FlowNode implements FlowSupplier {
@Override
public void addConsumerEdge(FlowEdge consumerEdge) {
- this.cpuEdge = consumerEdge;
+ this.muxEdge = consumerEdge;
}
@Override
public void removeConsumerEdge(FlowEdge consumerEdge) {
- this.cpuEdge = null;
+ this.muxEdge = null;
}
}
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 381a8754..436c5c12 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
@@ -40,7 +40,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
private double totalEnergyUsage = 0.0;
private FlowEdge cpuEdge;
- private FlowEdge powerEdge;
+ private FlowEdge powerSupplyEdge;
private double capacity = Long.MAX_VALUE;
@@ -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 += (double) (this.powerSupplied * duration * 0.001);
+ this.totalEnergyUsage += (this.powerSupplied * duration * 0.001);
}
}
@@ -136,20 +136,12 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
@Override
public void pushDemand(FlowEdge supplierEdge, double newDemand) {
- if (newDemand == this.powerDemand) {
- return;
- }
-
this.powerDemand = newDemand;
- powerEdge.pushSupply(newDemand);
+ powerSupplyEdge.pushDemand(newDemand);
}
@Override
public void pushSupply(FlowEdge consumerEdge, double newSupply) {
- if (newSupply == this.powerSupplied) {
- return;
- }
-
this.powerSupplied = newSupply;
cpuEdge.pushSupply(newSupply);
}
@@ -160,8 +152,10 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
return;
}
+ updateCounters();
this.powerDemand = newPowerDemand;
- this.invalidate();
+
+ pushDemand(this.powerSupplyEdge, newPowerDemand);
}
@Override
@@ -170,8 +164,10 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
return;
}
+ updateCounters();
this.powerSupplied = newPowerSupply;
- this.invalidate();
+
+ pushSupply(this.cpuEdge, newPowerSupply);
}
@Override
@@ -181,7 +177,7 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
@Override
public void addSupplierEdge(FlowEdge supplierEdge) {
- this.powerEdge = supplierEdge;
+ this.powerSupplyEdge = supplierEdge;
}
@Override
@@ -191,6 +187,6 @@ public final class SimPsu extends FlowNode implements FlowSupplier, FlowConsumer
@Override
public void removeSupplierEdge(FlowEdge supplierEdge) {
- this.powerEdge = null;
+ this.powerSupplyEdge = null;
}
}
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 59e38ce1..b269564d 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
@@ -196,22 +196,6 @@ public class SimTraceWorkload extends SimWorkload implements FlowConsumer {
this.invalidate();
}
- /**
- * Update the Fragments that are being used by the SimTraceWorkload
- * @param newFragments
- * @param offset
- */
- public void updateFragments(LinkedList<TraceFragment> newFragments, long offset) {
- this.remainingFragments = newFragments;
-
- // Start the first Fragment
- this.currentFragment = this.remainingFragments.pop();
- pushDemand(this.machineEdge, (double) this.currentFragment.cpuUsage());
- this.startOfFragment = offset;
-
- this.invalidate();
- }
-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FlowGraph Related functionality
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////