summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-compute/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-compute/src')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt2
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt6
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt30
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt5
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt2
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt12
7 files changed, 44 insertions, 18 deletions
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
index 6a4c594d..e14ea507 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt
@@ -22,7 +22,6 @@
package org.opendc.simulator.compute
-import kotlinx.coroutines.*
import mu.KotlinLogging
import org.opendc.simulator.compute.device.SimNetworkAdapter
import org.opendc.simulator.compute.device.SimPeripheral
@@ -87,8 +86,8 @@ public abstract class SimAbstractMachine(
_ctx?.close()
}
- override fun onConverge(now: Long, delta: Long) {
- parent?.onConverge(now, delta)
+ override fun onConverge(now: Long) {
+ parent?.onConverge(now)
}
/**
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
index 5df03d45..68792c72 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimBareMetalMachine.kt
@@ -81,7 +81,7 @@ public class SimBareMetalMachine(
private var _lastConverge = Long.MAX_VALUE
- override fun onConverge(now: Long, delta: Long) {
+ override fun onConverge(now: Long) {
// Update the PSU stage
psu.update()
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
index 09defbb5..caff4dc3 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/device/SimPsu.kt
@@ -86,17 +86,17 @@ public class SimPsu(
conn.shouldSourceConverge = true
}
- override fun onStop(conn: FlowConnection, now: Long, delta: Long) {
+ override fun onStop(conn: FlowConnection, now: Long) {
_ctx = null
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
val powerDraw = computePowerDraw(_driver?.computePower() ?: 0.0)
conn.push(powerDraw)
return Long.MAX_VALUE
}
- override fun onConverge(conn: FlowConnection, now: Long, delta: Long) {
+ override fun onConverge(conn: FlowConnection, now: Long) {
_powerDraw = conn.rate
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
index 07465126..8e925bdf 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimAbstractHypervisor.kt
@@ -134,17 +134,24 @@ public abstract class SimAbstractHypervisor(
private var _cpuCount = 0
private var _cpuCapacity = 0.0
+ private var _lastConverge = engine.clock.millis()
/* FlowConvergenceListener */
- override fun onConverge(now: Long, delta: Long) {
- _counters.record()
+ override fun onConverge(now: Long) {
+ val lastConverge = _lastConverge
+ _lastConverge = now
+ val delta = now - lastConverge
+
+ if (delta > 0) {
+ _counters.record()
+ }
val load = cpuDemand / cpuCapacity
for (governor in governors) {
governor.onLimit(load)
}
- listener?.onConverge(now, delta)
+ listener?.onConverge(now)
}
/**
@@ -274,6 +281,10 @@ public abstract class SimAbstractHypervisor(
fun close() {
switch.removeInput(source)
}
+
+ fun flush() {
+ switch.flushCounters(source)
+ }
}
/**
@@ -337,6 +348,11 @@ public abstract class SimAbstractHypervisor(
cpuTime[2] += ((demandDelta - actualDelta) * d).roundToLong()
cpuTime[3] += (interferenceDelta * d).roundToLong()
}
+
+ override fun flush() {
+ hv.mux.flushCounters()
+ record()
+ }
}
/**
@@ -348,10 +364,16 @@ public abstract class SimAbstractHypervisor(
override val cpuActiveTime: Long
get() = (cpus.sumOf { it.counters.actual } * d).roundToLong()
override val cpuIdleTime: Long
- get() = (cpus.sumOf { it.counters.actual + it.counters.remaining } * d).roundToLong()
+ get() = (cpus.sumOf { it.counters.remaining } * d).roundToLong()
override val cpuStealTime: Long
get() = (cpus.sumOf { it.counters.demand - it.counters.actual } * d).roundToLong()
override val cpuLostTime: Long
get() = (cpus.sumOf { it.counters.interference } * d).roundToLong()
+
+ override fun flush() {
+ for (cpu in cpus) {
+ cpu.flush()
+ }
+ }
}
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt
index 030d9c5f..63fee507 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/kernel/SimHypervisorCounters.kt
@@ -45,4 +45,9 @@ public interface SimHypervisorCounters {
* The amount of CPU time (in milliseconds) that was lost due to interference between virtual machines.
*/
public val cpuLostTime: Long
+
+ /**
+ * Flush the counter values.
+ */
+ public fun flush()
}
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt
index 4cf60605..207e8579 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt
@@ -217,7 +217,7 @@ public class SimTrace(
*/
private var _idx = 0
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
val size = size
val nowOffset = now - offset
diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt
index 742470a1..46113bb0 100644
--- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt
+++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimWorkloadLifecycle.kt
@@ -61,17 +61,17 @@ public class SimWorkloadLifecycle(private val ctx: SimMachineContext) {
delegate.onStart(conn, now)
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
- return delegate.onPull(conn, now, delta)
+ override fun onPull(conn: FlowConnection, now: Long): Long {
+ return delegate.onPull(conn, now)
}
- override fun onConverge(conn: FlowConnection, now: Long, delta: Long) {
- delegate.onConverge(conn, now, delta)
+ override fun onConverge(conn: FlowConnection, now: Long) {
+ delegate.onConverge(conn, now)
}
- override fun onStop(conn: FlowConnection, now: Long, delta: Long) {
+ override fun onStop(conn: FlowConnection, now: Long) {
try {
- delegate.onStop(conn, now, delta)
+ delegate.onStop(conn, now)
} finally {
complete(this)
}