From 7511fb768fab68d542adf5bbfb15e32300156c7e Mon Sep 17 00:00:00 2001 From: Dante Niewenhuis Date: Wed, 30 Oct 2024 17:35:06 +0100 Subject: Added power sources to OpenDC (#258) * Added power sources to OpenDC. In the current form each Cluster has a single power source that is connected to all hosts in that cluster * Added power sources to OpenDC. In the current form each Cluster has a single power source that is connected to all hosts in that cluster * Ran spotless Kotlin and Java --- .../opendc/compute/topology/TopologyFactories.kt | 35 ++++++++++++--------- .../opendc/compute/topology/specs/ClusterSpec.kt | 29 +++++++++++++++++ .../compute/topology/specs/PowerSourceSpec.kt | 33 ++++++++++++++++++++ .../opendc/compute/topology/specs/TopologySpecs.kt | 36 ++++++++++++++++++---- 4 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt create mode 100644 opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt (limited to 'opendc-compute/opendc-compute-topology/src') 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 3329f19c..76c653bf 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,9 +24,11 @@ package org.opendc.compute.topology +import org.opendc.compute.topology.specs.ClusterJSONSpec import org.opendc.compute.topology.specs.ClusterSpec import org.opendc.compute.topology.specs.HostJSONSpec import org.opendc.compute.topology.specs.HostSpec +import org.opendc.compute.topology.specs.PowerSourceSpec import org.opendc.compute.topology.specs.TopologySpec import org.opendc.simulator.compute.cpu.getPowerModel import org.opendc.simulator.compute.models.CpuModel @@ -49,7 +51,7 @@ private val reader = TopologyReader() public fun clusterTopology( pathToFile: String, random: RandomGenerator = SplittableRandom(0), -): List { +): List { return clusterTopology(File(pathToFile), random) } @@ -59,9 +61,9 @@ public fun clusterTopology( public fun clusterTopology( file: File, random: RandomGenerator = SplittableRandom(0), -): List { +): List { val topology = reader.read(file) - return topology.toHostSpecs(random) + return topology.toClusterSpec(random) } /** @@ -70,41 +72,44 @@ public fun clusterTopology( public fun clusterTopology( input: InputStream, random: RandomGenerator = SplittableRandom(0), -): List { +): List { val topology = reader.read(input) - return topology.toHostSpecs(random) + return topology.toClusterSpec(random) } /** * Helper method to convert a [TopologySpec] into a list of [HostSpec]s. */ -private fun TopologySpec.toHostSpecs(random: RandomGenerator): List { - return clusters.flatMap { cluster -> - List(cluster.count) { - cluster.toHostSpecs(random) - }.flatten() +private fun TopologySpec.toClusterSpec(random: RandomGenerator): List { + return clusters.map { cluster -> + cluster.toClusterSpec(random) } } /** - * Helper method to convert a [ClusterSpec] into a list of [HostSpec]s. + * Helper method to convert a [ClusterJSONSpec] into a list of [HostSpec]s. */ private var clusterId = 0 -private fun ClusterSpec.toHostSpecs(random: RandomGenerator): List { +private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec { val hostSpecs = hosts.flatMap { host -> ( List(host.count) { - host.toHostSpecs( + host.toHostSpec( clusterId, random, ) } ) } + val powerSourceSpec = + PowerSourceSpec( + UUID(random.nextLong(), (clusterId).toLong()), + totalPower = this.powerSource.totalPower, + ) clusterId++ - return hostSpecs + return ClusterSpec(this.name, hostSpecs, powerSourceSpec) } /** @@ -113,7 +118,7 @@ private fun ClusterSpec.toHostSpecs(random: RandomGenerator): List { private var hostId = 0 private var globalCoreId = 0 -private fun HostJSONSpec.toHostSpecs( +private fun HostJSONSpec.toHostSpec( clusterId: Int, random: RandomGenerator, ): HostSpec { diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt new file mode 100644 index 00000000..3b49b266 --- /dev/null +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/ClusterSpec.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.compute.topology.specs + +public data class ClusterSpec( + val name: String, + val hostSpecs: List, + val powerSource: PowerSourceSpec, +) diff --git a/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt new file mode 100644 index 00000000..79770684 --- /dev/null +++ b/opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 AtLarge Research + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.opendc.compute.topology.specs + +import java.util.UUID + +// TODO: add name to class +public data class PowerSourceSpec( + val uid: UUID, + val name: String = "unknown", + val meta: Map = emptyMap(), + val totalPower: Long, +) 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 974bb4a3..9acdf72a 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 @@ -34,7 +34,7 @@ import org.opendc.common.units.Power */ @Serializable public data class TopologySpec( - val clusters: List, + val clusters: List, val schemaVersion: Int = 1, ) @@ -46,10 +46,11 @@ public data class TopologySpec( * @param location Location of the cluster. This can impact the carbon intensity */ @Serializable -public data class ClusterSpec( +public data class ClusterJSONSpec( val name: String = "Cluster", val count: Int = 1, val hosts: List, + val powerSource: PowerSourceJSONSpec = PowerSourceJSONSpec.DFLT, val location: String = "NL", ) @@ -65,8 +66,8 @@ public data class ClusterSpec( @Serializable public data class HostJSONSpec( val name: String? = null, - val cpu: CPUSpec, - val memory: MemorySpec, + val cpu: CPUJSONSpec, + val memory: MemoryJSONSpec, val powerModel: PowerModelSpec = PowerModelSpec.DFLT, val count: Int = 1, ) @@ -81,7 +82,7 @@ public data class HostJSONSpec( * @param coreSpeed The speed of the cores */ @Serializable -public data class CPUSpec( +public data class CPUJSONSpec( val vendor: String = "unknown", val modelName: String = "unknown", val arch: String = "unknown", @@ -100,7 +101,7 @@ public data class CPUSpec( * @param memorySize The size of the memory Unit */ @Serializable -public data class MemorySpec( +public data class MemoryJSONSpec( val vendor: String = "unknown", val modelName: String = "unknown", val arch: String = "unknown", @@ -129,3 +130,26 @@ public data class PowerModelSpec( ) } } + +/** + * Definition of a power source used for JSON input. + * + * @property vendor + * @property modelName + * @property arch + * @property totalPower + */ +@Serializable +public data class PowerSourceJSONSpec( + val vendor: String = "unknown", + val modelName: String = "unknown", + val arch: String = "unknown", + val totalPower: Long, +) { + public companion object { + public val DFLT: PowerSourceJSONSpec = + PowerSourceJSONSpec( + totalPower = 10000, + ) + } +} -- cgit v1.2.3