summaryrefslogtreecommitdiff
path: root/opendc
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2020-04-12 14:47:27 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-04-12 14:47:27 +0200
commita584b53847ca6089d892a08fcd65b8694f262603 (patch)
treedb1dcb1e295adc6d65b0b0296420563b74ea248d /opendc
parentaa37f425959af99d22ee199f65e543c1711826ff (diff)
perf: Cache clock and job in VmImage
Diffstat (limited to 'opendc')
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt8
1 files changed, 6 insertions, 2 deletions
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
index b2a01804..b0688f99 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt
@@ -3,6 +3,7 @@ package com.atlarge.opendc.compute.core.image
import com.atlarge.odcsim.simulationContext
import com.atlarge.opendc.compute.core.execution.ServerContext
import com.atlarge.opendc.core.resource.TagContainer
+import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import java.util.UUID
@@ -19,8 +20,11 @@ class VmImage(
) : Image {
override suspend fun invoke(ctx: ServerContext) {
+ val clock = simulationContext.clock
+ val job = coroutineContext[Job]!!
+
for (fragment in flopsHistory) {
- coroutineContext.ensureActive()
+ job.ensureActive()
if (fragment.flops == 0L) {
delay(fragment.duration)
@@ -29,7 +33,7 @@ class VmImage(
val burst = LongArray(cores) { fragment.flops / cores }
val usage = DoubleArray(cores) { fragment.usage / cores }
- ctx.run(burst, usage, simulationContext.clock.millis() + fragment.duration)
+ ctx.run(burst, usage, clock.millis() + fragment.duration)
}
}
}