From 330b07d0e71bfda6151fd98428669e4fc23ff522 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Wed, 18 Sep 2019 16:39:38 +0200 Subject: [PATCH] Changed data structures of Address Decoder for speedup. --- DRAMSys/library/src/common/AddressDecoder.cpp | 5 - DRAMSys/library/src/common/AddressDecoder.h | 17 ++- .../src/common/CongenAddressDecoder.cpp | 16 +-- .../library/src/common/CongenAddressDecoder.h | 4 +- .../library/src/common/XmlAddressDecoder.cpp | 109 ++++++++++++------ .../library/src/common/XmlAddressDecoder.h | 28 ++++- DRAMSys/library/src/common/utils.h | 2 +- DRAMSys/library/src/controller/Controller.cpp | 2 - .../core/configuration/Configuration.cpp | 4 +- DRAMSys/library/src/error/errormodel.cpp | 2 +- DRAMSys/library/src/error/errormodel.h | 4 +- DRAMSys/library/src/simulation/Arbiter.cpp | 25 ++-- DRAMSys/library/src/simulation/DRAMSys.cpp | 15 +-- DRAMSys/library/src/simulation/Dram.cpp | 2 +- .../library/src/simulation/ExampleInitiator.h | 2 +- DRAMSys/library/src/simulation/IArbiter.h | 16 +-- 16 files changed, 152 insertions(+), 101 deletions(-) diff --git a/DRAMSys/library/src/common/AddressDecoder.cpp b/DRAMSys/library/src/common/AddressDecoder.cpp index b0a3b98f..81ea1252 100644 --- a/DRAMSys/library/src/common/AddressDecoder.cpp +++ b/DRAMSys/library/src/common/AddressDecoder.cpp @@ -60,8 +60,3 @@ void AddressDecoder::createInstance(Type t) break; } } - -AddressDecoder::AddressDecoder() -{ - -} diff --git a/DRAMSys/library/src/common/AddressDecoder.h b/DRAMSys/library/src/common/AddressDecoder.h index d240088b..b49f6e81 100644 --- a/DRAMSys/library/src/common/AddressDecoder.h +++ b/DRAMSys/library/src/common/AddressDecoder.h @@ -71,7 +71,7 @@ public: }; protected: - AddressDecoder(); + AddressDecoder() {} static AddressDecoder *m_pInstance; public: @@ -80,12 +80,21 @@ public: virtual void setConfiguration(std::string url) = 0; - virtual DecodedAddress decodeAddress(sc_dt::uint64 addr) = 0; - virtual sc_dt::uint64 encodeAddress(DecodedAddress n) = 0; + virtual DecodedAddress decodeAddress(uint64_t addr) = 0; + virtual uint64_t encodeAddress(DecodedAddress n) = 0; virtual void print() = 0; - std::map amount; + struct Amount + { + unsigned channel = 1; + unsigned rank = 1; + unsigned bankgroup = 1; + unsigned bank = 1; + unsigned row = 1; + unsigned column = 1; + unsigned bytes = 1; + } amount; }; #endif // ADDRESSDECODER_H diff --git a/DRAMSys/library/src/common/CongenAddressDecoder.cpp b/DRAMSys/library/src/common/CongenAddressDecoder.cpp index ea11dcbc..fca1ea3b 100644 --- a/DRAMSys/library/src/common/CongenAddressDecoder.cpp +++ b/DRAMSys/library/src/common/CongenAddressDecoder.cpp @@ -188,14 +188,14 @@ void CongenAddressDecoder::setConfiguration(std::string url) } // Fill the amount map. This is copied from xmlAddressDecoder without further investigation - amount["channel"] = 1; - amount["bank"] = pow(2.0, m_vBankBits.size()); - amount["row"] = pow(2.0, m_vRowBits.size()); - amount["column"] = pow(2.0, m_vColumnBits.size()); - amount["bytes"] = pow(2.0, m_nByteBits); + amount.channel = 1; + amount.bank = pow(2.0, m_vBankBits.size()); + amount.row = pow(2.0, m_vRowBits.size()); + amount.column = pow(2.0, m_vColumnBits.size()); + amount.bytes = pow(2.0, m_nByteBits); } -DecodedAddress CongenAddressDecoder::decodeAddress(sc_dt::uint64 addr) +DecodedAddress CongenAddressDecoder::decodeAddress(uint64_t addr) { DecodedAddress result; @@ -251,9 +251,9 @@ DecodedAddress CongenAddressDecoder::decodeAddress(sc_dt::uint64 addr) return result; } -sc_dt::uint64 CongenAddressDecoder::encodeAddress(DecodedAddress n) +uint64_t CongenAddressDecoder::encodeAddress(DecodedAddress n) { - sc_dt::uint64 address = 0; + uint64_t address = 0; // Bank // it->first: position of the target bit in the DecodedAddress struct field diff --git a/DRAMSys/library/src/common/CongenAddressDecoder.h b/DRAMSys/library/src/common/CongenAddressDecoder.h index 51778ecf..ed523d9d 100644 --- a/DRAMSys/library/src/common/CongenAddressDecoder.h +++ b/DRAMSys/library/src/common/CongenAddressDecoder.h @@ -101,8 +101,8 @@ public: virtual void setConfiguration(std::string url); - virtual DecodedAddress decodeAddress(sc_dt::uint64 addr); - virtual sc_dt::uint64 encodeAddress(DecodedAddress n); + virtual DecodedAddress decodeAddress(uint64_t addr); + virtual uint64_t encodeAddress(DecodedAddress n); static bool testConfigFile(std::string url); diff --git a/DRAMSys/library/src/common/XmlAddressDecoder.cpp b/DRAMSys/library/src/common/XmlAddressDecoder.cpp index 1c819b57..325412f5 100644 --- a/DRAMSys/library/src/common/XmlAddressDecoder.cpp +++ b/DRAMSys/library/src/common/XmlAddressDecoder.cpp @@ -41,7 +41,6 @@ #include "bitset" #include "../controller/core/configuration/Configuration.h" -using namespace std; using namespace tinyxml2; XmlAddressDecoder::XmlAddressDecoder() @@ -56,54 +55,87 @@ void XmlAddressDecoder::setConfiguration(std::string addressConfigURI) tinyxml2::XMLElement *addressMap = doc.RootElement(); string xmlNodeName(addressMap->Name()); - if ( xmlNodeName != "addressmapping") { + if (xmlNodeName != "addressmapping") reportFatal("AddressDecorder", "addressmap node expected"); - } for (XMLElement *child = addressMap->FirstChildElement(); - child != NULL; - child = child->NextSiblingElement()) { - int from; - int to; + child != NULL; child = child->NextSiblingElement()) + { + unsigned from; + unsigned to; child->QueryAttribute("from", &from); child->QueryAttribute("to", &to); - shifts[child->Name()] = from; - masks[child->Name()] = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); - amount[child->Name()] = pow(2.0, to - from + 1.0); + if (std::strcmp(child->Name(), "channel") == 0) + { + shifts.channel = from; + masks.channel = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.channel = pow(2.0, to - from + 1.0); + } + else if (std::strcmp(child->Name(), "rank") == 0) + { + shifts.rank = from; + masks.rank = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.rank = pow(2.0, to - from + 1.0); + std::cout << "Inside rank" << std::endl; + } + else if (std::strcmp(child->Name(), "bank") == 0) + { + shifts.bank = from; + masks.bank = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.bank = pow(2.0, to - from + 1.0); + } + else if (std::strcmp(child->Name(), "row") == 0) + { + shifts.row = from; + masks.row = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.row = pow(2.0, to - from + 1.0); + } + else if (std::strcmp(child->Name(), "column") == 0) + { + shifts.column = from; + masks.column = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.column = pow(2.0, to - from + 1.0); + } + else if (std::strcmp(child->Name(), "bytes") == 0) + { + shifts.bytes = from; + masks.bytes = pow(2.0, to + 1.0) - pow(2.0, from + 0.0); + amount.bytes = pow(2.0, to - from + 1.0); + } + else + SC_REPORT_FATAL("XmlAddressDecoder", ("Unknown field " + std::string(child->Name())).c_str()); } + + banksPerRank = amount.bank; + amount.bank = amount.bank * amount.rank; + amount.bankgroup = Configuration::getInstance().memSpec->NumberOfBankGroups; + banksPerGroup = amount.bank / amount.bankgroup; } -DecodedAddress XmlAddressDecoder::decodeAddress(sc_dt::uint64 addr) +DecodedAddress XmlAddressDecoder::decodeAddress(uint64_t addr) { DecodedAddress result; - result.channel = (addr & masks["channel"]) >> shifts["channel"]; - result.rank = (addr & masks["rank"]) >> shifts["rank"]; - //result.bankgroup = (addr & masks["bankgroup"]) >> shifts["bankgroup"]; - unsigned banksPerRank = Configuration::getInstance().memSpec->NumberOfBanks - / Configuration::getInstance().memSpec->NumberOfRanks; - result.bank = ((addr & masks["bank"]) >> shifts["bank"]) + result.rank * banksPerRank; - unsigned banksPerGroup = Configuration::getInstance().memSpec->NumberOfBanks - / Configuration::getInstance().memSpec->NumberOfBankGroups; + result.channel = (addr & masks.channel) >> shifts.channel; + result.rank = (addr & masks.rank) >> shifts.rank; result.bankgroup = result.bank / banksPerGroup; - //result.rank = result.bank % Configuration::getInstance().memSpec->NumberOfRanks; - result.row = (addr & masks["row"]) >> shifts["row"]; - result.column = (addr & masks["column"]) >> shifts["column"]; - result.bytes = (addr & masks["bytes"]) >> shifts["bytes"]; + result.bank = ((addr & masks.bank) >> shifts.bank) + result.rank * banksPerRank; + result.row = (addr & masks.row) >> shifts.row; + result.column = (addr & masks.column) >> shifts.column; + result.bytes = (addr & masks.bytes) >> shifts.bytes; return result; } -sc_dt::uint64 XmlAddressDecoder::encodeAddress(DecodedAddress n) +uint64_t XmlAddressDecoder::encodeAddress(DecodedAddress n) { - return n.channel << shifts["channel"] | - n.rank << shifts["rank"] | - n.bankgroup << shifts["bankgroup"] | - n.row << shifts["row"] | - n.bank << shifts["bank"] | - n.column << shifts["column"] | - n.bytes << shifts["bytes"]; + return (n.channel << shifts.channel) | + (n.rank << shifts.rank) | + ((n.bank % banksPerRank) << shifts.bank) | + (n.row << shifts.row) | + (n.column << shifts.column) | + (n.bytes << shifts.bytes); } bool XmlAddressDecoder::testConfigFile(std::string url) @@ -120,10 +152,13 @@ bool XmlAddressDecoder::testConfigFile(std::string url) void XmlAddressDecoder::print() { - cout << headline << endl; - cout << "Address Mapping:" << endl << endl; - for (auto &pair : masks) { - cout << std::setw(16) << pair.first << ": " << bitset<48>(pair.second) << endl; - } - cout << endl; + std::cout << headline << std::endl; + std::cout << "Address Mapping:" << std::endl << std::endl; + std::cout << std::setw(10) << "channel: " << std::bitset<64>(masks.channel) << std::endl; + std::cout << std::setw(10) << "rank: " << std::bitset<64>(masks.rank) << std::endl; + std::cout << std::setw(10) << "bank: " << std::bitset<64>(masks.bank) << std::endl; + std::cout << std::setw(10) << "row: " << std::bitset<64>(masks.row) << std::endl; + std::cout << std::setw(10) << "column: " << std::bitset<64>(masks.column) << std::endl; + std::cout << std::setw(10) << "bytes: " << std::bitset<64>(masks.bytes) << std::endl; + std::cout << std::endl; } diff --git a/DRAMSys/library/src/common/XmlAddressDecoder.h b/DRAMSys/library/src/common/XmlAddressDecoder.h index dfd65072..b0c848d7 100644 --- a/DRAMSys/library/src/common/XmlAddressDecoder.h +++ b/DRAMSys/library/src/common/XmlAddressDecoder.h @@ -51,16 +51,36 @@ class XmlAddressDecoder : private AddressDecoder friend class AddressDecoder; private: - std::map masks; - std::map shifts; + struct Masks + { + uint64_t channel = 0; + uint64_t rank = 0; + uint64_t bank = 0; + uint64_t row = 0; + uint64_t column = 0; + uint64_t bytes = 0; + } masks; + + struct Shifts + { + unsigned channel = 0; + unsigned rank = 0; + unsigned bank = 0; + unsigned row = 0; + unsigned column = 0; + unsigned bytes = 0; + } shifts; + + unsigned banksPerGroup; + unsigned banksPerRank; tinyxml2::XMLElement *addressmapping; public: XmlAddressDecoder(); - virtual DecodedAddress decodeAddress(sc_dt::uint64 addr); - virtual sc_dt::uint64 encodeAddress(DecodedAddress n); + virtual DecodedAddress decodeAddress(uint64_t addr); + virtual uint64_t encodeAddress(DecodedAddress n); void setConfiguration(std::string url); diff --git a/DRAMSys/library/src/common/utils.h b/DRAMSys/library/src/common/utils.h index 003c6829..e997d99a 100644 --- a/DRAMSys/library/src/common/utils.h +++ b/DRAMSys/library/src/common/utils.h @@ -92,7 +92,7 @@ bool isIn(const T &value, const std::vector &collection) } constexpr const char headline[] = - "========================================================="; + "=========================================================================="; static inline void loadbar(unsigned int x, unsigned int n, diff --git a/DRAMSys/library/src/controller/Controller.cpp b/DRAMSys/library/src/controller/Controller.cpp index 8c98beb5..15ae1e7a 100644 --- a/DRAMSys/library/src/controller/Controller.cpp +++ b/DRAMSys/library/src/controller/Controller.cpp @@ -213,8 +213,6 @@ tlm_sync_enum Controller::nb_transport_fw(tlm_generic_payload &trans, payloadToAcquire = &trans; timeToAcquire = sc_time_stamp() + notificationDelay; beginReqEvent.notify(notificationDelay); -// std::cout << "Bank: " << DramExtension::getBank(trans).ID() << ", BankGroup: " -// << DramExtension::getBankGroup(trans).ID() << ", Rank: " << DramExtension::getRank(trans).ID() << std::endl; } else if (phase = END_RESP) { diff --git a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp index db52486c..724c2043 100644 --- a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp @@ -186,7 +186,7 @@ void Configuration::setParameter(std::string name, std::string value) else if (name == "NumberOfMemChannels") { NumberOfMemChannels = string2int(value); unsigned int maxNumberofMemChannels = - AddressDecoder::getInstance().amount["channel"]; + AddressDecoder::getInstance().amount.channel; if (NumberOfMemChannels > maxNumberofMemChannels) { SC_REPORT_FATAL("Configuration", ("Invalid value for parameter " + name @@ -384,7 +384,7 @@ unsigned int Configuration::getBytesPerBurst() // offset of the N-byte-wide memory module (DIMM) (a single data word // or burst element has N bytes. N = 2^(# bits for byte offset)). unsigned int burstElementSizeInBytes = - AddressDecoder::getInstance().amount["bytes"]; + AddressDecoder::getInstance().amount.bytes; assert(bytesPerBurst == (burstElementSizeInBytes * memSpec->BurstLength)); } diff --git a/DRAMSys/library/src/error/errormodel.cpp b/DRAMSys/library/src/error/errormodel.cpp index cb73ee11..b23b8dff 100644 --- a/DRAMSys/library/src/error/errormodel.cpp +++ b/DRAMSys/library/src/error/errormodel.cpp @@ -48,7 +48,7 @@ void errorModel::init() // Get Configuration parameters: burstLenght = Configuration::getInstance().memSpec->BurstLength; numberOfColumns = Configuration::getInstance().memSpec->NumberOfColumns; - bytesPerColumn = AddressDecoder::getInstance().amount["bytes"]; + bytesPerColumn = AddressDecoder::getInstance().amount.bytes; // Adjust number of bytes per column dynamically to the selected ecc controller bytesPerColumn = Configuration::getInstance().adjustNumBytesAfterECC( diff --git a/DRAMSys/library/src/error/errormodel.h b/DRAMSys/library/src/error/errormodel.h index 7dab8f3f..23101b75 100644 --- a/DRAMSys/library/src/error/errormodel.h +++ b/DRAMSys/library/src/error/errormodel.h @@ -117,8 +117,8 @@ private: bool operator()( const DecodedAddress &first , const DecodedAddress &second) const { - sc_dt::uint64 addrFirst = AddressDecoder::getInstance().encodeAddress(first); - sc_dt::uint64 addrSecond = AddressDecoder::getInstance().encodeAddress(second); + uint64_t addrFirst = AddressDecoder::getInstance().encodeAddress(first); + uint64_t addrSecond = AddressDecoder::getInstance().encodeAddress(second); return addrFirst < addrSecond; } }; diff --git a/DRAMSys/library/src/simulation/Arbiter.cpp b/DRAMSys/library/src/simulation/Arbiter.cpp index 45554403..f275e057 100644 --- a/DRAMSys/library/src/simulation/Arbiter.cpp +++ b/DRAMSys/library/src/simulation/Arbiter.cpp @@ -229,24 +229,17 @@ void Arbiter::appendDramExtension(int socketId, tlm_generic_payload &payload) bool Arbiter::addressIsValid(DecodedAddress &decodedAddress) { - // TODO: correct this function - if (decodedAddress.channel >= AddressDecoder::getInstance().amount["channel"]) { + if (decodedAddress.channel >= AddressDecoder::getInstance().amount.channel) return false; - } -// if (decodedAddress.rank >= AddressDecoder::getInstance().amount["rank"]) { -// return false; -// } -// if (decodedAddress.bank >= AddressDecoder::getInstance().amount["bank"]) { -// return false; -// } -// if (decodedAddress.bankgroup >= AddressDecoder::getInstance().amount["bankgroup"]) { -// return false; -// } - if (decodedAddress.column >= AddressDecoder::getInstance().amount["column"]) { + if (decodedAddress.rank >= AddressDecoder::getInstance().amount.rank) return false; - } - if (decodedAddress.row >= AddressDecoder::getInstance().amount["row"]) { + if (decodedAddress.bankgroup >= AddressDecoder::getInstance().amount.bankgroup) + return false; + if (decodedAddress.bank >= AddressDecoder::getInstance().amount.bank) + return false; + if (decodedAddress.row >= AddressDecoder::getInstance().amount.row) + return false; + if (decodedAddress.column >= AddressDecoder::getInstance().amount.column) return false; - } return true; } diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index 3d5bba3a..bfb16a85 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -87,10 +87,16 @@ DRAMSys::DRAMSys(sc_module_name name, Configuration::getInstance().setPathToResources(pathToResources); + // MemSpec must be initialized first because AddressDecoder needs + // the number of bankgroups + ConfigurationLoader::loadMemSpec(Configuration::getInstance(), + pathToResources + + "configs/memspecs/" + + memspec); + // The xmlAddressDecoder MUST be initialized before calling the // ConfigurationLoader because some information from the xmlAddressDecoder // is needed to assure the coherence of the configuration. - if (XmlAddressDecoder::testConfigFile(pathToResources + "configs/amconfigs/" + amconfig)) { AddressDecoder::createInstance(AddressDecoder::Type::XML); @@ -109,7 +115,7 @@ DRAMSys::DRAMSys(sc_module_name name, AddressDecoder::getInstance().print(); - // Setup the memory controller with the propriate xml file + // Setup rest of the memory controller with the propriate xml file ConfigurationLoader::loadMCConfig(Configuration::getInstance(), pathToResources + "configs/mcconfigs/" @@ -125,11 +131,6 @@ DRAMSys::DRAMSys(sc_module_name name, + "configs/thermalsim/" + thermalconfig); - ConfigurationLoader::loadMemSpec(Configuration::getInstance(), - pathToResources - + "configs/memspecs/" - + memspec); - // If a simulation file is passed as argument to DRAMSys the simulation ID // is prepended to the simulation name if found. std::string simName; diff --git a/DRAMSys/library/src/simulation/Dram.cpp b/DRAMSys/library/src/simulation/Dram.cpp index 092221c3..53827b65 100644 --- a/DRAMSys/library/src/simulation/Dram.cpp +++ b/DRAMSys/library/src/simulation/Dram.cpp @@ -226,7 +226,7 @@ unsigned int Dram::transport_dbg(tlm_generic_payload &trans) else { tlm_command cmd = trans.get_command(); - //sc_dt::uint64 adr = trans.get_address(); // TODO: - offset; + //uint64_t adr = trans.get_address(); // TODO: - offset; unsigned char *ptr = trans.get_data_ptr(); unsigned int len = trans.get_data_length(); //unsigned int bank = DramExtension::getExtension(trans).getBank().ID(); diff --git a/DRAMSys/library/src/simulation/ExampleInitiator.h b/DRAMSys/library/src/simulation/ExampleInitiator.h index 7b227709..45233838 100644 --- a/DRAMSys/library/src/simulation/ExampleInitiator.h +++ b/DRAMSys/library/src/simulation/ExampleInitiator.h @@ -185,7 +185,7 @@ struct ExampleInitiator : sc_module } tlm::tlm_command cmd = trans.get_command(); - sc_dt::uint64 adr = trans.get_address(); + uint64_t adr = trans.get_address(); int *ptr = reinterpret_cast( trans.get_data_ptr() ); cout << hex << adr << " check, cmd=" << (cmd ? "write" : "read") diff --git a/DRAMSys/library/src/simulation/IArbiter.h b/DRAMSys/library/src/simulation/IArbiter.h index 8826610f..5b18dc1a 100644 --- a/DRAMSys/library/src/simulation/IArbiter.h +++ b/DRAMSys/library/src/simulation/IArbiter.h @@ -114,21 +114,21 @@ protected: bool addressIsValid(DecodedAddress &decodedAddress) { if (decodedAddress.channel >= - XmlAddressDecoder::getInstance().amount["channel"]) { + XmlAddressDecoder::getInstance().amount.channel) { return false; } - if (decodedAddress.bank >= XmlAddressDecoder::getInstance().amount["bank"]) { - return false; - } - if (decodedAddress.bankgroup > - XmlAddressDecoder::getInstance().amount["bankgroup"]) { + if (decodedAddress.bank >= XmlAddressDecoder::getInstance().amount.bank) { return false; } +// if (decodedAddress.bankgroup > +// XmlAddressDecoder::getInstance().amount["bankgroup"]) { +// return false; +// } if (decodedAddress.column >= - XmlAddressDecoder::getInstance().amount["column"]) { + XmlAddressDecoder::getInstance().amount.column) { return false; } - if (decodedAddress.row >= XmlAddressDecoder::getInstance().amount["row"]) { + if (decodedAddress.row >= XmlAddressDecoder::getInstance().amount.row) { return false; } return true;