summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildSrc/src/main/kotlin/library.kt2
-rw-r--r--opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt19
-rw-r--r--opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/experiment/ExperimentHelpers.kt2
3 files changed, 18 insertions, 5 deletions
diff --git a/buildSrc/src/main/kotlin/library.kt b/buildSrc/src/main/kotlin/library.kt
index de88f114..1a3c30a6 100644
--- a/buildSrc/src/main/kotlin/library.kt
+++ b/buildSrc/src/main/kotlin/library.kt
@@ -45,5 +45,5 @@ object Library {
/**
* Kotlin coroutines support
*/
- val KOTLINX_COROUTINES = "1.3.6"
+ val KOTLINX_COROUTINES = "1.3.7"
}
diff --git a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt
index 45dcae23..a0ca2347 100644
--- a/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt
+++ b/opendc/opendc-compute/src/main/kotlin/com/atlarge/opendc/compute/metal/driver/SimpleBareMetalDriver.kt
@@ -49,10 +49,12 @@ import com.atlarge.opendc.core.services.ServiceRegistry
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Delay
import kotlinx.coroutines.DisposableHandle
+import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.intrinsics.startCoroutineCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.selects.SelectClause0
@@ -63,6 +65,7 @@ import kotlin.math.max
import kotlin.math.min
import kotlinx.coroutines.withContext
import java.lang.Exception
+import java.time.Clock
import kotlin.coroutines.ContinuationInterceptor
import kotlin.random.Random
@@ -77,6 +80,7 @@ import kotlin.random.Random
* @param memoryUnits The memory units in this machine.
* @param powerModel The power model of this machine.
*/
+@OptIn(ExperimentalCoroutinesApi::class)
public class SimpleBareMetalDriver(
private val domain: Domain,
uid: UUID,
@@ -106,7 +110,7 @@ public class SimpleBareMetalDriver(
/**
* The flow containing the load of the server.
*/
- private val usageState = StateFlow(0.0)
+ private val usageState = MutableStateFlow(0.0)
/**
* The machine state.
@@ -260,6 +264,17 @@ public class SimpleBareMetalDriver(
*/
private var usageFlush: DisposableHandle? = null
+ /**
+ * Cache the [Clock] for timing.
+ */
+ private val clock= domain.coroutineContext[SimulationContext]!!.clock
+
+ /**
+ * Cache the [Delay] instance for timing. Ugly hack which may break in the future.
+ */
+ @OptIn(InternalCoroutinesApi::class)
+ private val delay = domain.coroutineContext[ContinuationInterceptor] as Delay
+
@OptIn(InternalCoroutinesApi::class)
override fun onRun(
batch: Sequence<ServerContext.Slice>,
@@ -276,8 +291,6 @@ public class SimpleBareMetalDriver(
usageFlush = null
val context = select.completion.context
- val clock = context[SimulationContext]!!.clock
- val delay = context[ContinuationInterceptor] as Delay
val queue = batch.iterator()
var start = Long.MIN_VALUE
diff --git a/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/experiment/ExperimentHelpers.kt b/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/experiment/ExperimentHelpers.kt
index 83952d43..ec61ac38 100644
--- a/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/experiment/ExperimentHelpers.kt
+++ b/opendc/opendc-experiments-sc20/src/main/kotlin/com/atlarge/opendc/experiments/sc20/experiment/ExperimentHelpers.kt
@@ -172,7 +172,7 @@ suspend fun attachMonitor(scheduler: SimpleVirtProvisioningService, monitor: Exp
.onEach { event ->
when (event) {
is HypervisorEvent.SliceFinished -> monitor.reportHostSlice(
- simulationContext.clock.millis(),
+ clock.millis(),
event.requestedBurst,
event.grantedBurst,
event.overcommissionedBurst,