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/include/modeling/Datacenter.h | 40 ++++++++++ Simulator/include/modeling/Entity.h | 12 +++ Simulator/include/modeling/ModelingTypes.h | 7 ++ Simulator/include/modeling/Rack.h | 33 ++++++++ Simulator/include/modeling/Room.h | 52 +++++++++++++ Simulator/include/modeling/TypeIndex.h | 9 +++ Simulator/include/modeling/machine/CPU.h | 34 ++++++++ Simulator/include/modeling/machine/GPU.h | 33 ++++++++ Simulator/include/modeling/machine/Machine.h | 112 +++++++++++++++++++++++++++ 9 files changed, 332 insertions(+) create mode 100644 Simulator/include/modeling/Datacenter.h create mode 100644 Simulator/include/modeling/Entity.h create mode 100644 Simulator/include/modeling/ModelingTypes.h create mode 100644 Simulator/include/modeling/Rack.h create mode 100644 Simulator/include/modeling/Room.h create mode 100644 Simulator/include/modeling/TypeIndex.h create mode 100644 Simulator/include/modeling/machine/CPU.h create mode 100644 Simulator/include/modeling/machine/GPU.h create mode 100644 Simulator/include/modeling/machine/Machine.h (limited to 'Simulator/include/modeling') diff --git a/Simulator/include/modeling/Datacenter.h b/Simulator/include/modeling/Datacenter.h new file mode 100644 index 00000000..a9558f0a --- /dev/null +++ b/Simulator/include/modeling/Datacenter.h @@ -0,0 +1,40 @@ +#pragma once +#include "modeling/Room.h" +#include "simulation/schedulers/Scheduler.h" +#include "modeling/TypeIndex.h" + +#include + +namespace Modeling +{ + /* + The Datacenter class models a datacenter with rooms/entities. + */ + template + class Datacenter + { + public: + /* + Returns a reference to the vector of rooms in this datacenter. + */ + template + std::vector& getRoomsOfType() + { + return std::get::value>(rooms); + } + + /* + Adds a room to this datacenter. + */ + template + void addRoomOfType(RoomType& room) + { + std::get::value>(rooms).push_back(std::move(room)); + } + + + private: + // A vector of rooms that are part of this datacenter. + std::tuple...> rooms; + }; +} diff --git a/Simulator/include/modeling/Entity.h b/Simulator/include/modeling/Entity.h new file mode 100644 index 00000000..c8c5a7cd --- /dev/null +++ b/Simulator/include/modeling/Entity.h @@ -0,0 +1,12 @@ +#pragma once +namespace Modeling +{ + class Entity + { + public: + explicit Entity(int id); + + // The id of this entity in the database + int id; + }; +} diff --git a/Simulator/include/modeling/ModelingTypes.h b/Simulator/include/modeling/ModelingTypes.h new file mode 100644 index 00000000..611a3653 --- /dev/null +++ b/Simulator/include/modeling/ModelingTypes.h @@ -0,0 +1,7 @@ +#pragma once + +// Define a DefaultDC type, capable of holding server rooms. +using DefaultDatacenter = Modeling::Datacenter; + +// Define a type of simulation, capable of simulating the DefaultDC. +using DefaultSection = Simulation::Section; \ No newline at end of file diff --git a/Simulator/include/modeling/Rack.h b/Simulator/include/modeling/Rack.h new file mode 100644 index 00000000..7e5638ef --- /dev/null +++ b/Simulator/include/modeling/Rack.h @@ -0,0 +1,33 @@ +#pragma once +#include "modeling/Entity.h" +#include "modeling/machine/Machine.h" + +#include + +namespace Modeling +{ + /* + The Rack class models a physical rack. It holds a vector of machines. + */ + class Rack : public Entity + { + public: + /* + Initializes the rack with the given machines. + */ + Rack(int id, std::unordered_map machines); + + /* + Returns all machines in this rack. + */ + std::unordered_map& getMachines(); + + /* + Returns the machine at the given slot. + */ + Machine& getMachineAtSlot(int slot); + + private: + std::unordered_map machines; + }; +} diff --git a/Simulator/include/modeling/Room.h b/Simulator/include/modeling/Room.h new file mode 100644 index 00000000..a57b045e --- /dev/null +++ b/Simulator/include/modeling/Room.h @@ -0,0 +1,52 @@ +#pragma once +#include "modeling/Rack.h" +#include "modeling/TypeIndex.h" + +#include + +namespace Modeling +{ + /* + The Room class models the rooms that can be created in the simulation. It contains a list of all entities in the room. + */ + template + class Room + { + //static_assert(std::is_base_of..., "Each type must be derived from Entity!"); + public: + /* + Initializes the room with the given name. + */ + explicit Room(int id) : id(id) {} + + /* + Adds the entity to the list of entities in this room. + */ + template + void addEntity(EntityType& e) + { + std::get::value>(entities).push_back(e); + } + + /* + Returns all entities of the given type. + */ + template + std::vector& getEntitiesOfType() + { + return std::get::value>(entities); + } + + // The id of this room corresponding to its id in the database. + const int id; + + private: + // A vector for each type of entity + std::tuple...> entities; + }; + + using ServerRoom = Room; + using Hallway = Room<>; + using PowerRoom = Room<>; + +} diff --git a/Simulator/include/modeling/TypeIndex.h b/Simulator/include/modeling/TypeIndex.h new file mode 100644 index 00000000..6fcda550 --- /dev/null +++ b/Simulator/include/modeling/TypeIndex.h @@ -0,0 +1,9 @@ +#pragma once +template struct indexOfType; + +template +struct indexOfType : std::integral_constant {}; + +template +struct indexOfType : std::integral_constant::value> {}; + diff --git a/Simulator/include/modeling/machine/CPU.h b/Simulator/include/modeling/machine/CPU.h new file mode 100644 index 00000000..dce4d2c5 --- /dev/null +++ b/Simulator/include/modeling/machine/CPU.h @@ -0,0 +1,34 @@ +#pragma once + +namespace Modeling +{ + class CPU + { + public: + CPU(int speed, int cores, int energyConsumption, int failureModelId); + + /* + Returns the speed of this CPU. + */ + int getSpeed(); + + /* + Returns the nr of cores of this CPU. + */ + int getCores(); + + /* + Returns the energy consumed by this CPU. + */ + int getEnergyConsumption(); + + /* + Returns the failure model id of this CPU. + */ + int getFailureModelId(); + + + private: + int speed, cores, energyConsumption, failureModelId; + }; +} diff --git a/Simulator/include/modeling/machine/GPU.h b/Simulator/include/modeling/machine/GPU.h new file mode 100644 index 00000000..049b928e --- /dev/null +++ b/Simulator/include/modeling/machine/GPU.h @@ -0,0 +1,33 @@ +#pragma once + +namespace Modeling +{ + class GPU + { + public: + GPU(int speed, int cores, int energyConsumption, int failureModelId); + + /* + Returns the speed of this CPU. + */ + int getSpeed(); + + /* + Returns the nr of cores of this CPU. + */ + int getCores(); + + /* + Returns the energy consumed by this CPU. + */ + int getEnergyConsumption(); + + /* + Returns the failure model id of this CPU. + */ + int getFailureModelId(); + + private: + int speed, cores, energyConsumption, failureModelId; + }; +} diff --git a/Simulator/include/modeling/machine/Machine.h b/Simulator/include/modeling/machine/Machine.h new file mode 100644 index 00000000..c89d32d1 --- /dev/null +++ b/Simulator/include/modeling/machine/Machine.h @@ -0,0 +1,112 @@ +#pragma once +#include "simulation/workloads/Workload.h" +#include "modeling/machine/CPU.h" +#include "modeling/machine/GPU.h" + +#include +#include +#include + +namespace Modeling +{ + // Defines the initial temperature of machine + constexpr float ROOM_TEMPERATURE_CELCIUS = 23.0f; + + // Defines the usage of memory by the kernel + constexpr uint32_t KERNEL_MEMORY_USAGE_MB = 50; + + /* + The Machine class models a physical machine in a rack. It has a speed, and can be given a workload on which it will work until finished or interrupted. + */ + class Machine + { + public: + /* + Initializes the machine as idle with the given speed. + */ + Machine(int id); + + /* + Adds a cpu to the list of this machine. + */ + void addCPU(CPU cpu); + + /* + Adds a cpu to the list of this machine. + */ + void addGPU(GPU gpu); + + /* + Gives the task to this machine. If the machine is already busy this does nothing. + */ + void giveTask(Simulation::Workload* workload); + + /* + Returns true if the machine is busy. + */ + bool isBusy() const; + + /* + Does work on the given task and updates temperature and load appropriately. + */ + void work(); + + /* + Returns the id of the current workload of this machine. + */ + int getWorkloadId() const; + + /* + Returns the id of this machine. + */ + int getId() const; + + /* + Returns the temperature of this machine. + */ + float getTemperature() const; + + /* + Returns the memory used by this machine. + */ + int getMemory() const; + + /* + Returns the load fraction on this machine. + */ + float getLoad() const; + + private: + // A list of cpus in this machine. + std::vector cpus; + + // A list of gpus in this machine. + std::vector gpus; + + // True if the machine is working on a task. + bool busy = false; + + // The current workload the machine is working on. + Simulation::Workload* currentWorkload; + + // Db id of this machine. + int id; + + // Temperature of this machine. + float temperature = ROOM_TEMPERATURE_CELCIUS; + float maxTemperature = 80.0f; + float minTemperature = 0.0f; + float temperatureIncrease = 10.f; + + // Memory used by this machine. + int memory = KERNEL_MEMORY_USAGE_MB; + + // The fraction of load on this machine. + float load = 0.0f; + + /* + Returns the speed of the machine. + */ + uint32_t getSpeed(); + }; +} -- cgit v1.2.3