diff options
| author | Hongyu <hongyuhe.cs@googlemail.com> | 2021-03-16 09:08:51 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-18 11:37:43 +0100 |
| commit | dd24782f3710678151c80f8ad365eecc7389b6f8 (patch) | |
| tree | 6e5ddf4e61e70495d67d4220f7657e7b271301e8 /simulator/opendc-simulator/opendc-simulator-compute/src | |
| parent | 054a3d376b8b31ba98f91e7b34c6e0ca717def18 (diff) | |
simulator: Add the CPU power model from iCanCloud/E-mc2
This change implements the CPU energy model with p-states from iCanCloud/E-mc2:
- Only pushed a portion of the code for discussion as not sure if the idea is
on track.
- Inline comments have been added, and formal documents will follow once the
model is finalized.
- The p-state power consumptions are currently hard-coded in a companion
object, which should be improved in the next PR(s).
**Breaking Changes**
- CpuPowerModel: directly interact with the machine it is measuring.
- SimBareMetalMachine: expose the speeds of its CPU cores and its clock
instant.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-compute/src')
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt index 1bdbb7e8..39ae34fe 100644 --- a/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt +++ b/simulator/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/SimAbstractMachine.kt @@ -38,8 +38,6 @@ import kotlin.coroutines.CoroutineContext /** * Abstract implementation of the [SimMachine] interface. - * - * @param context The [CoroutineContext] in which the machine runs. */ public abstract class SimAbstractMachine(private val clock: Clock) : SimMachine { private val _usage = MutableStateFlow(0.0) @@ -47,6 +45,13 @@ public abstract class SimAbstractMachine(private val clock: Clock) : SimMachine get() = _usage /** + * The speed of the CPU cores. + */ + public val speed: List<Double> + get() = _speed + private var _speed = mutableListOf<Double>() + + /** * A flag to indicate that the machine is terminated. */ private var isTerminated = false @@ -89,13 +94,16 @@ public abstract class SimAbstractMachine(private val clock: Clock) : SimMachine val ctx = Context(resources, meta + mapOf("coroutine-context" to context)) val totalCapacity = model.cpus.sumByDouble { it.frequency } + _speed = MutableList(model.cpus.size) { 0.0 } + workload.onStart(ctx) for ((cpu, source) in resources) { val consumer = workload.getConsumer(ctx, cpu) val job = source.speed .onEach { - _usage.value = resources.values.sumByDouble { it.speed.value } / totalCapacity + _speed[cpu.id] = source.speed.value + _usage.value = _speed.sum() / totalCapacity } .launchIn(this) |
