Created base class for XMLAddressDecoder and created an alternative JSONAddressDecoder class.

This class has still no functionality.
This commit is contained in:
Johannes Feldmann
2018-03-26 16:04:17 +02:00
parent 9e10464d44
commit ac950afda9
12 changed files with 269 additions and 67 deletions

View File

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

View File

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

View File

@@ -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 <tlm.h>
#include <iostream>
#include <sstream>
#include <string>
#include <map>
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<std::string, unsigned int> amount;
};
#endif // ADDRESSDECODER_H

View File

@@ -0,0 +1,44 @@
#include "jsonAddressDecoder.h"
#include <fstream>
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()
{
}

View File

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

View File

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

View File

@@ -38,45 +38,20 @@
#ifndef _XMLADDRESSDECODER_H
#define _XMLADDRESSDECODER_H
#include <tlm.h>
#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
#include <map>
#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<std::string, sc_dt::uint64> masks;
std::map<std::string, unsigned int> 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<std::string, unsigned int> amount;

View File

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

View File

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

View File

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

View File

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

View File

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