From cc5c5a7eac0ebcf97c283e1e0dd1674c855a261a Mon Sep 17 00:00:00 2001 From: Matthijs Bijman Date: Mon, 27 Feb 2017 13:55:50 +0100 Subject: Implement logging of cores_used in task_states --- Simulator/Simulator.vcxproj | 6 ++--- Simulator/include/database/Queries.h | 6 ++--- Simulator/include/modeling/machine/CPU.h | 27 ++++++++++--------- Simulator/include/modeling/machine/Machine.h | 5 ++++ Simulator/include/simulation/Experiment.h | 3 ++- .../include/simulation/history/WorkloadSnapshot.h | 3 ++- .../schedulers/FirstInFirstOutScheduler.h | 25 +++++++++++------- .../include/simulation/schedulers/Scheduler.h | 1 - .../schedulers/ShortestRemainingTimeScheduler.h | 30 +++++++++++++--------- Simulator/include/simulation/workloads/Workload.h | 15 ++++++++++- Simulator/src/database/Database.cpp | 3 ++- Simulator/src/modeling/machine/CPU.cpp | 8 +++--- Simulator/src/modeling/machine/Machine.cpp | 9 +++++++ Simulator/src/simulation/workloads/Workload.cpp | 12 +++++++-- .../src/simulation/workloads/WorkloadPool.cpp | 1 + opendc-simulator-dependencies | 2 +- 16 files changed, 105 insertions(+), 51 deletions(-) diff --git a/Simulator/Simulator.vcxproj b/Simulator/Simulator.vcxproj index aba44dba..954fad72 100644 --- a/Simulator/Simulator.vcxproj +++ b/Simulator/Simulator.vcxproj @@ -113,8 +113,8 @@ true - sqlite3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(SolutionDir)external\sqlite3; + sqlite3_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)opendc-simulator-dependencies\sqlite @@ -125,7 +125,7 @@ true - sqlite3.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + sqlite3_64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) $(SolutionDir)opendc-simulator-dependencies\sqlite diff --git a/Simulator/include/database/Queries.h b/Simulator/include/database/Queries.h index 33e8cdb9..59133058 100644 --- a/Simulator/include/database/Queries.h +++ b/Simulator/include/database/Queries.h @@ -118,11 +118,11 @@ namespace Database /* Inserts the state of a workload into the task_state table. Returns: <> - Binds: + Binds: */ Query<> WRITE_WORKLOAD_STATE(std::string(R"query( - INSERT INTO task_states (task_id, experiment_id, tick, flops_left) - VALUES ($tid, $ssid, $tick, $flops); + INSERT INTO task_states (task_id, experiment_id, tick, flops_left, cores_used) + VALUES ($tid, $ssid, $tick, $flops, $cores_used); )query")); /* diff --git a/Simulator/include/modeling/machine/CPU.h b/Simulator/include/modeling/machine/CPU.h index dce4d2c5..95af1c86 100644 --- a/Simulator/include/modeling/machine/CPU.h +++ b/Simulator/include/modeling/machine/CPU.h @@ -5,27 +5,30 @@ namespace Modeling class CPU { public: + /** + * \brief Creates a CPU with the given speed/core, number of cores, energy consumption, and failure model id. + */ CPU(int speed, int cores, int energyConsumption, int failureModelId); - /* - Returns the speed of this CPU. + /** + * \return the speed of this CPU. */ - int getSpeed(); + int getSpeed() const; - /* - Returns the nr of cores of this CPU. + /** + * \return The nr of cores of this CPU. */ - int getCores(); + int getCores() const; - /* - Returns the energy consumed by this CPU. + /** + * \return The energy consumed by this CPU. */ - int getEnergyConsumption(); + int getEnergyConsumption() const; - /* - Returns the failure model id of this CPU. + /** + * \return The failure model id of this CPU. */ - int getFailureModelId(); + int getFailureModelId() const; private: diff --git a/Simulator/include/modeling/machine/Machine.h b/Simulator/include/modeling/machine/Machine.h index c89d32d1..f18f8352 100644 --- a/Simulator/include/modeling/machine/Machine.h +++ b/Simulator/include/modeling/machine/Machine.h @@ -76,6 +76,11 @@ namespace Modeling */ float getLoad() const; + /** + * \return The number of cores in this machine. + */ + uint32_t getNumberOfCores() const; + private: // A list of cpus in this machine. std::vector cpus; diff --git a/Simulator/include/simulation/Experiment.h b/Simulator/include/simulation/Experiment.h index 69c192fa..400f418a 100644 --- a/Simulator/include/simulation/Experiment.h +++ b/Simulator/include/simulation/Experiment.h @@ -60,7 +60,8 @@ namespace Simulation currentTick, WorkloadSnapshot( workload->getId(), - workload->getRemainingOperations() + workload->getRemainingOperations(), + workload->getCoresUsed() ) ); } diff --git a/Simulator/include/simulation/history/WorkloadSnapshot.h b/Simulator/include/simulation/history/WorkloadSnapshot.h index 1e7e2695..30a93898 100644 --- a/Simulator/include/simulation/history/WorkloadSnapshot.h +++ b/Simulator/include/simulation/history/WorkloadSnapshot.h @@ -5,9 +5,10 @@ namespace Simulation class WorkloadSnapshot { public: - WorkloadSnapshot(uint32_t id, uint32_t flopsDone) : flopsDone(flopsDone), id(id) {} + WorkloadSnapshot(uint32_t id, uint32_t flopsDone, uint32_t coresUsed) : flopsDone(flopsDone), id(id), coresUsed(coresUsed) {} uint32_t flopsDone; uint32_t id; + uint32_t coresUsed; }; } \ No newline at end of file diff --git a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h index 0cac0dfa..797eb489 100644 --- a/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h +++ b/Simulator/include/simulation/schedulers/FirstInFirstOutScheduler.h @@ -12,8 +12,8 @@ namespace Simulation } public: - /* - Distribute workloads according to the FIFO principle + /** + * \brief Distribute workloads according to the FIFO principle. */ void schedule(std::vector>& machines, std::vector workloads) override { @@ -25,13 +25,20 @@ namespace Simulation while(!workloads.at(index)->dependencyFinished) index = (++index) % workloads.size(); - std::for_each( - machines.begin(), - machines.end(), - [index, &workloads](std::reference_wrapper& machine) { - machine.get().giveTask(workloads.at(index)); - } - ); + // Reset the number of cores used for each workload + for (auto workload : workloads) + { + workload->setCoresUsed(0); + } + + // Distribute tasks across machines and set cores used of workloads + for (auto machine : machines) + { + machine.get().giveTask(workloads.at(index)); + workloads.at(index)->setCoresUsed( + workloads.at(index)->getCoresUsed() + machine.get().getNumberOfCores() + ); + } } }; } diff --git a/Simulator/include/simulation/schedulers/Scheduler.h b/Simulator/include/simulation/schedulers/Scheduler.h index b084e8f6..69e20d01 100644 --- a/Simulator/include/simulation/schedulers/Scheduler.h +++ b/Simulator/include/simulation/schedulers/Scheduler.h @@ -1,5 +1,4 @@ #pragma once -#include "simulation/workloads/Workload.h" #include "modeling/machine/Machine.h" #include diff --git a/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h index 15265985..51673fb5 100644 --- a/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h +++ b/Simulator/include/simulation/schedulers/ShortestRemainingTimeScheduler.h @@ -12,14 +12,19 @@ namespace Simulation } public: - /* - Distribute workloads according to the srtf principle + /** + * \brief Distribute workloads according to the srtf principle. */ void schedule(std::vector>& machines, std::vector workloads) override { if (workloads.size() == 0) return; + for (auto workload : workloads) + { + workload->setCoresUsed(0); + } + std::sort( workloads.begin(), workloads.end(), @@ -30,17 +35,18 @@ namespace Simulation int taskIndex = 0; - std::for_each( - machines.begin(), - machines.end(), - [&workloads, &taskIndex](Modeling::Machine& machine) { - while (!workloads.at(taskIndex)->dependencyFinished) - taskIndex = (++taskIndex) % workloads.size(); - - machine.giveTask(workloads.at(taskIndex)); + for (auto machine : machines) + { + while (!workloads.at(taskIndex)->dependencyFinished) taskIndex = (++taskIndex) % workloads.size(); - } - ); + + machine.get().giveTask(workloads.at(taskIndex)); + workloads.at(taskIndex)->setCoresUsed( + workloads.at(taskIndex)->getCoresUsed() + machine.get().getNumberOfCores() + ); + + taskIndex = (++taskIndex) % workloads.size(); + } } }; } diff --git a/Simulator/include/simulation/workloads/Workload.h b/Simulator/include/simulation/workloads/Workload.h index 9de57990..0371deac 100644 --- a/Simulator/include/simulation/workloads/Workload.h +++ b/Simulator/include/simulation/workloads/Workload.h @@ -47,11 +47,21 @@ namespace Simulation /** * \return The start tick of this workload. */ - uint32_t getStartTick() const + uint32_t getStartTick() { return START_TICK; } + /** + * \brief Sets the coresUsed of this workload to the given number of cores. + */ + void setCoresUsed(uint32_t cores); + + /** + * \return Returns the number of cores used by this workload. + */ + uint32_t getCoresUsed(); + // True if the dependency of this workload has finished. bool dependencyFinished = false; @@ -76,5 +86,8 @@ namespace Simulation // The id of the trace this workload belongs to in the database. uint32_t TRACE_ID; + + // The number of cores that this workload is occupying + uint32_t coresUsed = 0; }; } diff --git a/Simulator/src/database/Database.cpp b/Simulator/src/database/Database.cpp index b953bc73..5abee41e 100644 --- a/Simulator/src/database/Database.cpp +++ b/Simulator/src/database/Database.cpp @@ -50,8 +50,9 @@ namespace Database uint32_t id = snapshot.id; uint32_t flopsDone = snapshot.flopsDone; + uint32_t coresUsed = snapshot.coresUsed; writeWorkloadStateQuery.reset() - .bindParams(id, experiment.getId(), tick, flopsDone) + .bindParams(id, experiment.getId(), tick, flopsDone, coresUsed) .executeOnce(); }); diff --git a/Simulator/src/modeling/machine/CPU.cpp b/Simulator/src/modeling/machine/CPU.cpp index 6167b133..0caa34ec 100644 --- a/Simulator/src/modeling/machine/CPU.cpp +++ b/Simulator/src/modeling/machine/CPU.cpp @@ -4,22 +4,22 @@ namespace Modeling { CPU::CPU(int speed, int cores, int energyConsumption, int failureModelId) : speed(speed), cores(cores), energyConsumption(energyConsumption), failureModelId(failureModelId) {} - int CPU::getCores() + int CPU::getCores() const { return this->cores; } - int CPU::getEnergyConsumption() + int CPU::getEnergyConsumption() const { return this->energyConsumption; } - int CPU::getFailureModelId() + int CPU::getFailureModelId() const { return this->failureModelId; } - int CPU::getSpeed() + int CPU::getSpeed() const { return this->speed; } diff --git a/Simulator/src/modeling/machine/Machine.cpp b/Simulator/src/modeling/machine/Machine.cpp index d7d4fac7..db336dd8 100644 --- a/Simulator/src/modeling/machine/Machine.cpp +++ b/Simulator/src/modeling/machine/Machine.cpp @@ -77,4 +77,13 @@ namespace Modeling { return this->load; } + + uint32_t Machine::getNumberOfCores() const + { + uint32_t cores = 0; + for (auto& processor : cpus) { + cores += processor.getCores(); + } + return cores; + } } diff --git a/Simulator/src/simulation/workloads/Workload.cpp b/Simulator/src/simulation/workloads/Workload.cpp index b6a3b2d0..ba8ca950 100644 --- a/Simulator/src/simulation/workloads/Workload.cpp +++ b/Simulator/src/simulation/workloads/Workload.cpp @@ -1,7 +1,5 @@ #include "simulation/workloads/Workload.h" -#include - namespace Simulation { Workload::Workload(int size, int startTick, int dbId, int traceId, int dependency) : dependencyId(dependency), remainingFlops(size), TOTAL_FLOPS(size), START_TICK(startTick), ID(dbId), TRACE_ID(traceId) {} @@ -44,4 +42,14 @@ namespace Simulation { return this->dependencyId; } + + void Workload::setCoresUsed(uint32_t cores) + { + this->coresUsed = cores; + } + + uint32_t Workload::getCoresUsed() + { + return coresUsed; + } } diff --git a/Simulator/src/simulation/workloads/WorkloadPool.cpp b/Simulator/src/simulation/workloads/WorkloadPool.cpp index c4910c7f..251dcb9a 100644 --- a/Simulator/src/simulation/workloads/WorkloadPool.cpp +++ b/Simulator/src/simulation/workloads/WorkloadPool.cpp @@ -1,4 +1,5 @@ #include "simulation/workloads/WorkloadPool.h" +#include "simulation/workloads/Workload.h" #include #include diff --git a/opendc-simulator-dependencies b/opendc-simulator-dependencies index b5466ecd..7c4fa2ee 160000 --- a/opendc-simulator-dependencies +++ b/opendc-simulator-dependencies @@ -1 +1 @@ -Subproject commit b5466ecde7da8977b00e2b541c6d55bef9b0a7bd +Subproject commit 7c4fa2ee95aaec4fec6abb750d73bdd2596716ca -- cgit v1.2.3