Skip to content

Commit 279f2a3

Browse files
Fixed power source bug (#265)
* Fixed a small bug making the power source not update energy usage properly * small update to the test
1 parent 4e8ca5d commit 279f2a3

File tree

8 files changed

+10
-33
lines changed

8 files changed

+10
-33
lines changed

opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ public class ComputeMetricReader(
9898
loggState()
9999
}
100100
} finally {
101-
loggState()
102-
103101
if (monitor is AutoCloseable) {
104102
monitor.close()
105103
}

opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public data class PowerSourceJSONSpec(
151151
public companion object {
152152
public val DFLT: PowerSourceJSONSpec =
153153
PowerSourceJSONSpec(
154-
totalPower = 10000,
154+
totalPower = Long.MAX_VALUE,
155155
)
156156
}
157157
}

opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/ScenarioIntegrationTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ class ScenarioIntegrationTest {
335335
{ assertEquals(0, monitor.tasksActive, "All VMs should finish after a run") },
336336
{ assertEquals(0, monitor.attemptsFailure, "No VM should be unscheduled") },
337337
{ assertEquals(0, monitor.tasksPending, "No VM should not be in the queue") },
338-
{ assertEquals(43101787433, monitor.idleTime) { "Incorrect idle time" } },
339-
{ assertEquals(3489412567, monitor.activeTime) { "Incorrect active time" } },
338+
{ assertEquals(43101793092, monitor.idleTime) { "Incorrect idle time" } },
339+
{ assertEquals(3489406908, monitor.activeTime) { "Incorrect active time" } },
340340
{ assertEquals(0, monitor.stealTime) { "Incorrect steal time" } },
341341
{ assertEquals(0, monitor.lostTime) { "Incorrect lost time" } },
342342
{ assertEquals(1.0016123392181786E10, monitor.energyUsage, 1E4) { "Incorrect energy usage" } },

opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/cpu/SimCpu.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public long onUpdate(long now) {
124124

125125
// Calculate Power Demand and send to PSU
126126
// TODO: look at the double / double thing
127-
double powerDemand = (double) this.cpuPowerModel.computePower((double) this.currentCpuUtilization);
127+
double powerDemand = this.cpuPowerModel.computePower(this.currentCpuUtilization);
128128

129129
if (powerDemand != this.currentPowerDemand) {
130130
this.pushDemand(this.psuEdge, powerDemand);
@@ -201,10 +201,6 @@ public void pushSupply(FlowEdge consumerEdge, double newCpuSupply) {
201201
*/
202202
@Override
203203
public void handleDemand(FlowEdge consumerEdge, double newCpuDemand) {
204-
if (newCpuDemand == this.currentCpuDemand) {
205-
return;
206-
}
207-
208204
updateCounters();
209205
this.currentCpuDemand = newCpuDemand;
210206
this.currentCpuUtilization = this.currentCpuDemand / this.maxCapacity;

opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/machine/VirtualMachine.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ public void pushSupply(FlowEdge consumerEdge, double newSupply) {
202202
**/
203203
@Override
204204
public void handleDemand(FlowEdge consumerEdge, double newDemand) {
205-
if (this.cpuDemand == newDemand) {
206-
return;
207-
}
208205

209206
updateCounters(this.clock.millis());
210207
this.cpuDemand = newDemand;
@@ -217,9 +214,6 @@ public void handleDemand(FlowEdge consumerEdge, double newDemand) {
217214
**/
218215
@Override
219216
public void handleSupply(FlowEdge supplierEdge, double newCpuSupply) {
220-
if (newCpuSupply == this.cpuSupply) {
221-
return;
222-
}
223217

224218
updateCounters(this.clock.millis());
225219
this.cpuSupply = newCpuSupply;

opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPowerSource.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,13 @@ public void updateCounters(long now) {
163163

164164
@Override
165165
public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) {
166-
if (newPowerDemand == this.powerDemand) {
167-
return;
168-
}
169166

170167
this.powerDemand = newPowerDemand;
171168
this.invalidate();
172169
}
173170

174171
@Override
175172
public void pushSupply(FlowEdge consumerEdge, double newSupply) {
176-
if (newSupply == this.powerSupplied) {
177-
return;
178-
}
179173

180174
this.powerSupplied = newSupply;
181175
consumerEdge.pushSupply(newSupply);

opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/SimPsu.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ public void pushSupply(FlowEdge consumerEdge, double newSupply) {
148148

149149
@Override
150150
public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) {
151-
if (newPowerDemand == this.powerDemand) {
152-
return;
153-
}
154151

155152
updateCounters();
156153
this.powerDemand = newPowerDemand;
@@ -160,9 +157,6 @@ public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) {
160157

161158
@Override
162159
public void handleSupply(FlowEdge supplierEdge, double newPowerSupply) {
163-
if (newPowerSupply == this.powerSupplied) {
164-
return;
165-
}
166160

167161
updateCounters();
168162
this.powerSupplied = newPowerSupply;

opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ public void addConsumerEdge(FlowEdge consumerEdge) {
130130
this.consumerEdges.add(consumerEdge);
131131
this.demands.add(0.0);
132132
this.supplies.add(0.0);
133+
134+
this.invalidate();
133135
}
134136

135137
@Override
136138
public void addSupplierEdge(FlowEdge supplierEdge) {
137139
this.supplierEdge = supplierEdge;
138140
this.capacity = supplierEdge.getCapacity();
139141
this.totalSupply = 0;
142+
143+
this.invalidate();
140144
}
141145

142146
@Override
@@ -176,15 +180,12 @@ public void handleDemand(FlowEdge consumerEdge, double newDemand) {
176180
demands.set(idx, newDemand);
177181

178182
this.totalDemand += (newDemand - prevDemand);
183+
this.invalidate();
179184
}
180185

181186
@Override
182187
public void handleSupply(FlowEdge supplierEdge, double newSupply) {
183-
if (newSupply == this.totalSupply) {
184-
return;
185-
}
186-
187-
this.totalSupply = newSupply;
188+
this.invalidate();
188189
}
189190

190191
@Override

0 commit comments

Comments
 (0)