summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CPUPowerModelsFactory.kt9
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java62
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimTrace.java29
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java17
4 files changed, 108 insertions, 9 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CPUPowerModelsFactory.kt b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CPUPowerModelsFactory.kt
index e2f852f8..2c64944c 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CPUPowerModelsFactory.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/power/CPUPowerModelsFactory.kt
@@ -22,6 +22,15 @@
package org.opendc.simulator.compute.power
+// TODO: couple this correctly
+public enum class CPUPowerModel {
+ Constant,
+ Sqrt,
+ Linear,
+ Square,
+ Cubic,
+}
+
public fun getPowerModel(
modelType: String,
power: Double,
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 bf54142f..c116a5e5 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
@@ -34,7 +34,7 @@ import org.opendc.simulator.flow2.OutPort;
* A [SimWorkload] that models application execution as a single duration.
*/
public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
- private final long duration;
+ private long duration;
private final double utilization;
private SimMachineContext ctx;
@@ -44,20 +44,52 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
private long remainingDuration;
private long lastUpdate;
+ private long checkpointTime; // How long does it take to make a checkpoint?
+ private long checkpointWait; // How long to wait until a new checkpoint is made?
+ private long totalChecks;
+
+ public SimRuntimeWorkload(long duration, double utilization) {
+ this(duration, utilization, 0, 0);
+ // if (duration < 0) {
+ // throw new IllegalArgumentException("Duration must be positive");
+ // } else if (utilization <= 0.0 || utilization > 1.0) {
+ // throw new IllegalArgumentException("Utilization must be in (0, 1]");
+ // }
+ //
+ // this.checkpointTime = 0L;
+ // this.checkpointWait = 0L;
+ // this.duration = duration;
+ //
+ // this.utilization = utilization;
+ // this.remainingDuration = duration;
+ }
+
/**
* Construct a new {@link SimRuntimeWorkload}.
*
* @param duration The duration of the workload in milliseconds.
* @param utilization The CPU utilization of the workload.
*/
- SimRuntimeWorkload(long duration, double utilization) {
+ public SimRuntimeWorkload(long duration, double utilization, long checkpointTime, long checkpointWait) {
if (duration < 0) {
throw new IllegalArgumentException("Duration must be positive");
} else if (utilization <= 0.0 || utilization > 1.0) {
throw new IllegalArgumentException("Utilization must be in (0, 1]");
}
+ this.checkpointTime = checkpointTime;
+ this.checkpointWait = checkpointWait;
this.duration = duration;
+
+ if (this.checkpointWait > 0) {
+ // Determine the number of checkpoints that need to be made during the workload
+ // If the total duration is divisible by the wait time between checkpoints, we can remove the last
+ // checkpoint
+ int to_remove = ((this.duration % this.checkpointWait == 0) ? 1 : 0);
+ this.totalChecks = this.duration / this.checkpointWait - to_remove;
+ this.duration += (this.checkpointTime * totalChecks);
+ }
+
this.utilization = utilization;
this.remainingDuration = duration;
}
@@ -108,7 +140,25 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
stage.sync();
}
- return new SimRuntimeWorkload(remainingDuration, utilization);
+ var remaining_time = this.remainingDuration;
+
+ if (this.checkpointWait > 0) {
+ // Calculate last checkpoint
+ var total_check_time = this.checkpointWait + this.checkpointTime;
+ var processed_time = this.duration - this.remainingDuration;
+ var processed_checks = (int) (processed_time / total_check_time);
+ var processed_time_last_check =
+ (processed_checks * total_check_time); // The processed time after the last checkpoint
+
+ remaining_time = this.duration
+ - processed_time_last_check; // The remaining duration to process after last checkpoint
+ var remaining_checks = (int) (remaining_time / total_check_time);
+ remaining_time -= (remaining_checks * checkpointTime);
+ } else {
+ remaining_time = duration;
+ }
+
+ return new SimRuntimeWorkload(remaining_time, utilization, this.checkpointTime, this.checkpointWait);
}
@Override
@@ -119,6 +169,12 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
long delta = now - lastUpdate;
long duration = this.remainingDuration - delta;
+ if (delta == 0 && this.ctx == null) {
+ // This means the workload has been terminated
+ // But, has not executed to completion
+ return Long.MAX_VALUE;
+ }
+
if (duration <= 0) {
final SimMachineContext machineContext = this.ctx;
if (machineContext != null) {
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 f2f4ce45..21379f0d 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
@@ -71,7 +71,16 @@ public final class SimTrace {
* // * @param offset The offset for the timestamps.
*/
public SimWorkload createWorkload(long start) {
- return new Workload(start, usageCol, deadlineCol, coresCol, size, 0);
+ return createWorkload(start, 0, 0);
+ }
+
+ /**
+ * Construct a {@link SimWorkload} for this trace.
+ *
+ * // * @param offset The offset for the timestamps.
+ */
+ public SimWorkload createWorkload(long start, long checkpointTime, long checkpointWait) {
+ return new Workload(start, usageCol, deadlineCol, coresCol, size, 0, checkpointTime, checkpointWait);
}
/**
@@ -215,13 +224,27 @@ public final class SimTrace {
private final int size;
private final int index;
- private Workload(long start, double[] usageCol, long[] deadlineCol, int[] coresCol, int size, int index) {
+ private long checkpointTime; // How long does it take to make a checkpoint?
+ private long checkpointWait; // How long to wait until a new checkpoint is made?
+ private long total_checks;
+
+ private Workload(
+ long start,
+ double[] usageCol,
+ long[] deadlineCol,
+ int[] coresCol,
+ int size,
+ int index,
+ long checkpointTime,
+ long checkpointWait) {
this.start = start;
this.usageCol = usageCol;
this.deadlineCol = deadlineCol;
this.coresCol = coresCol;
this.size = size;
this.index = index;
+ this.checkpointTime = checkpointTime;
+ this.checkpointWait = checkpointWait;
}
@Override
@@ -259,7 +282,7 @@ public final class SimTrace {
index = logic.getIndex();
}
- return new Workload(start, usageCol, deadlineCol, coresCol, size, index);
+ return new Workload(start, usageCol, deadlineCol, coresCol, size, index, checkpointTime, checkpointWait);
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java
index 82557d06..294b5dde 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java
@@ -48,7 +48,17 @@ public class SimWorkloads {
* @param utilization The CPU utilization of the workload.
*/
public static SimWorkload runtime(long duration, double utilization) {
- return new SimRuntimeWorkload(duration, utilization);
+ return runtime(duration, utilization, 0, 0);
+ }
+
+ /**
+ * Create a {@link SimWorkload} that consumes the CPU resources for a specified duration at the given utilization.
+ *
+ * @param duration The duration of the workload in milliseconds.
+ * @param utilization The CPU utilization of the workload.
+ */
+ public static SimWorkload runtime(long duration, double utilization, long checkpoint_time, long checkpoint_wait) {
+ return new SimRuntimeWorkload(duration, utilization, checkpoint_time, checkpoint_wait);
}
/**
@@ -57,8 +67,9 @@ public class SimWorkloads {
* @param duration The duration of the workload.
* @param utilization The CPU utilization of the workload.
*/
- public static SimWorkload runtime(Duration duration, double utilization) {
- return runtime(duration.toMillis(), utilization);
+ public static SimWorkload runtime(
+ Duration duration, double utilization, long checkpoint_time, long checkpoint_wait) {
+ return runtime(duration.toMillis(), utilization, checkpoint_time, checkpoint_wait);
}
/**