From 4f98fb2bf8204f6af52cd6eeb3313d21c6ca95bc Mon Sep 17 00:00:00 2001 From: Alessio Leonardo Tomei <122273875+T0mexX@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:40:57 +0200 Subject: Added Unit of measurament system with new deserialization (#242) --- .../opendc/compute/topology/TopologyFactories.kt | 7 +++-- .../opendc/compute/topology/specs/TopologySpecs.kt | 33 +++++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'opendc-compute') 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 656085e8..d4d4bfe3 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 @@ -120,16 +120,17 @@ private fun HostJSONSpec.toHostSpecs( random: RandomGenerator, ): HostSpec { val unknownProcessingNode = ProcessingNode("unknown", "unknown", "unknown", cpu.coreCount) - val units = List(cpu.count) { ProcessingUnit(unknownProcessingNode, globalCoreId++, cpu.coreSpeed) } + val units = List(cpu.count) { ProcessingUnit(unknownProcessingNode, globalCoreId++, cpu.coreSpeed.toMHz()) } - val unknownMemoryUnit = MemoryUnit(memory.vendor, memory.modelName, memory.memorySpeed, memory.memorySize) + val unknownMemoryUnit = MemoryUnit(memory.vendor, memory.modelName, memory.memorySpeed.toMHz(), memory.memorySize.toMiB().toLong()) val machineModel = MachineModel( units, listOf(unknownMemoryUnit), ) - val powerModel = getPowerModel(powerModel.modelType, powerModel.power, powerModel.maxPower, powerModel.idlePower) + val powerModel = + getPowerModel(powerModel.modelType, powerModel.power.toWatts(), powerModel.maxPower.toWatts(), powerModel.idlePower.toWatts()) var hostName: String if (name == null) { diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt index 110d6fb1..974bb4a3 100644 --- a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt @@ -23,6 +23,9 @@ package org.opendc.compute.topology.specs import kotlinx.serialization.Serializable +import org.opendc.common.units.DataSize +import org.opendc.common.units.Frequency +import org.opendc.common.units.Power /** * Definition of a Topology modeled in the simulation. @@ -64,7 +67,7 @@ public data class HostJSONSpec( val name: String? = null, val cpu: CPUSpec, val memory: MemorySpec, - val powerModel: PowerModelSpec = PowerModelSpec("linear", 350.0, 400.0, 200.0), + val powerModel: PowerModelSpec = PowerModelSpec.DFLT, val count: Int = 1, ) @@ -75,7 +78,7 @@ public data class HostJSONSpec( * @param modelName The model name of the device. * @param arch The micro-architecture of the processor node. * @param coreCount The number of cores in the CPU - * @param coreSpeed The speed of the cores in Mhz + * @param coreSpeed The speed of the cores */ @Serializable public data class CPUSpec( @@ -83,7 +86,7 @@ public data class CPUSpec( val modelName: String = "unknown", val arch: String = "unknown", val coreCount: Int, - val coreSpeed: Double, + val coreSpeed: Frequency, val count: Int = 1, ) @@ -93,26 +96,36 @@ public data class CPUSpec( * @param vendor The vendor of the storage device. * @param modelName The model name of the device. * @param arch The micro-architecture of the processor node. - * @param memorySpeed The speed of the cores in ? - * @param memorySize The size of the memory Unit in MiB + * @param memorySpeed The speed of the cores + * @param memorySize The size of the memory Unit */ @Serializable public data class MemorySpec( val vendor: String = "unknown", val modelName: String = "unknown", val arch: String = "unknown", - val memorySpeed: Double = -1.0, - val memorySize: Long, + val memorySpeed: Frequency = Frequency.ofMHz(-1), + val memorySize: DataSize, ) @Serializable public data class PowerModelSpec( val modelType: String, - val power: Double = 400.0, - val maxPower: Double, - val idlePower: Double, + val power: Power = Power.ofWatts(400), + val maxPower: Power, + val idlePower: Power, ) { init { require(maxPower >= idlePower) { "The max power of a power model can not be less than the idle power" } } + + public companion object { + public val DFLT: PowerModelSpec = + PowerModelSpec( + modelType = "linear", + power = Power.ofWatts(350), + maxPower = Power.ofWatts(400.0), + idlePower = Power.ofWatts(200.0), + ) + } } -- cgit v1.2.3