diff --git a/dram/dramSys/dramSys.pro b/dram/dramSys/dramSys.pro index 810dd8b5..bd033625 100644 --- a/dram/dramSys/dramSys.pro +++ b/dram/dramSys/dramSys.pro @@ -39,7 +39,6 @@ SOURCES += \ ../src/common/TlmRecorder.cpp \ ../src/common/dramExtension.cpp \ ../src/common/DebugManager.cpp \ - ../src/controller/core/configuration/MemSpecLoader.cpp \ ../src/controller/core/configuration/Configuration.cpp \ ../src/controller/core/powerdown/PowerDownManagerTimeout.cpp \ ../src/controller/core/powerdown/PowerDownManagerBankwise.cpp \ @@ -71,7 +70,8 @@ SOURCES += \ ../src/simulation/main.cpp \ ../src/controller/core/RowBufferStates.cpp \ ../src/controller/scheduler/Scheduler.cpp \ - ../src/controller/scheduler/readwritegrouper.cpp + ../src/controller/scheduler/readwritegrouper.cpp \ + ../src/controller/core/configuration/ConfigurationLoader.cpp HEADERS += \ ../src/common/third_party/tinyxml2.h \ @@ -82,7 +82,6 @@ HEADERS += \ ../src/common/protocol.h \ ../src/common/dramExtension.h \ ../src/common/DebugManager.h \ - ../src/controller/core/configuration/MemSpecLoader.h \ ../src/controller/core/configuration/Configuration.h \ ../src/controller/core/powerdown/PowerDownManagerTimeout.h \ ../src/controller/core/powerdown/PowerDownManagerBankwise.h \ @@ -129,4 +128,5 @@ HEADERS += \ ../src/simulation/TlmPacketGenerator.h \ ../src/simulation/StlPlayer.h \ ../src/simulation/TracePlayerListener.h + ../src/controller/core/configuration/ConfigurationLoader.h diff --git a/dram/resources/configs/memconfigs/fr_fcfs.xml b/dram/resources/configs/memconfigs/fr_fcfs.xml index 8aa70731..cce963c7 100644 --- a/dram/resources/configs/memconfigs/fr_fcfs.xml +++ b/dram/resources/configs/memconfigs/fr_fcfs.xml @@ -1,14 +1,12 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/dram/resources/simulations/sim-batch.xml b/dram/resources/simulations/sim-batch.xml index 3e19862c..cd725640 100644 --- a/dram/resources/simulations/sim-batch.xml +++ b/dram/resources/simulations/sim-batch.xml @@ -11,7 +11,7 @@ - mediabench-fractal_32.stl + chstone-sha_32.stl diff --git a/dram/src/common/Utils.cpp b/dram/src/common/Utils.cpp index 0425aef2..96bd6d63 100644 --- a/dram/src/common/Utils.cpp +++ b/dram/src/common/Utils.cpp @@ -96,7 +96,7 @@ double queryDoubleParameter(XMLElement* node, string name) bool queryBoolParameter(XMLElement* node, string name) { bool result; - XMLElement* element; + XMLElement* element;// = node->FirstChildElement("parameter"); for (element = node->FirstChildElement("parameter"); element != NULL; element = element->NextSiblingElement("parameter")) { diff --git a/dram/src/controller/core/configuration/Configuration.cpp b/dram/src/controller/core/configuration/Configuration.cpp index 286f3b49..b8eef538 100644 --- a/dram/src/controller/core/configuration/Configuration.cpp +++ b/dram/src/controller/core/configuration/Configuration.cpp @@ -6,21 +6,95 @@ */ #include "Configuration.h" -#include "MemSpecLoader.h" +#include "ConfigurationLoader.h" +#include "boost/lexical_cast.hpp" using namespace std; namespace core{ string Configuration::memspecUri = ""; -string Configuration::memconfigUri = ""; Configuration::Configuration() { - MemSpecLoader loader; - loader.loadConfiguration(*this, Configuration::memspecUri, Configuration::memconfigUri); +} + +int string2bool(string s) +{ + try { + bool x = boost::lexical_cast( s ); + return x; + } catch( boost::bad_lexical_cast const& ) { + SC_REPORT_FATAL("Configuration", ("Could not convert to bool: " + s).c_str()); + throw; + } +} + +int string2int(string s) +{ + try { + int x = boost::lexical_cast( s ); + return x; + } catch( boost::bad_lexical_cast const& ) { + SC_REPORT_FATAL("Configuration", ("Could not convert to int: " + s).c_str()); + throw; + } +} + +PowerDownMode string2PDNMode(string s) +{ + if(s == "NoPowerDown") + return PowerDownMode::NoPowerDown; + else if(s == "Staggered") + return PowerDownMode::Staggered; + else if (s == "TimeoutPDN") + return PowerDownMode::TimeoutPDN; + else if (s == "TimeoutSREF") + return PowerDownMode::TimeoutSREF; + else + { + SC_REPORT_FATAL("Configuration", ("Unknown PowerDownMode: " + s).c_str()); + throw; + } } +void Configuration::setParameter(std::string name, std::string value) +{ + if(name == "BankwiseLogic") + BankwiseLogic = string2bool(value); + else if(name == "OpenPagePolicy") + OpenPagePolicy = string2bool(value); + else if(name == "AdaptiveOpenPagePolicy") + AdaptiveOpenPagePolicy = string2bool(value); + else if(name == "RefreshAwareScheduling") + RefreshAwareScheduling = string2bool(value); + else if(name == "MaxNrOfTransactions") + MaxNrOfTransactions = string2int(value); + else if(name == "Scheduler") + Scheduler = value; + else if(name == "Capsize") + Capsize = string2int(value); + else if(name == "PowerDownTimeout") + powerDownTimeoutInClk = string2int(value); + else if(name == "PowerDownMode") + powerDownMode = string2PDNMode(value); + else if(name == "DatabaseRecordingEnabled") + databaseRecordingEnabled = string2bool(value); + else + { + SC_REPORT_FATAL("Configuration", ("Parameter " + name + " not defined in Configuration").c_str()); + throw; + } +} + +void Configuration::setParameters(std::map parameterMap) +{ + for(auto item : parameterMap) + { + setParameter(item.first, item.second); + } +} + } /* namespace core */ diff --git a/dram/src/controller/core/configuration/Configuration.h b/dram/src/controller/core/configuration/Configuration.h index feefaf3b..cc4835cc 100644 --- a/dram/src/controller/core/configuration/Configuration.h +++ b/dram/src/controller/core/configuration/Configuration.h @@ -12,10 +12,9 @@ #include #include "MemSpec.h" - namespace core{ -enum class PowerDownMode{Staggered, TimeoutPDN, TimeoutSREF}; +enum class PowerDownMode{NoPowerDown, Staggered, TimeoutPDN, TimeoutSREF}; struct Configuration @@ -29,7 +28,7 @@ struct Configuration return configuration; } - //MemConfiguration + //MemConfig bool BankwiseLogic = false; bool OpenPagePolicy = true; bool AdaptiveOpenPagePolicy = false; @@ -37,17 +36,21 @@ struct Configuration unsigned int MaxNrOfTransactions = 50; std::string Scheduler; unsigned int Capsize = 5; - sc_time powerDownTimeout = 3*memSpec.clk; - PowerDownMode powerDownMode; + sc_time getPowerDownTimeout(){return powerDownTimeoutInClk*memSpec.clk;} + PowerDownMode powerDownMode = PowerDownMode::Staggered; - //Memory Specification (from DRAM Power XML) + //SimConfig + bool databaseRecordingEnabled = true; + + //MemSpec(from DRAM-Power XML) MemSpec memSpec; - //Simulation Configuration - bool databaseRecordingEnabled = true; + void setParameter(std::string name, std::string value); + void setParameters(std::map parameterMap); private: Configuration(); + unsigned int powerDownTimeoutInClk = 3; }; } /* namespace core */ diff --git a/dram/src/controller/core/configuration/MemSpecLoader.cpp b/dram/src/controller/core/configuration/ConfigurationLoader.cpp similarity index 76% rename from dram/src/controller/core/configuration/MemSpecLoader.cpp rename to dram/src/controller/core/configuration/ConfigurationLoader.cpp index de3fd88a..67611c08 100644 --- a/dram/src/controller/core/configuration/MemSpecLoader.cpp +++ b/dram/src/controller/core/configuration/ConfigurationLoader.cpp @@ -5,7 +5,7 @@ * Author: jonny */ -#include "MemSpecLoader.h" +#include "ConfigurationLoader.h" #include "MemSpec.h" #include "../TimingCalculation.h" @@ -14,51 +14,46 @@ using namespace std; namespace core { -void MemSpecLoader::loadConfiguration(Configuration& config, string memspecUri, string memconfigUri) +void ConfigurationLoader::loadSimConfig(Configuration& config, string simconfigUri) +{ + tinyxml2::XMLDocument doc; + + loadXML(simconfigUri, doc); + XMLElement* simconfig = doc.FirstChildElement("simconfig"); + loadConfig(config, simconfig); +} + + +void ConfigurationLoader::loadMemConfig(Configuration& config, string memconfigUri) +{ + tinyxml2::XMLDocument doc; + + loadXML(memconfigUri, doc); + XMLElement* memconfig = doc.FirstChildElement("memconfig"); + loadConfig(config, memconfig); +} + +void ConfigurationLoader::loadConfig(Configuration& config, XMLElement* configNode) +{ + XMLElement* element; + for (element = configNode->FirstChildElement(); element != NULL; + element = element->NextSiblingElement()) + { + config.setParameter(element->Name(), element->Attribute("value")); + + } +} + +void ConfigurationLoader::loadMemSpec(Configuration& config, string memspecUri) { tinyxml2::XMLDocument doc; loadXML(memspecUri, doc); XMLElement* memspec = doc.FirstChildElement("memspec"); loadMemSpec(config, memspec); - - loadXML(memconfigUri, doc); - XMLElement* memconfig = doc.FirstChildElement("memspec"); - loadMemConfig(config, memconfig); } -void MemSpecLoader::loadMemConfig(Configuration& config, XMLElement* memconfig) -{ - //MemConfiguration - XMLElement* configuration = memconfig->FirstChildElement("memconfig"); - - config.BankwiseLogic = queryBoolParameter(configuration, "bankwiseLogic"); - config.OpenPagePolicy = queryBoolParameter(configuration, "openPagePolicy"); - config.AdaptiveOpenPagePolicy = queryBoolParameter(configuration, "adaptiveOpenPagePolicy"); - config.RefreshAwareScheduling = queryBoolParameter(configuration, "refreshAwareScheduling"); - config.MaxNrOfTransactions = queryUIntParameter(configuration, "maxNrOfTransactionsInDram"); - config.Scheduler = queryStringParameter(configuration, "scheduler"); - config.Capsize = queryUIntParameter(configuration, "capsize"); - - string mode = queryStringParameter(configuration, "powerDownMode"); - if (mode.compare("Staggered") == 0) - { - config.powerDownMode = PowerDownMode::Staggered; - } - else if (mode.compare("TimeoutPDN") == 0) - { - config.powerDownMode = PowerDownMode::TimeoutPDN; - } - else if (mode.compare("TimeoutSREF") == 0) - { - config.powerDownMode = PowerDownMode::TimeoutSREF; - } - config.powerDownTimeout = queryUIntParameter(configuration, "powerDownTimeout") * config.memSpec.clk; - - config.databaseRecordingEnabled = queryBoolParameter(configuration, "databaseRecordingEnabled"); -} - -void MemSpecLoader::loadMemSpec(Configuration& config, XMLElement* memspec) +void ConfigurationLoader::loadMemSpec(Configuration& config, XMLElement* memspec) { config.memSpec.MemoryId = queryStringParameter(memspec, "memoryId"); config.memSpec.MemoryType = queryStringParameter(memspec, "memoryType"); @@ -77,9 +72,9 @@ void MemSpecLoader::loadMemSpec(Configuration& config, XMLElement* memspec) } } -void MemSpecLoader::loadDDR4(Configuration& config, XMLElement* memspec) +void ConfigurationLoader::loadDDR4(Configuration& config, XMLElement* memspec) { - //MemSpecification + //MemArchitecture XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); config.memSpec.NumberOfBanks = queryUIntParameter(architecture, "nbrOfBanks"); @@ -126,7 +121,7 @@ void MemSpecLoader::loadDDR4(Configuration& config, XMLElement* memspec) } } -void MemSpecLoader::loadWideIO(Configuration& config, XMLElement* memspec) +void ConfigurationLoader::loadWideIO(Configuration& config, XMLElement* memspec) { //MemSpecification XMLElement* architecture = memspec->FirstChildElement("memarchitecturespec"); diff --git a/dram/src/controller/core/configuration/ConfigurationLoader.h b/dram/src/controller/core/configuration/ConfigurationLoader.h new file mode 100644 index 00000000..26e18d54 --- /dev/null +++ b/dram/src/controller/core/configuration/ConfigurationLoader.h @@ -0,0 +1,38 @@ +/* + * ConfigurationLoader.h + * + * Created on: Apr 7, 2014 + * Author: jonny + */ + +#ifndef CONFIGURATIONLOADER_H_ +#define CONFIGURATIONLOADER_H_ + +#include +#include "../../../common/third_party/tinyxml2.h" +#include "../../../common/Utils.h" +#include "Configuration.h" + +namespace core { + +class ConfigurationLoader +{ +public: + static void loadMemConfig(Configuration& config, std::string memconfigUri); + static void loadSimConfig(Configuration& config, std::string simconfigUri); + + static void loadMemSpec(Configuration& config, std::string memspecUri); + static void loadMemSpec(Configuration& config, tinyxml2::XMLElement* memspec); + +private: + ConfigurationLoader(){} + static void loadConfig(Configuration& config, tinyxml2::XMLElement* configNode); + + //specific loader + static void loadDDR4(Configuration& config, tinyxml2::XMLElement* memspec); + static void loadWideIO(Configuration& config, tinyxml2::XMLElement* memspec); +}; + +} /* namespace core */ + +#endif /* CONFIGURATIONLOADER_H_ */ diff --git a/dram/src/controller/core/configuration/MemSpec.h b/dram/src/controller/core/configuration/MemSpec.h index 9a47ce35..5be412e5 100644 --- a/dram/src/controller/core/configuration/MemSpec.h +++ b/dram/src/controller/core/configuration/MemSpec.h @@ -11,6 +11,7 @@ #include #include #include "../../../common/dramExtension.h" + namespace core{ struct RefreshTiming diff --git a/dram/src/controller/core/configuration/MemSpecLoader.h b/dram/src/controller/core/configuration/MemSpecLoader.h deleted file mode 100644 index 7653075e..00000000 --- a/dram/src/controller/core/configuration/MemSpecLoader.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * MemSpecLoader.h - * - * Created on: Apr 7, 2014 - * Author: jonny - */ - -#ifndef MEMSPECLOADER_H_ -#define MEMSPECLOADER_H_ - -#include -#include "../../../common/third_party/tinyxml2.h" -#include "../../../common/Utils.h" -#include "Configuration.h" - -namespace core { - -class MemSpecLoader -{ -public: - void loadConfiguration(Configuration& config, std::string memspecUri, std::string memconfigUri); - -private: - void loadMemConfig(Configuration& config, tinyxml2::XMLElement* memspec); - void loadMemSpec(Configuration& config, tinyxml2::XMLElement* memspec); - void loadDDR4(Configuration& config, tinyxml2::XMLElement* memspec); - void loadWideIO(Configuration& config, tinyxml2::XMLElement* memspec); -}; - -} /* namespace core */ - -#endif /* MEMSPECLOADER_H_ */ diff --git a/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp index 2910ebd3..b4a3268a 100644 --- a/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp +++ b/dram/src/controller/core/powerdown/PowerDownManagerTimeout.cpp @@ -29,7 +29,7 @@ PowerDownManagerTimeout::~PowerDownManagerTimeout() void PowerDownManagerTimeout::sleep(Bank bank, sc_time time) { - if(canSleep() && !isInPowerDown() && (time - controller.state.getLastScheduledCommand().getEnd()) >= Configuration::getInstance().powerDownTimeout) + if(canSleep() && !isInPowerDown() && (time - controller.state.getLastScheduledCommand().getEnd()) >= Configuration::getInstance().getPowerDownTimeout()) { PowerDownState newState; if(Configuration::getInstance().powerDownMode == PowerDownMode::TimeoutPDN) @@ -106,7 +106,7 @@ void PowerDownManagerTimeout::triggerSleep(Bank /*bank*/, sc_time time) { if(canSleep() && !isInPowerDown()) { - controller.wrapper.send(PDNTrigger, time + controller.config.powerDownTimeout, powerDownPayloads[Bank(0)]); + controller.wrapper.send(PDNTrigger, time + controller.config.getPowerDownTimeout(), powerDownPayloads[Bank(0)]); } } diff --git a/dram/src/controller/core/scheduling/checker/WriteChecker.h b/dram/src/controller/core/scheduling/checker/WriteChecker.h index 64dd726e..28ba61d5 100644 --- a/dram/src/controller/core/scheduling/checker/WriteChecker.h +++ b/dram/src/controller/core/scheduling/checker/WriteChecker.h @@ -29,8 +29,6 @@ private: bool collidesWithStrobeCommand(ScheduledCommand& write, ScheduledCommand& strobeCommand) const; const Configuration& config; ControllerState& state; - - }; } /* namespace controller */ diff --git a/dram/src/simulation/Simulation.cpp b/dram/src/simulation/Simulation.cpp index 75113baf..2954caa0 100644 --- a/dram/src/simulation/Simulation.cpp +++ b/dram/src/simulation/Simulation.cpp @@ -10,6 +10,7 @@ #include "../common/DebugManager.h" #include "../common/xmlAddressdecoder.h" #include "../controller/core/ControllerCore.h" +#include "../controller/core/configuration/ConfigurationLoader.h" #include #include #include @@ -28,9 +29,12 @@ Simulation::Simulation(sc_module_name /*name*/, string pathToResources, string t xmlAddressDecoder::addressConfigURI = pathToResources + string("configs/amconfigs/") + setup.addressmapping; - Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig; + //Configuration::memconfigUri = pathToResources + string("configs/memconfigs/") + setup.memconfig; Configuration::memspecUri = pathToResources + string("configs/memspecs/") + setup.memspec; + ConfigurationLoader::loadMemConfig(Configuration::getInstance(), pathToResources + string("configs/memconfigs/") + setup.memconfig); + ConfigurationLoader::loadMemSpec(Configuration::getInstance(), pathToResources + string("configs/memspecs/") + setup.memspec); + setupTlmRecorder(traceName, pathToResources, setup, devices); instantiateModules(pathToResources, devices); bindSockets(); diff --git a/dram/src/simulation/TracePlayer.h b/dram/src/simulation/TracePlayer.h index fc05f2f1..0fa606ad 100644 --- a/dram/src/simulation/TracePlayer.h +++ b/dram/src/simulation/TracePlayer.h @@ -81,8 +81,8 @@ void TracePlayer::printDebugMessage(std::string message) DebugManager::getInstance().printDebugMessage(this->name(), message); } -//todo move template +//TODO: this doesn't depend on the tracePlayer, move it somewhere void TracePlayer::setDataPointer(gp* payload, unsigned char * dataElement) { //check if payload takes ownership diff --git a/dram/src/simulation/main.cpp b/dram/src/simulation/main.cpp index 72b44ef8..b49f816f 100644 --- a/dram/src/simulation/main.cpp +++ b/dram/src/simulation/main.cpp @@ -31,7 +31,6 @@ int main(int argc, char **argv) int sc_main(int argc, char **argv) { - cout<<"hello"<