From 2dc44c7283200f4689cc1be15115a8b1cd37d456 Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Mon, 29 Apr 2024 12:48:20 +0200 Subject: Fixed several cpu related bugs, changed input topology (#226) --- .../compute/service/scheduler/filters/VCpuFilter.kt | 10 +++++----- .../kotlin/org/opendc/compute/simulator/SimHost.kt | 2 +- .../org/opendc/compute/topology/TopologyFactories.kt | 19 +++---------------- .../org/opendc/compute/topology/specs/JSONSpecs.kt | 4 ++-- 4 files changed, 11 insertions(+), 24 deletions(-) (limited to 'opendc-compute') diff --git a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/filters/VCpuFilter.kt b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/filters/VCpuFilter.kt index 451ea4b6..cefb3f7a 100644 --- a/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/filters/VCpuFilter.kt +++ b/opendc-compute/opendc-compute-service/src/main/kotlin/org/opendc/compute/service/scheduler/filters/VCpuFilter.kt @@ -36,15 +36,15 @@ public class VCpuFilter(private val allocationRatio: Double) : HostFilter { server: Server, ): Boolean { val requested = server.flavor.coreCount - val total = host.host.model.coreCount - val limit = total * allocationRatio + val totalCores = host.host.model.coreCount + val limit = totalCores * allocationRatio // Do not allow an instance to overcommit against itself, only against other instances - if (requested > total) { + if (requested > totalCores) { return false } - val free = limit - host.provisionedCores - return free >= requested + val availableCores = limit - host.provisionedCores + return availableCores >= requested } } diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt index bfd21a3c..84799123 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt +++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/SimHost.kt @@ -146,7 +146,7 @@ public class SimHost( override fun canFit(server: Server): Boolean { val sufficientMemory = model.memoryCapacity >= server.flavor.memorySize - val enoughCpus = model.cpuCount >= server.flavor.coreCount + val enoughCpus = model.coreCount >= server.flavor.coreCount val canFit = hypervisor.canFit(server.flavor.toMachineModel()) return sufficientMemory && enoughCpus && canFit diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt index f8c7afbd..549086d4 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt @@ -24,7 +24,6 @@ package org.opendc.compute.topology -import org.opendc.compute.topology.specs.CPUJSONSpec import org.opendc.compute.topology.specs.ClusterJSONSpec import org.opendc.compute.topology.specs.HostJSONSpec import org.opendc.compute.topology.specs.HostSpec @@ -104,14 +103,14 @@ private fun ClusterJSONSpec.toHostSpecs(random: RandomGenerator): List * Helper method to convert a [HostJSONSpec] into a [HostSpec]s. */ private var hostId = 0 +private var globalCoreId = 0 private fun HostJSONSpec.toHostSpecs( clusterId: Int, random: RandomGenerator, ): HostSpec { - val unknownProcessingNode = ProcessingNode("unknown", "unknown", "unknown", cpus.sumOf { it.coreCount }) - - val units = cpus.flatMap { cpu -> List(cpu.count) { cpu.toProcessingUnits(unknownProcessingNode) }.flatten() } + val unknownProcessingNode = ProcessingNode("unknown", "unknown", "unknown", cpu.coreCount) + val units = List(cpu.count) { ProcessingUnit(unknownProcessingNode, globalCoreId++, cpu.coreSpeed) } val unknownMemoryUnit = MemoryUnit(memory.vendor, memory.modelName, memory.memorySpeed, memory.memorySize) val machineModel = @@ -134,15 +133,3 @@ private fun HostJSONSpec.toHostSpecs( return hostSpec } - -/** - * Helper method to convert a [CPUJSONSpec] into a list of [ProcessingUnit]s. - */ -private var globalCoreId = 0 - -private fun CPUJSONSpec.toProcessingUnits(unknownProcessingNode: ProcessingNode): List { - val units = List(coreCount) { ProcessingUnit(unknownProcessingNode, globalCoreId++, coreSpeed) } - return units - -// return listOf(ProcessingUnit(unknownProcessingNode, globalCoreId++, coreSpeed)) -} diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt index 8f73f524..2bfed502 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/JSONSpecs.kt @@ -54,7 +54,7 @@ public data class ClusterJSONSpec( * Definition of a compute host modeled in the simulation. * * @param name The name of the host. - * @param cpus List of the different CPUs available in this cluster + * @param cpu The CPU available in this cluster * @param memory The amount of RAM memory available in Byte * @param powerModel The power model used to determine the power draw of a host * @param count The power model used to determine the power draw of a host @@ -62,7 +62,7 @@ public data class ClusterJSONSpec( @Serializable public data class HostJSONSpec( val name: String = "Host", - val cpus: List, + val cpu: CPUJSONSpec, val memory: MemoryJSONSpec, val powerModel: PowerModelJSONSpec = PowerModelJSONSpec("linear", 350.0, 400.0, 200.0), val count: Int = 1, -- cgit v1.2.3