summaryrefslogtreecommitdiff
path: root/opendc-simulator
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2023-11-15 15:56:03 +0100
committerGitHub <noreply@github.com>2023-11-15 15:56:03 +0100
commit05141e92582372c816648b94ef3de5e16d1fe5b9 (patch)
tree41e703d5a129948d445d9957392c632ab3f74872 /opendc-simulator
parent2fc71b81ea01072c37ce140d4a47e33a25d65f72 (diff)
parent1513efe07605975cd2f86f0b739bd490e4fc9970 (diff)
Merge pull request #168 from DanteNiewenhuis/greenifier-demo
Updated the simulation to let servers run until they are finished.
Diffstat (limited to 'opendc-simulator')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java3
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimChainWorkload.java8
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java3
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java3
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java69
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java2
6 files changed, 54 insertions, 34 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java
index a1623351..ffe327d3 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/kernel/SimHypervisor.java
@@ -72,6 +72,9 @@ public final class SimHypervisor implements SimWorkload {
private final ArrayList<VirtualMachine> vms = new ArrayList<>();
private final HvCounters counters = new HvCounters();
+ @Override
+ public void setOffset(long now) {}
+
/**
* Construct a {@link SimHypervisor} instance.
*
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 7480b3c0..f81b1779 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
@@ -61,6 +61,14 @@ final class SimChainWorkload implements SimWorkload {
}
@Override
+ public void setOffset(long now) {
+ for (SimWorkload workload : this.workloads) {
+ workload.setOffset(now);
+ }
+
+ }
+
+ @Override
public void onStart(SimMachineContext ctx) {
final SimWorkload[] workloads = this.workloads;
final int activeWorkloadIndex = this.activeWorkloadIndex;
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java
index 839856bb..8704f6b9 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java
@@ -64,6 +64,9 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic {
}
@Override
+ public void setOffset(long now) {}
+
+ @Override
public void onStart(SimMachineContext ctx) {
this.ctx = ctx;
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java
index 9c9f4788..bf54142f 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java
@@ -63,6 +63,9 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
}
@Override
+ public void setOffset(long now) {}
+
+ @Override
public void onStart(SimMachineContext ctx) {
this.ctx = ctx;
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java
index 1d8667d5..caf0c3d7 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java
@@ -68,10 +68,10 @@ public final class SimTrace {
/**
* Construct a {@link SimWorkload} for this trace.
*
- * @param offset The offset for the timestamps.
+// * @param offset The offset for the timestamps.
*/
- public SimWorkload createWorkload(long offset) {
- return new Workload(offset, usageCol, deadlineCol, coresCol, size, 0);
+ public SimWorkload createWorkload(long start) {
+ return new Workload(start, usageCol, deadlineCol, coresCol, size, 0);
}
/**
@@ -206,15 +206,17 @@ public final class SimTrace {
private static class Workload implements SimWorkload {
private WorkloadStageLogic logic;
- private final long offset;
+ private long offset;
+
+ private final long start;
private final double[] usageCol;
private final long[] deadlineCol;
private final int[] coresCol;
private final int size;
private final int index;
- private Workload(long offset, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) {
- this.offset = offset;
+ private Workload(long start, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) {
+ this.start = start;
this.usageCol = usageCol;
this.deadlineCol = deadlineCol;
this.coresCol = coresCol;
@@ -223,6 +225,11 @@ public final class SimTrace {
}
@Override
+ public void setOffset(long now) {
+ this.offset = now - this.start;
+ }
+
+ @Override
public void onStart(SimMachineContext ctx) {
final WorkloadStageLogic logic;
if (ctx.getCpus().size() == 1) {
@@ -252,7 +259,7 @@ public final class SimTrace {
index = logic.getIndex();
}
- return new Workload(offset, usageCol, deadlineCol, coresCol, size, index);
+ return new Workload(start, usageCol, deadlineCol, coresCol, size, index);
}
}
@@ -279,20 +286,20 @@ public final class SimTrace {
private final OutPort output;
private int index;
- private final long offset;
- private final double[] usageCol;
- private final long[] deadlineCol;
- private final int size;
+ private final long workloadOffset;
+ private final double[] cpuUsages;
+ private final long[] deadlines;
+ private final int traceSize;
private final SimMachineContext ctx;
private SingleWorkloadLogic(
SimMachineContext ctx, long offset, double[] usageCol, long[] deadlineCol, int size, int index) {
this.ctx = ctx;
- this.offset = offset;
- this.usageCol = usageCol;
- this.deadlineCol = deadlineCol;
- this.size = size;
+ this.workloadOffset = offset;
+ this.cpuUsages = usageCol;
+ this.deadlines = deadlineCol;
+ this.traceSize = size;
this.index = index;
final FlowGraph graph = ctx.getGraph();
@@ -309,25 +316,20 @@ public final class SimTrace {
@Override
public long onUpdate(FlowStage ctx, long now) {
- int size = this.size;
- long offset = this.offset;
- long nowOffset = now - offset;
-
- int index = this.index;
-
- long[] deadlines = deadlineCol;
- long deadline = deadlines[index];
+ // Shift the current time to align with the starting time of the workload
+ long nowOffset = now - this.workloadOffset;
+ long deadline = this.deadlines[this.index];
+ // Loop through the deadlines until the next deadline is reached.
while (deadline <= nowOffset) {
- if (++index >= size) {
+ if (++this.index >= this.traceSize) {
return doStop(ctx);
}
- deadline = deadlines[index];
+ deadline = this.deadlines[this.index];
}
- this.index = index;
- this.output.push((float) usageCol[index]);
- return deadline + offset;
+ this.output.push((float) this.cpuUsages[this.index]);
+ return deadline + this.workloadOffset;
}
@Override
@@ -366,7 +368,7 @@ public final class SimTrace {
private final double[] usageCol;
private final long[] deadlineCol;
private final int[] coresCol;
- private final int size;
+ private final int traceSize;
private final SimMachineContext ctx;
@@ -376,14 +378,14 @@ public final class SimTrace {
double[] usageCol,
long[] deadlineCol,
int[] coresCol,
- int size,
+ int traceSize,
int index) {
this.ctx = ctx;
this.offset = offset;
this.usageCol = usageCol;
this.deadlineCol = deadlineCol;
this.coresCol = coresCol;
- this.size = size;
+ this.traceSize = traceSize;
this.index = index;
final FlowGraph graph = ctx.getGraph();
@@ -406,7 +408,6 @@ public final class SimTrace {
@Override
public long onUpdate(FlowStage ctx, long now) {
- int size = this.size;
long offset = this.offset;
long nowOffset = now - offset;
@@ -415,11 +416,11 @@ public final class SimTrace {
long[] deadlines = deadlineCol;
long deadline = deadlines[index];
- while (deadline <= nowOffset && ++index < size) {
+ while (deadline <= nowOffset && ++index < this.traceSize) {
deadline = deadlines[index];
}
- if (index >= size) {
+ if (index >= this.traceSize) {
final SimMachineContext machineContext = this.ctx;
if (machineContext != null) {
machineContext.shutdown();
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java
index cad324fb..0c3779bd 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkload.java
@@ -50,4 +50,6 @@ public interface SimWorkload {
* Create a snapshot of this workload.
*/
SimWorkload snapshot();
+
+ void setOffset(long now);
}