Code cleanup, no functional changes.

This commit is contained in:
Lukas Steiner
2020-05-27 09:47:56 +02:00
parent 8cabd35b2a
commit 0de8ababfa
10 changed files with 107 additions and 270 deletions

View File

@@ -157,7 +157,6 @@ add_library(DRAMSysLibrary
src/simulation/ExampleInitiator.h
src/simulation/MemoryManager.cpp
src/simulation/ReorderBuffer.h
src/simulation/Setup.cpp
src/simulation/StlPlayer.h
src/simulation/TemperatureController.cpp
src/simulation/TraceGenerator.h

View File

@@ -95,7 +95,8 @@ void TlmRecorder::recordPhase(tlm_generic_payload &trans,
if (currentTransactionsInSystem.count(&trans) == 0)
introduceTransactionSystem(trans);
std::string phaseName = phaseNameToString(phase);
//std::string phaseName = phaseNameToString(phase);
std::string phaseName = phase.get_name();
std::string phaseBeginPrefix = "BEGIN_";
std::string phaseEndPrefix = "END_";
@@ -232,10 +233,20 @@ void TlmRecorder::openDB(std::string name)
}
}
void TlmRecorder::createTables(std::string pathToURI)
{
std::string initial = loadTextFileContents(pathToURI);
std::string initial;
ifstream in(pathToURI.c_str(), ios::in | ios::binary);
if (!in)
SC_REPORT_FATAL("Error loading file", ("Could not load textfile from " + pathToURI).c_str());
in.seekg(0, ios::end);
initial.resize(in.tellg());
in.seekg(0, ios::beg);
in.read(&initial[0], initial.size());
in.close();
executeSqlCommand(initial);
}

View File

@@ -64,73 +64,6 @@ sc_time getDistance(sc_time a, sc_time b)
return b - a;
}
std::string phaseNameToString(tlm_phase phase)
{
std::ostringstream oss;
oss << phase;
std::string str = oss.str();
return str;
}
unsigned int uIntParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_number_unsigned())
return obj;
else
throw std::invalid_argument("Expected type for '" + name + "': unsigned int");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}
double doubleParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_number() && (obj > 0))
return obj;
else
throw std::invalid_argument("Expected type for " + name + ": positive double");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}
std::string stringParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_string())
return obj;
else
throw std::invalid_argument("Expected type for " + name + ": string");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}
std::string loadTextFileContents(std::string filename)
{
ifstream in(filename.c_str(), ios::in | ios::binary);
if (in)
{
std::string contents;
in.seekg(0, ios::end);
contents.resize(in.tellg());
in.seekg(0, ios::beg);
in.read(&contents[0], contents.size());
in.close();
return (contents);
}
else
{
SC_REPORT_FATAL("Error loading file", ("Could not load textfile from " + filename).c_str());
return "";
}
}
nlohmann::json parseJSON(std::string path)
{
try

View File

@@ -134,17 +134,8 @@ static inline void loadbar(unsigned int x,
std::cout << "|\r" << std::flush;
}
//TODO : Move to debug manager
std::string phaseNameToString(tlm::tlm_phase phase);
//TODO : Move to other source specific
std::string getFileName(std::string uri);
std::string loadTextFileContents(std::string filename);
unsigned int uIntParameter(nlohmann::json obj, std::string name);
double doubleParameter(nlohmann::json obj, std::string name);
std::string stringParameter(nlohmann::json obj, std::string name);
nlohmann::json parseJSON(std::string path);

View File

@@ -40,57 +40,47 @@
using json = nlohmann::json;
void ConfigurationLoader::loadSimConfig(Configuration &config,
std::string simconfigUri)
void ConfigurationLoader::loadSimConfig(Configuration &config, std::string simconfigUri)
{
json doc = parseJSON(simconfigUri);
auto simconfig = doc["simconfig"].get_ptr<json::object_t*>();
json::object_t *simconfig = doc["simconfig"].get_ptr<json::object_t*>();
loadConfigJson(config, simconfig);
}
void ConfigurationLoader::loadTemperatureSimConfig(Configuration &config,
std::string thermalsimconfigUri)
void ConfigurationLoader::loadTemperatureSimConfig(Configuration &config, std::string thermalsimconfigUri)
{
json doc = parseJSON(thermalsimconfigUri);
auto thermalconfig = doc["thermalsimconfig"].get_ptr<json::object_t*>();
json::object_t *thermalconfig = doc["thermalsimconfig"].get_ptr<json::object_t*>();
loadConfigJson(config, thermalconfig);
}
void ConfigurationLoader::loadConfigJson(Configuration &config,
json::object_t *configNode)
void ConfigurationLoader::loadConfigJson(Configuration &config, json::object_t *configNode)
{
json j = *configNode;
for (auto& x : j.items())
config.setParameter(x.key(), x.value());
}
void ConfigurationLoader::loadMCConfig(Configuration &config,
std::string mcconfigUri)
void ConfigurationLoader::loadMCConfig(Configuration &config, std::string mcconfigUri)
{
config.mcconfigUri = mcconfigUri;
json doc = parseJSON(mcconfigUri);
auto mcconfig = doc["mcconfig"].get_ptr<json::object_t*>();
json::object_t *mcconfig = doc["mcconfig"].get_ptr<json::object_t*>();
loadConfigJson(config, mcconfig);
}
void ConfigurationLoader::loadMemSpec(Configuration &config, std::string memspecUri)
{
config.memspecUri = memspecUri;
json doc = parseJSON(memspecUri);
auto memspec = doc["memspec"].get_ptr<json::object_t*>();
json::object_t *memspec = doc["memspec"].get_ptr<json::object_t*>();
loadMemSpec(config, memspec);
}
void ConfigurationLoader::loadMemSpec(Configuration &config,
json::object_t *memspec)
void ConfigurationLoader::loadMemSpec(Configuration &config, json::object_t *memspec)
{
using json = nlohmann::json;
json j = *memspec;
auto memoryType = j["memoryType"];
std::string memoryType = j["memoryType"];
if (memoryType == "DDR3")
{
@@ -725,3 +715,42 @@ void ConfigurationLoader::loadGDDR6(Configuration &config, json::object_t *json
// Currents and voltages
// TODO: to be completed
}
unsigned int ConfigurationLoader::uIntParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_number_unsigned())
return obj;
else
throw std::invalid_argument("Expected type for '" + name + "': unsigned int");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}
double ConfigurationLoader::doubleParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_number() && (obj > 0))
return obj;
else
throw std::invalid_argument("Expected type for '" + name + "': positive double");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}
std::string ConfigurationLoader::stringParameter(nlohmann::json obj, std::string name)
{
if (!obj.empty())
{
if (obj.is_string())
return obj;
else
throw std::invalid_argument("Expected type for '" + name + "': string");
}
else
SC_REPORT_FATAL("Query json", ("Parameter '" + name + "' does not exist.").c_str());
}

View File

@@ -82,6 +82,10 @@ private:
static void loadGDDR5(Configuration &config, nlohmann::json::object_t *memspec);
static void loadGDDR5X(Configuration &config, nlohmann::json::object_t *memspec);
static void loadGDDR6(Configuration &config, nlohmann::json::object_t *memspec);
static unsigned int uIntParameter(nlohmann::json obj, std::string name);
static double doubleParameter(nlohmann::json obj, std::string name);
static std::string stringParameter(nlohmann::json obj, std::string name);
};

View File

@@ -74,18 +74,18 @@ DRAMSys::DRAMSys(sc_module_name name,
logo();
// Read Configuration Setup:
std::string memspec;
std::string mcconfig;
std::string amconfig;
std::string simconfig;
std::string thermalconfig;
nlohmann::json simulationdoc = parseJSON(simulationToRun);
Setup setup(simulationToRun,
memspec,
mcconfig,
amconfig,
simconfig,
thermalconfig);
if (simulationdoc["simulation"].empty())
SC_REPORT_FATAL("SimulationManager",
"Cannot load simulation: simulation node expected");
// Load all sub-configuration JSON files
std::string memspec = simulationdoc["simulation"]["memspec"];
std::string mcconfig = simulationdoc["simulation"]["mcconfig"];
std::string amconfig = simulationdoc["simulation"]["addressmapping"];
std::string simconfig = simulationdoc["simulation"]["simconfig"];
std::string thermalconfig = simulationdoc["simulation"]["thermalconfig"];
Configuration::getInstance().setPathToResources(pathToResources);
@@ -118,9 +118,8 @@ DRAMSys::DRAMSys(sc_module_name name,
std::string simName;
simName = Configuration::getInstance().simulationName;
nlohmann::json simulationdoc = parseJSON(simulationToRun);
if (!simulationdoc["simulation"]["simulationid"].empty()) {
if (!simulationdoc["simulation"]["simulationid"].empty())
{
std::string sid = simulationdoc["simulation"]["simulationid"];
simName = sid + '_' + Configuration::getInstance().simulationName;
}
@@ -165,16 +164,12 @@ void DRAMSys::setupTlmRecorders(const std::string &traceName,
const std::string &pathToResources)
{
// Create TLM Recorders, one per channel.
for (size_t i = 0;
i < Configuration::getInstance().numberOfMemChannels;
i++) {
for (size_t i = 0; i < Configuration::getInstance().numberOfMemChannels; i++)
{
std::string sqlScriptURI = pathToResources
+ std::string("scripts/createTraceDB.sql");
std::string dbName = traceName
+ std::string("_ch")
+ std::to_string(i)
+ ".tdb";
std::string dbName = traceName + std::string("_ch") + std::to_string(i) + ".tdb";
std::string recorderName = "tlmRecorder" + std::to_string(i);
@@ -325,19 +320,19 @@ void DRAMSys::bindSockets()
else
SC_REPORT_FATAL("DRAMSys", "Unsupported ECC mode");
if (Configuration::getInstance().checkTLM2Protocol) {
for (size_t i = 0;
i < Configuration::getInstance().numberOfMemChannels;
i++) {
if (Configuration::getInstance().checkTLM2Protocol)
{
for (size_t i = 0; i < Configuration::getInstance().numberOfMemChannels; i++)
{
arbiter->iSocket.bind(controllersTlmCheckers[i]->target_socket);
controllersTlmCheckers[i]->initiator_socket.bind(
controllers[i]->tSocket);
controllersTlmCheckers[i]->initiator_socket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
} else {
for (size_t i = 0;
i < Configuration::getInstance().numberOfMemChannels;
i++) {
}
else
{
for (size_t i = 0; i < Configuration::getInstance().numberOfMemChannels; i++)
{
arbiter->iSocket.bind(controllers[i]->tSocket);
controllers[i]->iSocket.bind(drams[i]->tSocket);
}
@@ -351,25 +346,20 @@ DRAMSys::~DRAMSys()
delete arbiter;
for (auto dram : drams) {
for (auto dram : drams)
delete dram;
}
for (auto rec : tlmRecorders) {
for (auto rec : tlmRecorders)
delete rec;
}
for (auto tlmChecker : playersTlmCheckers) {
for (auto tlmChecker : playersTlmCheckers)
delete tlmChecker;
}
for (auto tlmChecker : controllersTlmCheckers) {
for (auto tlmChecker : controllersTlmCheckers)
delete tlmChecker;
}
for (auto controller : controllers) {
for (auto controller : controllers)
delete controller;
}
}
void DRAMSys::report(std::string message)

View File

@@ -1,62 +0,0 @@
/*
* Copyright (c) 2017, University of Kaiserslautern
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors:
* Matthias Jung
* Luiza Correa
*/
#include "Setup.h"
Setup::Setup(std::string uri,
std::string &memspec,
std::string &mcconfig,
std::string &amconfig,
std::string &simconfig,
std::string &thermalconfig)
{
// Load Simulation:
nlohmann::json simulationdoc = parseJSON(uri);
if (simulationdoc["simulation"].empty())
SC_REPORT_FATAL("SimulationManager",
"Cannot load simulation: simulation node expected");
// Load all sub-configuration JSON files
memspec = simulationdoc["simulation"]["memspec"];
mcconfig = simulationdoc["simulation"]["mcconfig"];
amconfig = simulationdoc["simulation"]["addressmapping"];
simconfig = simulationdoc["simulation"]["simconfig"];
thermalconfig = simulationdoc["simulation"]["thermalconfig"];
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright (c) 2017, University of Kaiserslautern
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors:
* Matthias Jung
*/
#ifndef SETUP_H
#define SETUP_H
#include <vector>
#include <string>
#include "../common/utils.h"
#include "TracePlayer.h"
#include "StlPlayer.h"
class Setup
{
public:
Setup(std::string uri,
std::string &memspec,
std::string &mcconfig,
std::string &amconfig,
std::string &simconfig,
std::string &thermalconfig);
};
#endif // SETUP_H

View File

@@ -62,37 +62,38 @@ int sc_main(int argc, char **argv)
sc_set_time_resolution(1, SC_PS);
std::string SimulationJSON;
std::string simulationJSON;
// Run only with default config (ddr3-example.json):
if (argc == 1) {
// Get path of resources:
resources = pathOfFile(argv[0])
+ std::string("/../../DRAMSys/library/resources/");
SimulationJSON = resources + "simulations/ddr3-example.json";
simulationJSON = resources + "simulations/ddr3-example.json";
}
// Run with specific config but default resource folders:
else if (argc == 2) {
// Get path of resources:
resources = pathOfFile(argv[0])
+ std::string("/../../DRAMSys/library/resources/");
SimulationJSON = argv[1];
simulationJSON = argv[1];
}
// Run with spefific config and specific resource folder:
else if (argc == 3) {
SimulationJSON = argv[1];
simulationJSON = argv[1];
resources = argv[2];
}
std::vector<TracePlayer *> players;
// Instantiate DRAMSys:
DRAMSys *dramSys = new DRAMSys("DRAMSys", SimulationJSON, resources);
DRAMSys *dramSys = new DRAMSys("DRAMSys", simulationJSON, resources);
// Instantiate STL Players:
TraceSetup *ts = new TraceSetup(SimulationJSON, resources, &players);
TraceSetup *ts = new TraceSetup(simulationJSON, resources, &players);
// Bind STL Players with DRAMSys:
for (size_t i = 0; i < players.size(); i++) {
for (size_t i = 0; i < players.size(); i++)
{
if(Configuration::getInstance().checkTLM2Protocol)
{
std::string str = "TLMCheckerPlayer" + std::to_string(i);
@@ -112,9 +113,8 @@ int sc_main(int argc, char **argv)
auto start = std::chrono::high_resolution_clock::now();
// Kickstart the players:
for (auto &p : players) {
for (auto &p : players)
p->nextPayload();
}
// Start SystemC Simulation:
sc_set_stop_mode(SC_STOP_FINISH_DELTA);