From 136c1b9ddc7bd9331d3552d681e9190fc6198271 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sat, 3 Oct 2020 17:41:59 +0200 Subject: Migrate codebase to opendc-simulator-compute This change updates the remainder of the codebase to use the opendc-simulator-compute module for the simulation of workloads. --- .../kotlin/org/opendc/simulator/compute/SimHypervisor.kt | 14 +++++++++----- .../opendc/simulator/compute/workload/SimTraceWorkload.kt | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'simulator/opendc-simulator') diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimHypervisor.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimHypervisor.kt index 7c2cfbe3..55eda70f 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimHypervisor.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimHypervisor.kt @@ -103,14 +103,15 @@ public class SimHypervisor( * Run the scheduling process of the hypervisor. */ override suspend fun run(ctx: SimExecutionContext) { - val maxUsage = ctx.machine.cpus.sumByDouble { it.frequency } - val pCPUs = ctx.machine.cpus.indices.sortedBy { ctx.machine.cpus[it].frequency } + val model = ctx.machine + val maxUsage = model.cpus.sumByDouble { it.frequency } + val pCPUs = model.cpus.indices.sortedBy { model.cpus[it].frequency } val vms = mutableSetOf() val vcpus = mutableListOf() - val usage = DoubleArray(ctx.machine.cpus.size) - val burst = LongArray(ctx.machine.cpus.size) + val usage = DoubleArray(model.cpus.size) + val burst = LongArray(model.cpus.size) fun process(command: SchedulerCommand) { when (command) { @@ -180,13 +181,16 @@ public class SimHypervisor( duration = min(duration, req.burst / grantedUsage) } + // XXX We set the minimum duration to 5 minutes here to prevent the rounding issues that are occurring with the FLOPs. + duration = 300.0 + val totalAllocatedUsage = maxUsage - availableUsage var totalAllocatedBurst = 0L availableUsage = totalAllocatedUsage // Divide the requests over the available capacity of the pCPUs fairly for (i in pCPUs) { - val maxCpuUsage = ctx.machine.cpus[i].frequency + val maxCpuUsage = model.cpus[i].frequency val fraction = maxCpuUsage / maxUsage val grantedUsage = min(maxCpuUsage, totalAllocatedUsage * fraction) val grantedBurst = ceil(duration * grantedUsage).toLong() diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt index e7eaa8bf..7b1ddf32 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTraceWorkload.kt @@ -29,7 +29,7 @@ import kotlin.math.min * A [SimWorkload] that replays a workload trace consisting of multiple fragments, each indicating the resource * consumption for some period of time. */ -public class SimTraceWorkload(private val trace: Sequence) : SimWorkload { +public class SimTraceWorkload(public val trace: Sequence) : SimWorkload { override suspend fun run(ctx: SimExecutionContext) { var offset = ctx.clock.millis() -- cgit v1.2.3