diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-04-12 14:47:27 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2020-04-12 14:47:27 +0200 |
| commit | a584b53847ca6089d892a08fcd65b8694f262603 (patch) | |
| tree | db1dcb1e295adc6d65b0b0296420563b74ea248d | |
| parent | aa37f425959af99d22ee199f65e543c1711826ff (diff) | |
perf: Cache clock and job in VmImage
| -rw-r--r-- | opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt | 8 |
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) } } } |
