From ac950afda9a88fae4428d2e9863d816520962ede Mon Sep 17 00:00:00 2001 From: Johannes Feldmann Date: Mon, 26 Mar 2018 16:04:17 +0200 Subject: [PATCH] Created base class for XMLAddressDecoder and created an alternative JSONAddressDecoder class. This class has still no functionality. --- DRAMSys/library/library.pro | 8 +- DRAMSys/library/src/common/AddressDecoder.cpp | 28 ++++++ DRAMSys/library/src/common/AddressDecoder.h | 93 +++++++++++++++++++ .../library/src/common/jsonAddressDecoder.cpp | 44 +++++++++ .../library/src/common/jsonAddressDecoder.h | 58 ++++++++++++ .../library/src/common/xmlAddressdecoder.cpp | 17 +--- .../library/src/common/xmlAddressdecoder.h | 37 ++------ .../core/configuration/Configuration.cpp | 4 +- DRAMSys/library/src/error/errormodel.cpp | 6 +- DRAMSys/library/src/error/errormodel.h | 4 +- DRAMSys/library/src/simulation/Arbiter.h | 14 +-- DRAMSys/library/src/simulation/DRAMSys.cpp | 23 ++++- 12 files changed, 269 insertions(+), 67 deletions(-) create mode 100644 DRAMSys/library/src/common/AddressDecoder.cpp create mode 100644 DRAMSys/library/src/common/AddressDecoder.h create mode 100644 DRAMSys/library/src/common/jsonAddressDecoder.cpp create mode 100644 DRAMSys/library/src/common/jsonAddressDecoder.h diff --git a/DRAMSys/library/library.pro b/DRAMSys/library/library.pro index ad74744a..20a1eb2d 100644 --- a/DRAMSys/library/library.pro +++ b/DRAMSys/library/library.pro @@ -119,7 +119,9 @@ SOURCES += \ src/error/eccbaseclass.cpp \ src/error/ecchamming.cpp \ src/controller/scheduler/Fr_Fcfs_read_priority.cpp \ - src/controller/scheduler/Fr_Fcfs_grouper.cpp + src/controller/scheduler/Fr_Fcfs_grouper.cpp \ + src/common/AddressDecoder.cpp \ + src/common/jsonAddressDecoder.cpp HEADERS += \ src/common/third_party/tinyxml2/tinyxml2.h \ @@ -190,7 +192,9 @@ HEADERS += \ src/error/eccbaseclass.h \ src/error/ecchamming.h \ src/controller/scheduler/Fr_Fcfs_read_priority.h \ - src/controller/scheduler/Fr_Fcfs_grouper.h + src/controller/scheduler/Fr_Fcfs_grouper.h \ + src/common/AddressDecoder.h \ + src/common/jsonAddressDecoder.h thermalsim = $$(THERMALSIM) isEmpty(thermalsim) { diff --git a/DRAMSys/library/src/common/AddressDecoder.cpp b/DRAMSys/library/src/common/AddressDecoder.cpp new file mode 100644 index 00000000..a473b442 --- /dev/null +++ b/DRAMSys/library/src/common/AddressDecoder.cpp @@ -0,0 +1,28 @@ +#include "AddressDecoder.h" +#include "xmlAddressdecoder.h" +#include "jsonAddressDecoder.h" + +CAddressDecoder* CAddressDecoder::m_pInstance = nullptr; + +CAddressDecoder& CAddressDecoder::getInstance() +{ + assert(m_pInstance != nullptr); + return *m_pInstance; +} + +void CAddressDecoder::createInstance(Type t) +{ + assert(m_pInstance == nullptr); + switch(t) + { + case Type::XML: + m_pInstance = new xmlAddressDecoder; + case Type::JSON: + m_pInstance = new JSONAddressDecoder; + } +} + +CAddressDecoder::CAddressDecoder() +{ + +} diff --git a/DRAMSys/library/src/common/AddressDecoder.h b/DRAMSys/library/src/common/AddressDecoder.h new file mode 100644 index 00000000..c5c23a70 --- /dev/null +++ b/DRAMSys/library/src/common/AddressDecoder.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018, 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: + * Johannes Feldmann + */ + +#ifndef ADDRESSDECODER_H +#define ADDRESSDECODER_H + +#include +#include +#include +#include +#include + +struct DecodedAddress +{ + DecodedAddress() : channel(0), + rank(0), + bankgroup(0), + row(0), + bank(0), + column(0), + bytes(0) + { + } + + unsigned int channel; + unsigned int rank; + unsigned int bankgroup; + unsigned int row; + unsigned int bank; + unsigned int column; + unsigned int bytes; +}; + +class CAddressDecoder +{ +public: + enum class Type + { + XML, + JSON + }; + +protected: + CAddressDecoder(); + + static CAddressDecoder* m_pInstance; +public: + static CAddressDecoder& getInstance(); + static void createInstance(Type t); + + virtual void setConfiguration(std::string url) = 0; + + virtual DecodedAddress decodeAddress(sc_dt::uint64 addr) = 0; + virtual sc_dt::uint64 encodeAddress(DecodedAddress n) = 0; + + virtual void print() = 0; + + std::map amount; +}; + +#endif // ADDRESSDECODER_H diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.cpp b/DRAMSys/library/src/common/jsonAddressDecoder.cpp new file mode 100644 index 00000000..d82f41bf --- /dev/null +++ b/DRAMSys/library/src/common/jsonAddressDecoder.cpp @@ -0,0 +1,44 @@ +#include "jsonAddressDecoder.h" + +#include + +using std::ifstream; +using std::cout; +using std::endl; + +JSONAddressDecoder::JSONAddressDecoder() +{ + +} + +void JSONAddressDecoder::setConfiguration(std::string url) +{ + ifstream file; + + file.open(url); + + if(!file.is_open()) + { + cout << "Unable to open file " << url << endl; + return; + } + + file.close(); +} + +DecodedAddress JSONAddressDecoder::decodeAddress(sc_dt::uint64 addr) +{ + DecodedAddress result; + + return result; +} + +sc_dt::uint64 JSONAddressDecoder::encodeAddress(DecodedAddress n) +{ + return 0; +} + +void JSONAddressDecoder::print() +{ + +} diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.h b/DRAMSys/library/src/common/jsonAddressDecoder.h new file mode 100644 index 00000000..bc5eb8df --- /dev/null +++ b/DRAMSys/library/src/common/jsonAddressDecoder.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, 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: + * Johannes Feldmann + */ + +#ifndef JSONADDRESSDECODER_H +#define JSONADDRESSDECODER_H + +#include "AddressDecoder.h" + +class JSONAddressDecoder + : public CAddressDecoder +{ + friend class CAddressDecoder; + +private: + JSONAddressDecoder(); + +public: + virtual void setConfiguration(std::string url); + + virtual DecodedAddress decodeAddress(sc_dt::uint64 addr); + virtual sc_dt::uint64 encodeAddress(DecodedAddress n); + + virtual void print(); +}; + +#endif // JSONADDRESSDECODER_H diff --git a/DRAMSys/library/src/common/xmlAddressdecoder.cpp b/DRAMSys/library/src/common/xmlAddressdecoder.cpp index 31304f1d..639631fa 100644 --- a/DRAMSys/library/src/common/xmlAddressdecoder.cpp +++ b/DRAMSys/library/src/common/xmlAddressdecoder.cpp @@ -49,26 +49,11 @@ xmlAddressDecoder::xmlAddressDecoder() addressmapping = NULL; } -xmlAddressDecoder::xmlAddressDecoder(string addressConfigURI) -{ - setConfiguration(addressConfigURI); -} - -xmlAddressDecoder::xmlAddressDecoder(XMLElement* addressmap) -{ - setConfiguration(addressmap); -} - void xmlAddressDecoder::setConfiguration(std::string addressConfigURI) { tinyxml2::XMLDocument doc; loadXML(addressConfigURI, doc); - setConfiguration(doc.RootElement()); -} - -void xmlAddressDecoder::setConfiguration(tinyxml2::XMLElement* addressMap) -{ - tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* addressMap = doc.RootElement(); string xmlNodeName(addressMap->Name()); if( xmlNodeName != "addressmapping") diff --git a/DRAMSys/library/src/common/xmlAddressdecoder.h b/DRAMSys/library/src/common/xmlAddressdecoder.h index 0e9094fb..ed300670 100644 --- a/DRAMSys/library/src/common/xmlAddressdecoder.h +++ b/DRAMSys/library/src/common/xmlAddressdecoder.h @@ -38,45 +38,20 @@ #ifndef _XMLADDRESSDECODER_H #define _XMLADDRESSDECODER_H -#include -#include -#include -#include #include -#include #include "Utils.h" #include "third_party/tinyxml2/tinyxml2.h" - -struct DecodedAddress -{ - DecodedAddress() : channel(0), - rank(0), - bankgroup(0), - row(0), - bank(0), - column(0), - bytes(0) - { - } - - unsigned int channel; - unsigned int rank; - unsigned int bankgroup; - unsigned int row; - unsigned int bank; - unsigned int column; - unsigned int bytes; -}; +#include "AddressDecoder.h" class xmlAddressDecoder + : public CAddressDecoder { + friend class CAddressDecoder; - private: +private: xmlAddressDecoder(); - xmlAddressDecoder(std::string URI); - xmlAddressDecoder(tinyxml2::XMLElement* addressMap); std::map masks; std::map shifts; @@ -84,13 +59,13 @@ class xmlAddressDecoder tinyxml2::XMLElement* addressmapping; public: - DEF_SINGLETON(xmlAddressDecoder); - DecodedAddress decodeAddress(sc_dt::uint64 addr); sc_dt::uint64 encodeAddress(DecodedAddress n); void setConfiguration(std::string url); +private: void setConfiguration(tinyxml2::XMLElement* addressMap); +public: void print(); std::map amount; diff --git a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp index 93a1d523..29cc6f94 100644 --- a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp +++ b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp @@ -191,7 +191,7 @@ void Configuration::setParameter(std::string name, std::string value) Debug = string2bool(value); else if (name == "NumberOfMemChannels") { NumberOfMemChannels = string2int(value); - unsigned int maxNumberofMemChannels = xmlAddressDecoder::getInstance().amount["channel"]; + unsigned int maxNumberofMemChannels = CAddressDecoder::getInstance().amount["channel"]; if (NumberOfMemChannels > maxNumberofMemChannels) { SC_REPORT_FATAL("Configuration", ("Invalid value for parameter " + name @@ -349,7 +349,7 @@ unsigned int Configuration::getBytesPerBurst() // The least significant bits of the physical address are the byte // 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 = xmlAddressDecoder::getInstance().amount["bytes"]; + unsigned int burstElementSizeInBytes = CAddressDecoder::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 e1010f6a..18966452 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 = xmlAddressDecoder::getInstance().amount["bytes"]; + bytesPerColumn = CAddressDecoder::getInstance().amount["bytes"]; // Adjust number of bytes per column dynamically to the selected ecc controller bytesPerColumn = Configuration::getInstance().adjustNumBytesAfterECC(bytesPerColumn); @@ -157,7 +157,7 @@ void errorModel::store(tlm::tlm_generic_payload &trans) markBitFlips(); // Get the key for the dataMap from the transaction's address: - DecodedAddress key = xmlAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress key = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); // Set context: setContext(key); @@ -225,7 +225,7 @@ void errorModel::load(tlm::tlm_generic_payload &trans) markBitFlips(); // Get the key for the dataMap from the transaction's address: - DecodedAddress key = xmlAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress key = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); // Set context: setContext(key); diff --git a/DRAMSys/library/src/error/errormodel.h b/DRAMSys/library/src/error/errormodel.h index d85027c5..d3914c6c 100644 --- a/DRAMSys/library/src/error/errormodel.h +++ b/DRAMSys/library/src/error/errormodel.h @@ -120,8 +120,8 @@ class errorModel : public sc_module { bool operator()( const DecodedAddress& first , const DecodedAddress& second) const { - sc_dt::uint64 addrFirst = xmlAddressDecoder::getInstance().encodeAddress(first); - sc_dt::uint64 addrSecond = xmlAddressDecoder::getInstance().encodeAddress(second); + sc_dt::uint64 addrFirst = CAddressDecoder::getInstance().encodeAddress(first); + sc_dt::uint64 addrSecond = CAddressDecoder::getInstance().encodeAddress(second); return addrFirst < addrSecond; } }; diff --git a/DRAMSys/library/src/simulation/Arbiter.h b/DRAMSys/library/src/simulation/Arbiter.h index 114e3d03..5b60b410 100644 --- a/DRAMSys/library/src/simulation/Arbiter.h +++ b/DRAMSys/library/src/simulation/Arbiter.h @@ -151,7 +151,7 @@ private: // adjust address offset: trans.set_address(trans.get_address() - Configuration::getInstance().AddressOffset); - DecodedAddress decodedAddress = xmlAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress decodedAddress = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); return iSocket[decodedAddress.channel]->transport_dbg(trans); } @@ -248,7 +248,7 @@ private: payload.set_auto_extension(genExtension); unsigned int burstlength = payload.get_streaming_width(); - DecodedAddress decodedAddress = xmlAddressDecoder::getInstance().decodeAddress(payload.get_address()); + DecodedAddress decodedAddress = CAddressDecoder::getInstance().decodeAddress(payload.get_address()); // Check the valid range of decodedAddress if (addressIsValid(decodedAddress)) { DramExtension* extension = new DramExtension(Thread(socketId+1), Channel(decodedAddress.channel), Bank(decodedAddress.bank), BankGroup(decodedAddress.bankgroup), Row(decodedAddress.row), Column(decodedAddress.column),burstlength); @@ -260,19 +260,19 @@ private: bool addressIsValid(DecodedAddress& decodedAddress) { - if (decodedAddress.channel >= xmlAddressDecoder::getInstance().amount["channel"]) { + if (decodedAddress.channel >= CAddressDecoder::getInstance().amount["channel"]) { return false; } - if (decodedAddress.bank >= xmlAddressDecoder::getInstance().amount["bank"]) { + if (decodedAddress.bank >= CAddressDecoder::getInstance().amount["bank"]) { return false; } - if (decodedAddress.bankgroup > xmlAddressDecoder::getInstance().amount["bankgroup"]) { + if (decodedAddress.bankgroup > CAddressDecoder::getInstance().amount["bankgroup"]) { return false; } - if (decodedAddress.column >= xmlAddressDecoder::getInstance().amount["column"]) { + if (decodedAddress.column >= CAddressDecoder::getInstance().amount["column"]) { return false; } - if (decodedAddress.row >= xmlAddressDecoder::getInstance().amount["row"]) { + if (decodedAddress.row >= CAddressDecoder::getInstance().amount["row"]) { return false; } return true; diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index ea544ee4..403435d4 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -83,10 +83,25 @@ DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, // The xmlAddressDecoder MUST be initialized before calling the // ConfigurationLoader because some information from the xmlAddressDecoder // is needed to assure the coherence of the configuration. - xmlAddressDecoder::getInstance().setConfiguration(pathToResources - + "configs/amconfigs/" - + amconfig); - xmlAddressDecoder::getInstance().print(); + + if(amconfig.find(".xml") != string::npos) + { + CAddressDecoder::createInstance(CAddressDecoder::Type::XML); + CAddressDecoder::getInstance().setConfiguration(pathToResources + + "configs/amconfigs/" + + amconfig); + } + else if(amconfig.find(".json") != string::npos) + { + CAddressDecoder::createInstance(CAddressDecoder::Type::JSON); + CAddressDecoder::getInstance().setConfiguration(pathToResources + amconfig); + } + else + { + cout << "No address mapping loaded. Unknown file extension" << endl; + } + + CAddressDecoder::getInstance().print(); ConfigurationLoader::loadMemSpec(Configuration::getInstance(), pathToResources