summaryrefslogtreecommitdiff
path: root/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-28 03:27:36 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2017-09-28 03:27:36 +0200
commitd6d9d37abf17071ff050e45ea37c693e659a4e98 (patch)
tree248d11c478ee71a6bc47cf3f5c73870c73b4c210 /opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine
parent23a476613b000bf04194ec2962d270fa3cabfc5d (diff)
Implement JPA integration
Diffstat (limited to 'opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine')
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt8
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt8
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt32
-rw-r--r--opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt8
4 files changed, 29 insertions, 27 deletions
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt
index 78e2eaaa..f97e73e9 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Cpu.kt
@@ -29,10 +29,4 @@ package nl.atlarge.opendc.topology.machine
*
* @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
*/
-data class Cpu(
- override val speed: Int,
- override val cores: Int,
- override val energyConsumption: Int
-) : ProcessingUnit {
- override val initialState = Unit
-}
+interface Cpu : ProcessingUnit
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt
index 09179c94..15c5263f 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Gpu.kt
@@ -29,11 +29,5 @@ package nl.atlarge.opendc.topology.machine
*
* @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
*/
-class Gpu(
- override val speed: Int,
- override val cores: Int,
- override val energyConsumption: Int
-) : ProcessingUnit {
- override val initialState = Unit
-}
+interface Gpu : ProcessingUnit
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
index 3305581a..4338ae04 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/Machine.kt
@@ -25,8 +25,8 @@
package nl.atlarge.opendc.topology.machine
import mu.KotlinLogging
-import nl.atlarge.opendc.extension.topology.destinations
-import nl.atlarge.opendc.workload.Task
+import nl.atlarge.opendc.topology.destinations
+import nl.atlarge.opendc.platform.workload.Task
import nl.atlarge.opendc.kernel.Context
import nl.atlarge.opendc.kernel.Process
import nl.atlarge.opendc.kernel.time.Duration
@@ -38,7 +38,7 @@ import nl.atlarge.opendc.topology.Entity
*
* @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl)
*/
-class Machine : Entity<Machine.State>, Process<Machine> {
+open class Machine : Entity<Machine.State>, Process<Machine> {
/**
* The logger instance to use for the simulator.
*/
@@ -53,8 +53,18 @@ class Machine : Entity<Machine.State>, Process<Machine> {
/**
* The shape of the state of a [Machine] entity.
+ *
+ * @property status The status of the machine.
+ * @property task The task assign to the machine.
+ * @property memory The memory usage of the machine (defaults to 50mb for the kernel)
+ * @property load The load on the machine (defaults to 0.0)
+ * @property temperature The temperature of the machine (defaults to 23 degrees Celcius)
*/
- data class State(val status: Status, val task: Task? = null)
+ data class State(val status: Status,
+ val task: Task? = null,
+ val memory: Int = 50,
+ val load: Double = 0.0,
+ val temperature: Double = 23.0)
/**
* The initial state of a [Machine] entity.
@@ -69,24 +79,28 @@ class Machine : Entity<Machine.State>, Process<Machine> {
val interval: Duration = 10
val cpus = outgoingEdges.destinations<Cpu>("cpu")
- val speed = cpus.fold(0, { acc, (speed, cores) -> acc + speed * cores })
+ val speed = cpus.fold(0, { acc, cpu -> acc + cpu.clockRate * cpu.cores }) / 10
+
var task: Task = receiveTask()
- update(State(Status.RUNNING, task))
+ update(State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0))
+ task.run { start() }
while (true) {
- if (task.finished) {
+ if (task.remaining <= 0) {
+ task.run { finalize() }
logger.info { "${entity.id}: Task ${task.id} finished. Machine idle at $time" }
update(State(Status.IDLE))
task = receiveTask()
} else {
- task.consume(speed * delta)
+ task.run { consume(speed * delta) }
}
// Check if we have received a new order in the meantime.
val msg = receive(interval)
if (msg is Task) {
task = msg
- update(State(Status.RUNNING, task))
+ update(State(Status.RUNNING, task, load = 1.0, memory = state.memory + 50, temperature = 30.0))
+ task.run { start() }
}
}
}
diff --git a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt
index 31bfbcd6..abc8608b 100644
--- a/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt
+++ b/opendc-stdlib/src/main/kotlin/nl/atlarge/opendc/topology/machine/ProcessingUnit.kt
@@ -33,9 +33,9 @@ import nl.atlarge.opendc.topology.Entity
*/
interface ProcessingUnit : Entity<Unit> {
/**
- * The speed of this [ProcessingUnit] per core.
+ * The speed of this [ProcessingUnit] per core in MHz.
*/
- val speed: Int
+ val clockRate: Int
/**
* The amount of cores within this [ProcessingUnit].
@@ -43,7 +43,7 @@ interface ProcessingUnit : Entity<Unit> {
val cores: Int
/**
- * The energy consumption of this [ProcessingUnit] in Kj/s.
+ * The energy consumption of this [ProcessingUnit] in Watt.
*/
- val energyConsumption: Int
+ val energyConsumption: Double
}