From ff91c37df335f3806b40efff556e5087cefe328f Mon Sep 17 00:00:00 2001 From: Johannes Feldmann Date: Fri, 30 Mar 2018 17:51:12 +0200 Subject: [PATCH] Changes suggest by review colleagues. --- DRAMSys/library/src/common/AddressDecoder.cpp | 43 +++++++++++++++++-- DRAMSys/library/src/common/AddressDecoder.h | 8 ++-- .../library/src/common/jsonAddressDecoder.cpp | 35 +++++++++++++++ .../library/src/common/jsonAddressDecoder.h | 6 ++- .../library/src/common/xmlAddressdecoder.h | 6 ++- .../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 | 10 ++--- 10 files changed, 105 insertions(+), 31 deletions(-) diff --git a/DRAMSys/library/src/common/AddressDecoder.cpp b/DRAMSys/library/src/common/AddressDecoder.cpp index 938129c8..63e2e921 100644 --- a/DRAMSys/library/src/common/AddressDecoder.cpp +++ b/DRAMSys/library/src/common/AddressDecoder.cpp @@ -1,16 +1,51 @@ +/* + * 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 + */ + #include "AddressDecoder.h" #include "xmlAddressdecoder.h" #include "jsonAddressDecoder.h" -CAddressDecoder* CAddressDecoder::m_pInstance = nullptr; +AddressDecoder* AddressDecoder::m_pInstance = nullptr; -CAddressDecoder& CAddressDecoder::getInstance() +AddressDecoder& AddressDecoder::getInstance() { assert(m_pInstance != nullptr); return *m_pInstance; } -void CAddressDecoder::createInstance(Type t) +void AddressDecoder::createInstance(Type t) { assert(m_pInstance == nullptr); switch(t) @@ -24,7 +59,7 @@ void CAddressDecoder::createInstance(Type t) } } -CAddressDecoder::CAddressDecoder() +AddressDecoder::AddressDecoder() { } diff --git a/DRAMSys/library/src/common/AddressDecoder.h b/DRAMSys/library/src/common/AddressDecoder.h index c5c23a70..be74980f 100644 --- a/DRAMSys/library/src/common/AddressDecoder.h +++ b/DRAMSys/library/src/common/AddressDecoder.h @@ -63,7 +63,7 @@ struct DecodedAddress unsigned int bytes; }; -class CAddressDecoder +class AddressDecoder { public: enum class Type @@ -73,11 +73,11 @@ public: }; protected: - CAddressDecoder(); + AddressDecoder(); - static CAddressDecoder* m_pInstance; + static AddressDecoder* m_pInstance; public: - static CAddressDecoder& getInstance(); + static AddressDecoder& getInstance(); static void createInstance(Type t); virtual void setConfiguration(std::string url) = 0; diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.cpp b/DRAMSys/library/src/common/jsonAddressDecoder.cpp index dd9c8b62..9fdf09bd 100644 --- a/DRAMSys/library/src/common/jsonAddressDecoder.cpp +++ b/DRAMSys/library/src/common/jsonAddressDecoder.cpp @@ -1,3 +1,38 @@ +/* + * 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 + */ + #include "jsonAddressDecoder.h" #include "Utils.h" diff --git a/DRAMSys/library/src/common/jsonAddressDecoder.h b/DRAMSys/library/src/common/jsonAddressDecoder.h index 354b7513..475d084d 100644 --- a/DRAMSys/library/src/common/jsonAddressDecoder.h +++ b/DRAMSys/library/src/common/jsonAddressDecoder.h @@ -46,9 +46,11 @@ using std::pair; using std::map; class JSONAddressDecoder - : public CAddressDecoder + : public AddressDecoder { - friend class CAddressDecoder; + // Friendship needed so that the AddressDecoder can access the + // constructor of this class to create the object in CreateInstance. + friend class AddressDecoder; private: JSONAddressDecoder(); diff --git a/DRAMSys/library/src/common/xmlAddressdecoder.h b/DRAMSys/library/src/common/xmlAddressdecoder.h index 03ade6c5..7266b8df 100644 --- a/DRAMSys/library/src/common/xmlAddressdecoder.h +++ b/DRAMSys/library/src/common/xmlAddressdecoder.h @@ -45,9 +45,11 @@ #include "AddressDecoder.h" class xmlAddressDecoder - : public CAddressDecoder + : public AddressDecoder { - friend class CAddressDecoder; + // Friendship needed so that the AddressDecoder can access the + // constructor of this class to create the object in CreateInstance. + friend class AddressDecoder; private: xmlAddressDecoder(); diff --git a/DRAMSys/library/src/controller/core/configuration/Configuration.cpp b/DRAMSys/library/src/controller/core/configuration/Configuration.cpp index 29cc6f94..d7070107 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 = CAddressDecoder::getInstance().amount["channel"]; + unsigned int maxNumberofMemChannels = AddressDecoder::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 = CAddressDecoder::getInstance().amount["bytes"]; + unsigned int burstElementSizeInBytes = 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 18966452..9a40a869 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 = CAddressDecoder::getInstance().amount["bytes"]; + bytesPerColumn = AddressDecoder::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 = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress key = AddressDecoder::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 = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress key = AddressDecoder::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 d3914c6c..f7efed69 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 = CAddressDecoder::getInstance().encodeAddress(first); - sc_dt::uint64 addrSecond = CAddressDecoder::getInstance().encodeAddress(second); + sc_dt::uint64 addrFirst = AddressDecoder::getInstance().encodeAddress(first); + sc_dt::uint64 addrSecond = AddressDecoder::getInstance().encodeAddress(second); return addrFirst < addrSecond; } }; diff --git a/DRAMSys/library/src/simulation/Arbiter.h b/DRAMSys/library/src/simulation/Arbiter.h index 5b60b410..72e8e1c8 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 = CAddressDecoder::getInstance().decodeAddress(trans.get_address()); + DecodedAddress decodedAddress = AddressDecoder::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 = CAddressDecoder::getInstance().decodeAddress(payload.get_address()); + DecodedAddress decodedAddress = AddressDecoder::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 >= CAddressDecoder::getInstance().amount["channel"]) { + if (decodedAddress.channel >= AddressDecoder::getInstance().amount["channel"]) { return false; } - if (decodedAddress.bank >= CAddressDecoder::getInstance().amount["bank"]) { + if (decodedAddress.bank >= AddressDecoder::getInstance().amount["bank"]) { return false; } - if (decodedAddress.bankgroup > CAddressDecoder::getInstance().amount["bankgroup"]) { + if (decodedAddress.bankgroup > AddressDecoder::getInstance().amount["bankgroup"]) { return false; } - if (decodedAddress.column >= CAddressDecoder::getInstance().amount["column"]) { + if (decodedAddress.column >= AddressDecoder::getInstance().amount["column"]) { return false; } - if (decodedAddress.row >= CAddressDecoder::getInstance().amount["row"]) { + if (decodedAddress.row >= AddressDecoder::getInstance().amount["row"]) { return false; } return true; diff --git a/DRAMSys/library/src/simulation/DRAMSys.cpp b/DRAMSys/library/src/simulation/DRAMSys.cpp index 245b4aca..e37ae09f 100644 --- a/DRAMSys/library/src/simulation/DRAMSys.cpp +++ b/DRAMSys/library/src/simulation/DRAMSys.cpp @@ -86,15 +86,15 @@ DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, if(amconfig.find(".xml") != string::npos) { - CAddressDecoder::createInstance(CAddressDecoder::Type::XML); - CAddressDecoder::getInstance().setConfiguration(pathToResources + AddressDecoder::createInstance(AddressDecoder::Type::XML); + AddressDecoder::getInstance().setConfiguration(pathToResources + "configs/amconfigs/" + amconfig); } else if(amconfig.find(".json") != string::npos) { - CAddressDecoder::createInstance(CAddressDecoder::Type::JSON); - CAddressDecoder::getInstance().setConfiguration(pathToResources + AddressDecoder::createInstance(AddressDecoder::Type::JSON); + AddressDecoder::getInstance().setConfiguration(pathToResources + "configs/amconfigs/" + amconfig); } @@ -103,7 +103,7 @@ DRAMSys::DRAMSys(sc_module_name __attribute__((unused)) name, cout << "No address mapping loaded. Unknown file extension" << endl; } - CAddressDecoder::getInstance().print(); + AddressDecoder::getInstance().print(); ConfigurationLoader::loadMemSpec(Configuration::getInstance(), pathToResources