Skip to content

Commit

Permalink
Fixed power source bug (#265)
Browse files Browse the repository at this point in the history
* Fixed a small bug making the power source not update energy usage properly

* small update to the test
  • Loading branch information
DanteNiewenhuis authored Nov 7, 2024
1 parent 4e8ca5d commit 279f2a3
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public class ComputeMetricReader(
loggState()
}
} finally {
loggState()

if (monitor is AutoCloseable) {
monitor.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public data class PowerSourceJSONSpec(
public companion object {
public val DFLT: PowerSourceJSONSpec =
PowerSourceJSONSpec(
totalPower = 10000,
totalPower = Long.MAX_VALUE,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ class ScenarioIntegrationTest {
{ assertEquals(0, monitor.tasksActive, "All VMs should finish after a run") },
{ assertEquals(0, monitor.attemptsFailure, "No VM should be unscheduled") },
{ assertEquals(0, monitor.tasksPending, "No VM should not be in the queue") },
{ assertEquals(43101787433, monitor.idleTime) { "Incorrect idle time" } },
{ assertEquals(3489412567, monitor.activeTime) { "Incorrect active time" } },
{ assertEquals(43101793092, monitor.idleTime) { "Incorrect idle time" } },
{ assertEquals(3489406908, monitor.activeTime) { "Incorrect active time" } },
{ assertEquals(0, monitor.stealTime) { "Incorrect steal time" } },
{ assertEquals(0, monitor.lostTime) { "Incorrect lost time" } },
{ assertEquals(1.0016123392181786E10, monitor.energyUsage, 1E4) { "Incorrect energy usage" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public long onUpdate(long now) {

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

if (powerDemand != this.currentPowerDemand) {
this.pushDemand(this.psuEdge, powerDemand);
Expand Down Expand Up @@ -201,10 +201,6 @@ public void pushSupply(FlowEdge consumerEdge, double newCpuSupply) {
*/
@Override
public void handleDemand(FlowEdge consumerEdge, double newCpuDemand) {
if (newCpuDemand == this.currentCpuDemand) {
return;
}

updateCounters();
this.currentCpuDemand = newCpuDemand;
this.currentCpuUtilization = this.currentCpuDemand / this.maxCapacity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ public void pushSupply(FlowEdge consumerEdge, double newSupply) {
**/
@Override
public void handleDemand(FlowEdge consumerEdge, double newDemand) {
if (this.cpuDemand == newDemand) {
return;
}

updateCounters(this.clock.millis());
this.cpuDemand = newDemand;
Expand All @@ -217,9 +214,6 @@ public void handleDemand(FlowEdge consumerEdge, double newDemand) {
**/
@Override
public void handleSupply(FlowEdge supplierEdge, double newCpuSupply) {
if (newCpuSupply == this.cpuSupply) {
return;
}

updateCounters(this.clock.millis());
this.cpuSupply = newCpuSupply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,13 @@ public void updateCounters(long now) {

@Override
public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) {
if (newPowerDemand == this.powerDemand) {
return;
}

this.powerDemand = newPowerDemand;
this.invalidate();
}

@Override
public void pushSupply(FlowEdge consumerEdge, double newSupply) {
if (newSupply == this.powerSupplied) {
return;
}

this.powerSupplied = newSupply;
consumerEdge.pushSupply(newSupply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ public void pushSupply(FlowEdge consumerEdge, double newSupply) {

@Override
public void handleDemand(FlowEdge consumerEdge, double newPowerDemand) {
if (newPowerDemand == this.powerDemand) {
return;
}

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

@Override
public void handleSupply(FlowEdge supplierEdge, double newPowerSupply) {
if (newPowerSupply == this.powerSupplied) {
return;
}

updateCounters();
this.powerSupplied = newPowerSupply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ public void addConsumerEdge(FlowEdge consumerEdge) {
this.consumerEdges.add(consumerEdge);
this.demands.add(0.0);
this.supplies.add(0.0);

this.invalidate();
}

@Override
public void addSupplierEdge(FlowEdge supplierEdge) {
this.supplierEdge = supplierEdge;
this.capacity = supplierEdge.getCapacity();
this.totalSupply = 0;

this.invalidate();
}

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

this.totalDemand += (newDemand - prevDemand);
this.invalidate();
}

@Override
public void handleSupply(FlowEdge supplierEdge, double newSupply) {
if (newSupply == this.totalSupply) {
return;
}

this.totalSupply = newSupply;
this.invalidate();
}

@Override
Expand Down

0 comments on commit 279f2a3

Please sign in to comment.