From 070ce923574dcc57435cb3fb2dfe86b6a38cd249 Mon Sep 17 00:00:00 2001 From: MDBijman Date: Tue, 24 Jan 2017 12:15:26 +0100 Subject: Initial code commit with organized dependencies --- Simulator/src/modeling/Entity.cpp | 8 +++ Simulator/src/modeling/Rack.cpp | 21 ++++++++ Simulator/src/modeling/machine/CPU.cpp | 26 ++++++++++ Simulator/src/modeling/machine/GPU.cpp | 26 ++++++++++ Simulator/src/modeling/machine/Machine.cpp | 80 ++++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 Simulator/src/modeling/Entity.cpp create mode 100644 Simulator/src/modeling/Rack.cpp create mode 100644 Simulator/src/modeling/machine/CPU.cpp create mode 100644 Simulator/src/modeling/machine/GPU.cpp create mode 100644 Simulator/src/modeling/machine/Machine.cpp (limited to 'Simulator/src/modeling') diff --git a/Simulator/src/modeling/Entity.cpp b/Simulator/src/modeling/Entity.cpp new file mode 100644 index 00000000..eb39222b --- /dev/null +++ b/Simulator/src/modeling/Entity.cpp @@ -0,0 +1,8 @@ +#include "modeling/Entity.h" + +namespace Modeling +{ + Entity::Entity(int id) : id(id) + { + } +} diff --git a/Simulator/src/modeling/Rack.cpp b/Simulator/src/modeling/Rack.cpp new file mode 100644 index 00000000..2b330abd --- /dev/null +++ b/Simulator/src/modeling/Rack.cpp @@ -0,0 +1,21 @@ +#include "modeling/Rack.h" + +#include +#include + +namespace Modeling +{ + Rack::Rack(int id, std::unordered_map machines) : Entity(id), machines(machines) {} + + std::unordered_map& Rack::getMachines() + { + return machines; + } + + Machine& Rack::getMachineAtSlot(int slot) + { + assert(machines.find(slot) != machines.end()); + + return machines.at(slot); + } +} diff --git a/Simulator/src/modeling/machine/CPU.cpp b/Simulator/src/modeling/machine/CPU.cpp new file mode 100644 index 00000000..6167b133 --- /dev/null +++ b/Simulator/src/modeling/machine/CPU.cpp @@ -0,0 +1,26 @@ +#include "modeling/machine/CPU.h" + +namespace Modeling +{ + CPU::CPU(int speed, int cores, int energyConsumption, int failureModelId) : speed(speed), cores(cores), energyConsumption(energyConsumption), failureModelId(failureModelId) {} + + int CPU::getCores() + { + return this->cores; + } + + int CPU::getEnergyConsumption() + { + return this->energyConsumption; + } + + int CPU::getFailureModelId() + { + return this->failureModelId; + } + + int CPU::getSpeed() + { + return this->speed; + } +} diff --git a/Simulator/src/modeling/machine/GPU.cpp b/Simulator/src/modeling/machine/GPU.cpp new file mode 100644 index 00000000..8458925b --- /dev/null +++ b/Simulator/src/modeling/machine/GPU.cpp @@ -0,0 +1,26 @@ +#include "modeling/machine/GPU.h" + +namespace Modeling +{ + GPU::GPU(int speed, int cores, int energyConsumption, int failureModelId) : speed(speed), cores(cores), energyConsumption(energyConsumption), failureModelId(failureModelId) {} + + int GPU::getCores() + { + return this->cores; + } + + int GPU::getEnergyConsumption() + { + return this->energyConsumption; + } + + int GPU::getFailureModelId() + { + return this->failureModelId; + } + + int GPU::getSpeed() + { + return this->speed; + } +} diff --git a/Simulator/src/modeling/machine/Machine.cpp b/Simulator/src/modeling/machine/Machine.cpp new file mode 100644 index 00000000..d7d4fac7 --- /dev/null +++ b/Simulator/src/modeling/machine/Machine.cpp @@ -0,0 +1,80 @@ +#include "modeling/machine/Machine.h" + +namespace Modeling +{ + Machine::Machine(int id) : busy(false), currentWorkload(), id(id) + {} + + void Machine::addCPU(CPU c) + { + cpus.push_back(c); + } + + void Machine::addGPU(GPU g) + { + gpus.push_back(g); + } + + void Machine::giveTask(Simulation::Workload* workload) + { + busy = true; + currentWorkload = workload; + } + + bool Machine::isBusy() const + { + return this->busy; + } + + uint32_t Machine::getSpeed() + { + int speed = 0; + for(auto cpu : cpus) + { + speed += cpu.getSpeed() * cpu.getCores(); + } + return speed; + } + + void Machine::work() + { + if(!currentWorkload) + return; + + currentWorkload->doOperations(static_cast(getSpeed() * load)); + + temperature += load * temperatureIncrease; + //load = temperature < 70.0f ? 1.0f : 1.0f / (temperature - 69.0f); + load = 1.0f; + temperature = temperature > maxTemperature ? maxTemperature + : temperature < minTemperature ? minTemperature + : temperature; + } + + int Machine::getWorkloadId() const + { + if(currentWorkload) + return currentWorkload->getId(); + return 0; + } + + int Machine::getId() const + { + return this->id; + } + + float Machine::getTemperature() const + { + return this->temperature; + } + + int Machine::getMemory() const + { + return this->memory; + } + + float Machine::getLoad() const + { + return this->load; + } +} -- cgit v1.2.3