Changed data structures of Address Decoder for speedup.

This commit is contained in:
Lukas Steiner
2019-09-18 16:39:38 +02:00
parent 6eef8ff1e6
commit 330b07d0e7
16 changed files with 152 additions and 101 deletions

View File

@@ -60,8 +60,3 @@ void AddressDecoder::createInstance(Type t)
break;
}
}
AddressDecoder::AddressDecoder()
{
}

View File

@@ -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<std::string, unsigned int> 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

View File

@@ -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

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -51,16 +51,36 @@ class XmlAddressDecoder : private AddressDecoder
friend class AddressDecoder;
private:
std::map<std::string, sc_dt::uint64> masks;
std::map<std::string, unsigned int> 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);

View File

@@ -92,7 +92,7 @@ bool isIn(const T &value, const std::vector<T> &collection)
}
constexpr const char headline[] =
"=========================================================";
"==========================================================================";
static inline void loadbar(unsigned int x,
unsigned int n,

View File

@@ -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)
{

View File

@@ -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));
}

View File

@@ -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(

View File

@@ -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;
}
};

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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();

View File

@@ -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<int *>( trans.get_data_ptr() );
cout << hex << adr << " check, cmd=" << (cmd ? "write" : "read")

View File

@@ -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;