From a584b53847ca6089d892a08fcd65b8694f262603 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 12 Apr 2020 14:47:27 +0200 Subject: perf: Cache clock and job in VmImage --- .../main/kotlin/com/atlarge/opendc/compute/core/image/VmImage.kt | 8 ++++++-- 1 file 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) } } } -- cgit v1.2.3