summaryrefslogtreecommitdiff
path: root/opendc-compute
diff options
context:
space:
mode:
authorDante Niewenhuis <d.niewenhuis@hotmail.com>2024-11-03 20:00:26 +0100
committerGitHub <noreply@github.com>2024-11-03 20:00:26 +0100
commitf3e578a2a43c99997dbf35e09debfde255a4ae22 (patch)
tree312dde871072cff0468d2a5a11cd671d85063220 /opendc-compute
parent6fa203b9187b474816e7719baed8c97eadd689cb (diff)
Rewritten the Carbon model (#260)
Diffstat (limited to 'opendc-compute')
-rw-r--r--opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTrace.kt113
-rw-r--r--opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceLoader.kt15
-rw-r--r--opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceReader.kt15
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java7
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt3
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt7
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt11
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt4
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt10
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt10
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt17
-rw-r--r--opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt12
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/TopologyFactories.kt1
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/PowerSourceSpec.kt3
-rw-r--r--opendc-compute/opendc-compute-topology/src/main/kotlin/org/opendc/compute/topology/specs/TopologySpecs.kt4
15 files changed, 44 insertions, 188 deletions
diff --git a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTrace.kt b/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTrace.kt
deleted file mode 100644
index 2ba3e4e3..00000000
--- a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTrace.kt
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (c) 2021 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.carbon
-
-import java.time.Instant
-
-/**
- * A virtual machine workload.
- *
- * @param uid The unique identifier of the virtual machine.
- * @param name The name of the virtual machine.
- * @param cpuCapacity The required CPU capacity for the VM in MHz.
- * @param cpuCount The number of vCPUs in the VM.
- * @param memCapacity The provisioned memory for the VM in MB.
- * @param startTime The start time of the VM.
- * @param stopTime The stop time of the VM.
- * @param trace The trace that belong to this VM.
- * @param interferenceProfile The interference profile of this virtual machine.
- */
-public data class CarbonFragment(
- var startTime: Long,
- var endTime: Long,
- var carbonIntensity: Double,
-) {
- init {
- require(endTime > startTime) {
- "The end time of a report should be higher than the start time -> start time: $startTime, end time: $endTime"
- }
- require(carbonIntensity >= 0.0) { "carbon intensity cannot be negative" }
- }
-}
-
-public class CarbonTrace(reports: List<CarbonFragment>? = null) {
- private var index: Int = 0
- private val numberOfReports = reports?.size
- private val reports = reports?.sortedBy { it.startTime }
-
- private fun hasPreviousReport(): Boolean {
- return index > 0
- }
-
- private fun hasNextReport(): Boolean {
- if (numberOfReports == null) {
- return false
- }
-
- return index < numberOfReports
- }
-
- public fun getCarbonIntensity(timestamp: Instant): Double {
- return getCarbonIntensity(timestamp.toEpochMilli())
- }
-
- /**
- * Get the carbon intensity of the energy at a given timestamp
- * Returns the carbon intensity of the first or last [CarbonFragment]
- * if the given timestamp is outside the information
- *
- * @param timestamp
- * @return The carbon intensity at the given timestamp in gCO2/kWh
- */
- public fun getCarbonIntensity(timestamp: Long): Double {
- if (reports == null) {
- return 0.0
- }
-
- var currentFragment: CarbonFragment
-
- while (true) {
- currentFragment = reports[index]
-
- if (currentFragment.startTime > timestamp) {
- if (hasPreviousReport()) {
- index--
- continue
- }
- break
- }
-
- if (currentFragment.endTime <= timestamp) {
- if (hasNextReport()) {
- index++
- continue
- }
- break
- }
-
- break
- }
-
- return currentFragment.carbonIntensity
- }
-}
diff --git a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceLoader.kt b/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceLoader.kt
index b66aedf9..ccf1d81c 100644
--- a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceLoader.kt
+++ b/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceLoader.kt
@@ -22,6 +22,7 @@
package org.opendc.compute.carbon
+import org.opendc.simulator.compute.power.CarbonFragmentNew
import org.opendc.trace.Trace
import org.opendc.trace.conv.CARBON_INTENSITY_TIMESTAMP
import org.opendc.trace.conv.CARBON_INTENSITY_VALUE
@@ -40,14 +41,14 @@ public class CarbonTraceLoader {
/**
* The cache of workloads.
*/
- private val cache = ConcurrentHashMap<String, SoftReference<List<CarbonFragment>>>()
+ private val cache = ConcurrentHashMap<String, SoftReference<List<CarbonFragmentNew>>>()
- private val builder = CarbonFragmentBuilder()
+ private val builder = CarbonFragmentNewBuilder()
/**
* Read the metadata into a workload.
*/
- private fun parseCarbon(trace: Trace): List<CarbonFragment> {
+ private fun parseCarbon(trace: Trace): List<CarbonFragmentNew> {
val reader = checkNotNull(trace.getTable(TABLE_CARBON_INTENSITIES)).newReader()
val startTimeCol = reader.resolve(CARBON_INTENSITY_TIMESTAMP)
@@ -76,7 +77,7 @@ public class CarbonTraceLoader {
/**
* Load the trace with the specified [name] and [format].
*/
- public fun get(pathToFile: File): List<CarbonFragment> {
+ public fun get(pathToFile: File): List<CarbonFragmentNew> {
val trace = Trace.open(pathToFile, "carbon")
return parseCarbon(trace)
@@ -92,11 +93,11 @@ public class CarbonTraceLoader {
/**
* A builder for a VM trace.
*/
- private class CarbonFragmentBuilder {
+ private class CarbonFragmentNewBuilder {
/**
* The total load of the trace.
*/
- public val fragments: MutableList<CarbonFragment> = mutableListOf<CarbonFragment>()
+ public val fragments: MutableList<CarbonFragmentNew> = mutableListOf()
/**
* Add a fragment to the trace.
@@ -109,7 +110,7 @@ public class CarbonTraceLoader {
carbonIntensity: Double,
) {
fragments.add(
- CarbonFragment(startTime.toEpochMilli(), Long.MAX_VALUE, carbonIntensity),
+ CarbonFragmentNew(startTime.toEpochMilli(), Long.MAX_VALUE, carbonIntensity),
)
}
diff --git a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceReader.kt b/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceReader.kt
index 3e0269f8..0b2b07a1 100644
--- a/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceReader.kt
+++ b/opendc-compute/opendc-compute-carbon/src/main/kotlin/org/opendc/compute/carbon/CarbonTraceReader.kt
@@ -20,33 +20,32 @@
* SOFTWARE.
*/
-@file:JvmName("ComputeWorkloads")
+@file:JvmName("ComputeWorkloadsNew")
package org.opendc.compute.carbon
+import org.opendc.simulator.compute.power.CarbonFragmentNew
import java.io.File
import javax.management.InvalidAttributeValueException
/**
* Construct a workload from a trace.
*/
-public fun getCarbonTrace(pathToFile: String?): CarbonTrace {
+public fun getCarbonFragments(pathToFile: String?): List<CarbonFragmentNew>? {
if (pathToFile == null) {
- return CarbonTrace(null)
+ return null
}
- return getCarbonTrace(File(pathToFile))
+ return getCarbonFragments(File(pathToFile))
}
/**
* Construct a workload from a trace.
*/
-public fun getCarbonTrace(file: File): CarbonTrace {
+public fun getCarbonFragments(file: File): List<CarbonFragmentNew> {
if (!file.exists()) {
throw InvalidAttributeValueException("The carbon trace cannot be found")
}
- val fragments = CarbonTraceLoader().get(file)
-
- return CarbonTrace(fragments)
+ return CarbonTraceLoader().get(file)
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java
index 8df0d7d8..b6a69209 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java
+++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java
@@ -346,8 +346,11 @@ public final class ComputeService implements AutoCloseable {
public void setTaskToBeRemoved(ServiceTask task) {
this.tasksToRemove.add(task);
- if ((tasksTerminated + tasksCompleted) == tasksExpected) {
- metricReader.loggState(); // Logg the state for the final time. This will also delete all remaining tasks.
+ if ((this.tasksTerminated + this.tasksCompleted) == this.tasksExpected) {
+ if (this.metricReader != null) {
+ this.metricReader
+ .loggState(); // Logg the state for the final time. This will also delete all remaining tasks.
+ }
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
index da6dcfbc..29e9d541 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeMonitorProvisioningStep.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.provisioner
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.telemetry.ComputeMetricReader
import org.opendc.compute.simulator.telemetry.ComputeMonitor
@@ -37,7 +36,6 @@ public class ComputeMonitorProvisioningStep(
private val monitor: ComputeMonitor,
private val exportInterval: Duration,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
@@ -51,7 +49,6 @@ public class ComputeMonitorProvisioningStep(
monitor,
exportInterval,
startTime,
- carbonTrace,
)
return metricReader
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
index d8bb703e..7d9cae60 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/ComputeSteps.kt
@@ -24,7 +24,6 @@
package org.opendc.compute.simulator.provisioner
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.scheduler.ComputeScheduler
import org.opendc.compute.simulator.telemetry.ComputeMonitor
import org.opendc.compute.topology.specs.ClusterSpec
@@ -60,9 +59,8 @@ public fun registerComputeMonitor(
monitor: ComputeMonitor,
exportInterval: Duration = Duration.ofMinutes(5),
startTime: Duration = Duration.ofMillis(0),
- carbonTrace: CarbonTrace = CarbonTrace(null),
): ProvisioningStep {
- return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime, carbonTrace)
+ return ComputeMonitorProvisioningStep(serviceDomain, monitor, exportInterval, startTime)
}
/**
@@ -76,6 +74,7 @@ public fun registerComputeMonitor(
public fun setupHosts(
serviceDomain: String,
specs: List<ClusterSpec>,
+ startTime: Long = 0L,
): ProvisioningStep {
- return HostsProvisioningStep(serviceDomain, specs)
+ return HostsProvisioningStep(serviceDomain, specs, startTime)
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
index d2231f0d..8e7293c8 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/provisioner/HostsProvisioningStep.kt
@@ -22,6 +22,7 @@
package org.opendc.compute.simulator.provisioner
+import org.opendc.compute.carbon.getCarbonFragments
import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.topology.specs.ClusterSpec
@@ -40,6 +41,7 @@ import org.opendc.simulator.engine.FlowEngine
public class HostsProvisioningStep internal constructor(
private val serviceDomain: String,
private val clusterSpecs: List<ClusterSpec>,
+ private val startTime: Long = 0L,
) : ProvisioningStep {
override fun apply(ctx: ProvisioningContext): AutoCloseable {
val service =
@@ -54,8 +56,11 @@ public class HostsProvisioningStep internal constructor(
for (cluster in clusterSpecs) {
// Create the Power Source to which hosts are connected
- // TODO: Add connection to totalPower
- val simPowerSource = SimPowerSource(graph)
+
+ val carbonFragments = getCarbonFragments(cluster.powerSource.carbonTracePath)
+
+ val simPowerSource = SimPowerSource(graph, cluster.powerSource.totalPower.toDouble(), carbonFragments, startTime)
+
service.addPowerSource(simPowerSource)
simPowerSources.add(simPowerSource)
@@ -88,7 +93,7 @@ public class HostsProvisioningStep internal constructor(
for (simPowerSource in simPowerSources) {
// TODO: add close function
-// simPowerSource.close()
+ simPowerSource.close()
}
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt
index 3098ed55..5dab5d7a 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/ComputeMetricReader.kt
@@ -29,7 +29,6 @@ import kotlinx.coroutines.launch
import mu.KotlinLogging
import org.opendc.common.Dispatcher
import org.opendc.common.asCoroutineDispatcher
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.host.SimHost
import org.opendc.compute.simulator.service.ComputeService
import org.opendc.compute.simulator.service.ServiceTask
@@ -55,7 +54,6 @@ public class ComputeMetricReader(
private val monitor: ComputeMonitor,
private val exportInterval: Duration = Duration.ofMinutes(5),
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : AutoCloseable {
private val logger = KotlinLogging.logger {}
private val scope = CoroutineScope(dispatcher.asCoroutineDispatcher())
@@ -119,7 +117,6 @@ public class ComputeMetricReader(
HostTableReaderImpl(
it,
startTime,
- carbonTrace,
)
}
reader.record(now)
@@ -152,7 +149,6 @@ public class ComputeMetricReader(
PowerSourceTableReaderImpl(
it,
startTime,
- carbonTrace,
)
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
index 1b76da6b..805b224d 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/parquet/DfltHostExportColumns.kt
@@ -154,16 +154,6 @@ public object DfltHostExportColumns {
field = Types.required(FLOAT).named("energy_usage"),
) { it.energyUsage }
- public val CARBON_INTENSITY: ExportColumn<HostTableReader> =
- ExportColumn(
- field = Types.required(FLOAT).named("carbon_intensity"),
- ) { it.carbonIntensity }
-
- public val CARBON_EMISSION: ExportColumn<HostTableReader> =
- ExportColumn(
- field = Types.required(FLOAT).named("carbon_emission"),
- ) { it.carbonEmission }
-
public val UP_TIME: ExportColumn<HostTableReader> =
ExportColumn(
field = Types.required(INT64).named("uptime"),
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
index cf8d3c8c..35565f82 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReader.kt
@@ -123,16 +123,6 @@ public interface HostTableReader : Exportable {
public val energyUsage: Double
/**
- * The current carbon intensity of the host in gCO2 / kW.
- */
- public val carbonIntensity: Double
-
- /**
- * The current carbon emission since the last deadline in g.
- */
- public val carbonEmission: Double
-
- /**
* The uptime of the host since last time in ms.
*/
public val uptime: Long
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
index ab8c0036..90f091f2 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/HostTableReaderImpl.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.telemetry.table
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.compute.simulator.host.SimHost
import java.time.Duration
import java.time.Instant
@@ -33,7 +32,6 @@ import java.time.Instant
public class HostTableReaderImpl(
host: SimHost,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : HostTableReader {
override fun copy(): HostTableReader {
val newHostTable =
@@ -61,8 +59,6 @@ public class HostTableReaderImpl(
_cpuLostTime = table.cpuLostTime
_powerDraw = table.powerDraw
_energyUsage = table.energyUsage
- _carbonIntensity = table.carbonIntensity
- _carbonEmission = table.carbonEmission
_uptime = table.uptime
_downtime = table.downtime
_bootTime = table.bootTime
@@ -150,14 +146,6 @@ public class HostTableReaderImpl(
private var _energyUsage = 0.0
private var previousEnergyUsage = 0.0
- override val carbonIntensity: Double
- get() = _carbonIntensity
- private var _carbonIntensity = 0.0
-
- override val carbonEmission: Double
- get() = _carbonEmission
- private var _carbonEmission = 0.0
-
override val uptime: Long
get() = _uptime - previousUptime
private var _uptime = 0L
@@ -200,9 +188,6 @@ public class HostTableReaderImpl(
_cpuLostTime = hostCpuStats.lostTime
_powerDraw = hostSysStats.powerDraw
_energyUsage = hostSysStats.energyUsage
- _carbonIntensity = carbonTrace.getCarbonIntensity(timestampAbsolute)
-
- _carbonEmission = carbonIntensity * (energyUsage / 3600000.0) // convert energy usage from J to kWh
_uptime = hostSysStats.uptime.toMillis()
_downtime = hostSysStats.downtime.toMillis()
_bootTime = hostSysStats.bootTime
@@ -234,7 +219,5 @@ public class HostTableReaderImpl(
_powerDraw = 0.0
_energyUsage = 0.0
- _carbonIntensity = 0.0
- _carbonEmission = 0.0
}
}
diff --git a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
index 91918ea8..6a44d1ea 100644
--- a/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
+++ b/opendc-compute/opendc-compute-simulator/src/main/kotlin/org/opendc/compute/simulator/telemetry/table/PowerSourceTableReaderImpl.kt
@@ -22,7 +22,6 @@
package org.opendc.compute.simulator.telemetry.table
-import org.opendc.compute.carbon.CarbonTrace
import org.opendc.simulator.compute.power.SimPowerSource
import java.time.Duration
import java.time.Instant
@@ -33,7 +32,6 @@ import java.time.Instant
public class PowerSourceTableReaderImpl(
powerSource: SimPowerSource,
private val startTime: Duration = Duration.ofMillis(0),
- private val carbonTrace: CarbonTrace = CarbonTrace(null),
) : PowerSourceTableReader {
override fun copy(): PowerSourceTableReader {
val newPowerSourceTable =
@@ -84,8 +82,9 @@ public class PowerSourceTableReaderImpl(
private var _carbonIntensity = 0.0
override val carbonEmission: Double
- get() = _carbonEmission
+ get() = _carbonEmission - previousCarbonEmission
private var _carbonEmission = 0.0
+ private var previousCarbonEmission = 0.0
/**
* Record the next cycle.
@@ -95,10 +94,12 @@ public class PowerSourceTableReaderImpl(
_timestampAbsolute = now + startTime
_hostsConnected = 0
+
+ powerSource.updateCounters()
_powerDraw = powerSource.powerDraw
_energyUsage = powerSource.energyUsage
- _carbonIntensity = 0.0
- _carbonEmission = carbonIntensity * (energyUsage / 3600000.0)
+ _carbonIntensity = powerSource.carbonIntensity
+ _carbonEmission = powerSource.carbonEmission
}
/**
@@ -106,6 +107,7 @@ public class PowerSourceTableReaderImpl(
*/
override fun reset() {
previousEnergyUsage = _energyUsage
+ previousCarbonEmission = _carbonEmission
_hostsConnected = 0
_powerDraw = 0.0
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 76c653bf..f271c028 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
@@ -107,6 +107,7 @@ private fun ClusterJSONSpec.toClusterSpec(random: RandomGenerator): ClusterSpec
PowerSourceSpec(
UUID(random.nextLong(), (clusterId).toLong()),
totalPower = this.powerSource.totalPower,
+ carbonTracePath = this.powerSource.carbonTracePath,
)
clusterId++
return ClusterSpec(this.name, hostSpecs, 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
index 79770684..179e8f9e 100644
--- 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
@@ -29,5 +29,6 @@ public data class PowerSourceSpec(
val uid: UUID,
val name: String = "unknown",
val meta: Map<String, Any> = emptyMap(),
- val totalPower: Long,
+ val totalPower: Long = Long.MAX_VALUE,
+ val carbonTracePath: String? = 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 9acdf72a..cdc1d96a 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
@@ -115,6 +115,7 @@ public data class PowerModelSpec(
val power: Power = Power.ofWatts(400),
val maxPower: Power,
val idlePower: Power,
+ val carbonTracePaths: String? = null,
) {
init {
require(maxPower >= idlePower) { "The max power of a power model can not be less than the idle power" }
@@ -144,7 +145,8 @@ public data class PowerSourceJSONSpec(
val vendor: String = "unknown",
val modelName: String = "unknown",
val arch: String = "unknown",
- val totalPower: Long,
+ val totalPower: Long = Long.MAX_VALUE,
+ val carbonTracePath: String? = null,
) {
public companion object {
public val DFLT: PowerSourceJSONSpec =