diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-01-12 23:17:33 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-02-18 20:05:10 +0100 |
| commit | 5a0821e19eed87e91054289051213cb60b4235b4 (patch) | |
| tree | 3737158b657c8cb2f102621f90d7f5dedddaba77 /opendc-experiments/opendc-experiments-tf20/src | |
| parent | 9e69eaf1c7b0c4985d37f3f4595e2e2478d389f2 (diff) | |
refactor(simulator): Remove delta parameter from flow callbacks
This change removes the delta parameter from the callbacks of the flow
framework. This parameter was used to indicate the duration in time
between the last call and the current call. However, its usefulness was
limited since the actual delta values needed by implementors of this
method had to be bridged across different flow callbacks.
Diffstat (limited to 'opendc-experiments/opendc-experiments-tf20/src')
| -rw-r--r-- | opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt index c751463d..5245261c 100644 --- a/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt +++ b/opendc-experiments/opendc-experiments-tf20/src/main/kotlin/org/opendc/experiments/tf20/core/SimTFDevice.kt @@ -120,6 +120,11 @@ public class SimTFDevice( */ private var activeWork: Work? = null + /** + * The timestamp of the last pull. + */ + private var lastPull: Long = 0L + override fun onStart(ctx: SimMachineContext) { for (cpu in ctx.cpus) { cpu.startConsumer(this) @@ -131,11 +136,15 @@ public class SimTFDevice( override fun onStart(conn: FlowConnection, now: Long) { ctx = conn capacity = conn.capacity - + lastPull = now conn.shouldSourceConverge = true } - override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long { + override fun onPull(conn: FlowConnection, now: Long): Long { + val lastPull = lastPull + this.lastPull = now + val delta = (now - lastPull).coerceAtLeast(0) + val consumedWork = conn.rate * delta / 1000.0 capacity = conn.capacity @@ -164,7 +173,7 @@ public class SimTFDevice( } } - override fun onConverge(conn: FlowConnection, now: Long, delta: Long) { + override fun onConverge(conn: FlowConnection, now: Long) { _usage.record(conn.rate) _power.record(machine.psu.powerDraw) } |
