summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimFlopsWorkload.java4
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimRuntimeWorkload.java4
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.java60
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java63
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt14
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt13
6 files changed, 80 insertions, 78 deletions
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 255fd1b2..f3efbebb 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
@@ -49,9 +49,9 @@ public class SimFlopsWorkload implements SimWorkload, FlowStageLogic {
* Construct a new {@link SimFlopsWorkload}.
*
* @param flops The number of floating point operations to perform for this task in MFLOPs.
- * @param utilization A model of the CPU utilization of the application.
+ * @param utilization The CPU utilization of the workload.
*/
- public SimFlopsWorkload(long flops, double utilization) {
+ SimFlopsWorkload(long flops, double utilization) {
if (flops < 0) {
throw new IllegalArgumentException("Number of FLOPs must be positive");
} else if (utilization <= 0.0 || utilization > 1.0) {
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 c3380b31..194efafd 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
@@ -48,9 +48,9 @@ public class SimRuntimeWorkload implements SimWorkload, FlowStageLogic {
* Construct a new {@link SimRuntimeWorkload}.
*
* @param duration The duration of the workload in milliseconds.
- * @param utilization A model of the CPU utilization of the application.
+ * @param utilization The CPU utilization of the workload.
*/
- public SimRuntimeWorkload(long duration, double utilization) {
+ SimRuntimeWorkload(long duration, double utilization) {
if (duration < 0) {
throw new IllegalArgumentException("Duration must be positive");
} else if (utilization <= 0.0 || utilization > 1.0) {
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.java b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.java
deleted file mode 100644
index f0e2561f..00000000
--- a/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (c) 2022 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.simulator.compute.workload;
-
-import java.util.HashSet;
-import org.opendc.simulator.compute.SimMachineContext;
-
-/**
- * A helper class to manage the lifecycle of a {@link SimWorkload}.
- */
-public final class SimWorkloadLifecycle {
- private final SimMachineContext ctx;
- private final HashSet<Runnable> waiting = new HashSet<>();
-
- /**
- * Construct a {@link SimWorkloadLifecycle} instance.
- *
- * @param ctx The {@link SimMachineContext} of the workload.
- */
- public SimWorkloadLifecycle(SimMachineContext ctx) {
- this.ctx = ctx;
- }
-
- /**
- * Register a "completer" callback that must be invoked before ending the lifecycle of the workload.
- */
- public Runnable newCompleter() {
- Runnable completer = new Runnable() {
- @Override
- public void run() {
- final HashSet<Runnable> waiting = SimWorkloadLifecycle.this.waiting;
- if (waiting.remove(this) && waiting.isEmpty()) {
- ctx.shutdown();
- }
- }
- };
- waiting.add(completer);
- return completer;
- }
-}
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
new file mode 100644
index 00000000..8655fd0a
--- /dev/null
+++ b/opendc-simulator/opendc-simulator-compute/src/main/java/org/opendc/simulator/compute/workload/SimWorkloads.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2022 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.simulator.compute.workload;
+
+import java.time.Duration;
+
+/**
+ * Helper methods for constructing {@link SimWorkload}s.
+ */
+public class SimWorkloads {
+ private SimWorkloads() {}
+
+ /**
+ * Create a {@link SimWorkload} that executes a specified number of floating point operations (FLOPs) at the given
+ * utilization.
+ *
+ * @param flops The number of floating point operations to perform for this task in MFLOPs.
+ * @param utilization The CPU utilization of the workload.
+ */
+ public static SimWorkload flops(long flops, double utilization) {
+ return new SimFlopsWorkload(flops, utilization);
+ }
+
+ /**
+ * 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) {
+ return new SimRuntimeWorkload(duration, utilization);
+ }
+
+ /**
+ * Create a {@link SimWorkload} that consumes the CPU resources for a specified duration at the given utilization.
+ *
+ * @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);
+ }
+}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
index f0aae15b..266839bd 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/SimMachineTest.kt
@@ -40,9 +40,9 @@ import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.model.StorageDevice
import org.opendc.simulator.compute.power.CpuPowerModels
-import org.opendc.simulator.compute.workload.SimFlopsWorkload
import org.opendc.simulator.compute.workload.SimTrace
import org.opendc.simulator.compute.workload.SimWorkload
+import org.opendc.simulator.compute.workload.SimWorkloads
import org.opendc.simulator.flow2.FlowEngine
import org.opendc.simulator.flow2.source.SimpleFlowSource
import org.opendc.simulator.kotlin.runSimulation
@@ -78,7 +78,7 @@ class SimMachineTest {
machineModel
)
- machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0))
+ machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0))
// Two cores execute 1000 MFlOps per second (1000 ms)
assertEquals(1000, clock.millis())
@@ -123,7 +123,7 @@ class SimMachineTest {
machineModel
)
- machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0))
+ machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0))
// Two sockets with two cores execute 2000 MFlOps per second (500 ms)
assertEquals(500, clock.millis())
@@ -142,7 +142,7 @@ class SimMachineTest {
source.connect(machine.psu)
coroutineScope {
- launch { machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0)) }
+ launch { machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0)) }
yield()
assertAll(
@@ -304,7 +304,7 @@ class SimMachineTest {
try {
coroutineScope {
- launch { machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0)) }
+ launch { machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0)) }
cancel()
}
} catch (_: CancellationException) {
@@ -326,11 +326,11 @@ class SimMachineTest {
coroutineScope {
launch {
- machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0))
+ machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0))
}
assertThrows<IllegalStateException> {
- machine.runWorkload(SimFlopsWorkload(2_000, /*utilization*/ 1.0))
+ machine.runWorkload(SimWorkloads.flops(2_000, /*utilization*/ 1.0))
}
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
index ba5a5c68..d11b91ee 100644
--- a/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/test/kotlin/org/opendc/simulator/compute/kernel/SimSpaceSharedHypervisorTest.kt
@@ -38,10 +38,9 @@ import org.opendc.simulator.compute.model.MemoryUnit
import org.opendc.simulator.compute.model.ProcessingNode
import org.opendc.simulator.compute.model.ProcessingUnit
import org.opendc.simulator.compute.runWorkload
-import org.opendc.simulator.compute.workload.SimFlopsWorkload
-import org.opendc.simulator.compute.workload.SimRuntimeWorkload
import org.opendc.simulator.compute.workload.SimTrace
import org.opendc.simulator.compute.workload.SimTraceFragment
+import org.opendc.simulator.compute.workload.SimWorkloads
import org.opendc.simulator.flow2.FlowEngine
import org.opendc.simulator.flow2.mux.FlowMultiplexerFactory
import org.opendc.simulator.kotlin.runSimulation
@@ -99,7 +98,7 @@ internal class SimSpaceSharedHypervisorTest {
@Test
fun testRuntimeWorkload() = runSimulation {
val duration = 5 * 60L * 1000
- val workload = SimRuntimeWorkload(duration, 1.0)
+ val workload = SimWorkloads.runtime(duration, 1.0)
val engine = FlowEngine.create(coroutineContext, clock)
val graph = engine.newGraph()
@@ -123,7 +122,7 @@ internal class SimSpaceSharedHypervisorTest {
@Test
fun testFlopsWorkload() = runSimulation {
val duration = 5 * 60L * 1000
- val workload = SimFlopsWorkload((duration * 3.2).toLong(), 1.0)
+ val workload = SimWorkloads.flops((duration * 3.2).toLong(), 1.0)
val engine = FlowEngine.create(coroutineContext, clock)
val graph = engine.newGraph()
@@ -155,13 +154,13 @@ internal class SimSpaceSharedHypervisorTest {
yield()
val vm = hypervisor.newMachine(machineModel)
- vm.runWorkload(SimRuntimeWorkload(duration, 1.0))
+ vm.runWorkload(SimWorkloads.runtime(duration, 1.0))
hypervisor.removeMachine(vm)
yield()
val vm2 = hypervisor.newMachine(machineModel)
- vm2.runWorkload(SimRuntimeWorkload(duration, 1.0))
+ vm2.runWorkload(SimWorkloads.runtime(duration, 1.0))
hypervisor.removeMachine(vm2)
machine.cancel()
@@ -184,7 +183,7 @@ internal class SimSpaceSharedHypervisorTest {
yield()
val vm = hypervisor.newMachine(machineModel)
- launch { vm.runWorkload(SimFlopsWorkload(10_000, 1.0)) }
+ launch { vm.runWorkload(SimWorkloads.runtime(10_000, 1.0)) }
yield()
assertAll(