Code refactoring.
This commit is contained in:
@@ -40,26 +40,24 @@
|
||||
|
||||
#include "../configuration/Configuration.h"
|
||||
|
||||
void DebugManager::printDebugMessage(std::string sender, std::string message)
|
||||
void DebugManager::printDebugMessage(const std::string &sender, const std::string &message)
|
||||
{
|
||||
if (Configuration::getInstance().debug) {
|
||||
if (Configuration::getInstance().debug)
|
||||
{
|
||||
if (writeToConsole)
|
||||
std::cout << " at " << sc_time_stamp() << "\t in " << sender << "\t: " << message <<
|
||||
std::endl;
|
||||
std::cout << " at " << sc_time_stamp() << "\t in " << sender << "\t: " << message << std::endl;
|
||||
|
||||
if (writeToFile && debugFile)
|
||||
debugFile << " at " << sc_time_stamp() << " in " << sender << "\t: " << message
|
||||
<< "\n";
|
||||
debugFile << " at " << sc_time_stamp() << " in " << sender << "\t: " << message << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void DebugManager::printMessage(std::string sender, std::string message)
|
||||
void DebugManager::printMessage(const std::string &sender, const std::string &message)
|
||||
{
|
||||
std::cout << " at " << sc_time_stamp() << "\t in " << sender << "\t: " << message <<
|
||||
std::endl;
|
||||
std::cout << " at " << sc_time_stamp() << "\t in " << sender << "\t: " << message << std::endl;
|
||||
}
|
||||
|
||||
void DebugManager::openDebugFile(std::string filename)
|
||||
void DebugManager::openDebugFile(const std::string &filename)
|
||||
{
|
||||
if (debugFile)
|
||||
debugFile.close();
|
||||
@@ -73,7 +71,8 @@ DebugManager::DebugManager() :
|
||||
|
||||
DebugManager::~DebugManager()
|
||||
{
|
||||
if (writeToFile) {
|
||||
if (writeToFile)
|
||||
{
|
||||
debugFile.flush();
|
||||
debugFile.close();
|
||||
}
|
||||
|
||||
@@ -74,9 +74,9 @@ public:
|
||||
bool writeToConsole;
|
||||
bool writeToFile;
|
||||
|
||||
void printDebugMessage(std::string sender, std::string message);
|
||||
void printMessage(std::string sender, std::string message);
|
||||
void openDebugFile(std::string filename);
|
||||
void printDebugMessage(const std::string &sender, const std::string &message);
|
||||
static void printMessage(const std::string &sender, const std::string &message);
|
||||
void openDebugFile(const std::string &filename);
|
||||
|
||||
private:
|
||||
ofstream debugFile;
|
||||
|
||||
@@ -232,7 +232,7 @@ tlm_extension_base *DramExtension::clone() const
|
||||
|
||||
void DramExtension::copy_from(const tlm_extension_base &ext)
|
||||
{
|
||||
const DramExtension &cpyFrom = static_cast<const DramExtension &>(ext);
|
||||
const auto &cpyFrom = dynamic_cast<const DramExtension &>(ext);
|
||||
thread = cpyFrom.thread;
|
||||
channel = cpyFrom.channel;
|
||||
rank = cpyFrom.rank;
|
||||
@@ -305,12 +305,12 @@ tlm_extension_base *GenerationExtension::clone() const
|
||||
|
||||
void GenerationExtension::copy_from(const tlm_extension_base &ext)
|
||||
{
|
||||
const GenerationExtension &cpyFrom = static_cast<const GenerationExtension &>(ext);
|
||||
const auto &cpyFrom = dynamic_cast<const GenerationExtension &>(ext);
|
||||
timeOfGeneration = cpyFrom.timeOfGeneration;
|
||||
|
||||
}
|
||||
|
||||
void GenerationExtension::setExtension(tlm::tlm_generic_payload *payload, sc_time timeOfGeneration)
|
||||
void GenerationExtension::setExtension(tlm::tlm_generic_payload *payload, const sc_time &timeOfGeneration)
|
||||
{
|
||||
GenerationExtension *extension = nullptr;
|
||||
payload->get_extension(extension);
|
||||
@@ -326,7 +326,7 @@ void GenerationExtension::setExtension(tlm::tlm_generic_payload *payload, sc_tim
|
||||
}
|
||||
}
|
||||
|
||||
void GenerationExtension::setExtension(tlm::tlm_generic_payload &payload, sc_time timeOfGeneration)
|
||||
void GenerationExtension::setExtension(tlm::tlm_generic_payload &payload, const sc_time &timeOfGeneration)
|
||||
{
|
||||
GenerationExtension::setExtension(&payload, timeOfGeneration);
|
||||
}
|
||||
@@ -434,7 +434,7 @@ bool operator !=(const Row &lhs, const Row &rhs)
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
const Row Row::operator ++()
|
||||
Row Row::operator ++()
|
||||
{
|
||||
id = (id + 1) % Configuration::getInstance().memSpec->numberOfRows;
|
||||
return *this;
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
return id;
|
||||
}
|
||||
|
||||
const Row operator++();
|
||||
Row operator++();
|
||||
|
||||
private:
|
||||
unsigned int id;
|
||||
@@ -168,8 +168,8 @@ public:
|
||||
Column column, unsigned int burstLength,
|
||||
uint64_t threadPayloadID, uint64_t channelPayloadID);
|
||||
|
||||
virtual tlm::tlm_extension_base *clone() const;
|
||||
virtual void copy_from(const tlm::tlm_extension_base &ext);
|
||||
tlm::tlm_extension_base *clone() const override;
|
||||
void copy_from(const tlm::tlm_extension_base &ext) override;
|
||||
|
||||
static void setExtension(tlm::tlm_generic_payload *payload,
|
||||
Thread thread, Channel channel, Rank rank,
|
||||
@@ -247,10 +247,10 @@ class GenerationExtension : public tlm::tlm_extension<GenerationExtension>
|
||||
public:
|
||||
GenerationExtension(sc_time timeOfGeneration)
|
||||
: timeOfGeneration(timeOfGeneration) {}
|
||||
virtual tlm::tlm_extension_base *clone() const;
|
||||
virtual void copy_from(const tlm::tlm_extension_base &ext);
|
||||
static void setExtension(tlm::tlm_generic_payload *payload, sc_time timeOfGeneration);
|
||||
static void setExtension(tlm::tlm_generic_payload &payload, sc_time timeOfGeneration);
|
||||
tlm::tlm_extension_base *clone() const override;
|
||||
void copy_from(const tlm::tlm_extension_base &ext) override;
|
||||
static void setExtension(tlm::tlm_generic_payload *payload, const sc_time &timeOfGeneration);
|
||||
static void setExtension(tlm::tlm_generic_payload &payload, const sc_time &timeOfGeneration);
|
||||
static GenerationExtension &getExtension(const tlm::tlm_generic_payload *payload);
|
||||
static GenerationExtension &getExtension(const tlm::tlm_generic_payload &payload);
|
||||
static sc_time getTimeOfGeneration(const tlm::tlm_generic_payload *payload);
|
||||
|
||||
@@ -302,7 +302,7 @@ unsigned int Configuration::adjustNumBytesAfterECC(unsigned nBytes) const
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::loadSimConfig(Configuration &config, std::string simconfigUri)
|
||||
void Configuration::loadSimConfig(Configuration &config, const std::string &simconfigUri)
|
||||
{
|
||||
json doc = parseJSON(simconfigUri);
|
||||
if (doc["simconfig"].empty())
|
||||
@@ -311,7 +311,7 @@ void Configuration::loadSimConfig(Configuration &config, std::string simconfigUr
|
||||
config.setParameter(x.key(), x.value());
|
||||
}
|
||||
|
||||
void Configuration::loadTemperatureSimConfig(Configuration &config, std::string thermalsimconfigUri)
|
||||
void Configuration::loadTemperatureSimConfig(Configuration &config, const std::string &thermalsimconfigUri)
|
||||
{
|
||||
json doc = parseJSON(thermalsimconfigUri);
|
||||
if (doc["thermalsimconfig"].empty())
|
||||
@@ -320,20 +320,20 @@ void Configuration::loadTemperatureSimConfig(Configuration &config, std::string
|
||||
config.setParameter(x.key(), x.value());
|
||||
}
|
||||
|
||||
void Configuration::loadMCConfig(Configuration &config, std::string mcconfigUri)
|
||||
void Configuration::loadMCConfig(Configuration &config, const std::string &_mcconfigUri)
|
||||
{
|
||||
config.mcconfigUri = mcconfigUri;
|
||||
json doc = parseJSON(mcconfigUri);
|
||||
Configuration::mcconfigUri = _mcconfigUri;
|
||||
json doc = parseJSON(_mcconfigUri);
|
||||
if (doc["mcconfig"].empty())
|
||||
SC_REPORT_FATAL("Configuration", "mcconfig is empty.");
|
||||
for (auto& x : doc["mcconfig"].items())
|
||||
config.setParameter(x.key(), x.value());
|
||||
}
|
||||
|
||||
void Configuration::loadMemSpec(Configuration &config, std::string memspecUri)
|
||||
void Configuration::loadMemSpec(Configuration &config, const std::string &_memspecUri)
|
||||
{
|
||||
config.memspecUri = memspecUri;
|
||||
json doc = parseJSON(memspecUri);
|
||||
Configuration::memspecUri = _memspecUri;
|
||||
json doc = parseJSON(_memspecUri);
|
||||
json jMemSpec = doc["memspec"];
|
||||
|
||||
std::string memoryType = jMemSpec["memoryType"];
|
||||
|
||||
@@ -120,10 +120,10 @@ public:
|
||||
unsigned int adjustNumBytesAfterECC(unsigned bytes) const;
|
||||
void setPathToResources(const std::string &path);
|
||||
|
||||
void loadMCConfig(Configuration &config, std::string amconfigUri);
|
||||
void loadSimConfig(Configuration &config, std::string simconfigUri);
|
||||
void loadMemSpec(Configuration &config, std::string memspecUri);
|
||||
void loadTemperatureSimConfig(Configuration &config, std::string simconfigUri);
|
||||
static void loadMCConfig(Configuration &config, const std::string &_mcconfigUri);
|
||||
static void loadSimConfig(Configuration &config, const std::string &simconfigUri);
|
||||
void loadMemSpec(Configuration &config, const std::string &_memspecUri);
|
||||
static void loadTemperatureSimConfig(Configuration &config, const std::string &simconfigUri);
|
||||
};
|
||||
|
||||
#endif // CONFIGURATION_H
|
||||
|
||||
@@ -38,7 +38,7 @@ using namespace tlm;
|
||||
|
||||
CommandTuple::Type RefreshManagerDummy::getNextCommand()
|
||||
{
|
||||
return CommandTuple::Type(Command::NOP, nullptr, sc_max_time());
|
||||
return {Command::NOP, nullptr, sc_max_time()};
|
||||
}
|
||||
|
||||
sc_time RefreshManagerDummy::start()
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
virtual void updateState(Command) = 0;
|
||||
|
||||
protected:
|
||||
static sc_time getTimeForFirstTrigger(sc_time refreshInterval, Rank rank, unsigned numberOfRanks)
|
||||
static sc_time getTimeForFirstTrigger(const sc_time &refreshInterval, Rank rank, unsigned numberOfRanks)
|
||||
{
|
||||
// Calculate bit-reversal rank ID
|
||||
unsigned rankID = rank.ID();
|
||||
|
||||
@@ -132,9 +132,9 @@ tlm_generic_payload *SchedulerFrFcfsGrp::getNextRequest(BankMachine *bankMachine
|
||||
bool SchedulerFrFcfsGrp::hasFurtherRowHit(Bank bank, Row row) const
|
||||
{
|
||||
unsigned rowHitCounter = 0;
|
||||
for (auto it = buffer[bank.ID()].begin(); it != buffer[bank.ID()].end(); it++)
|
||||
for (auto it : buffer[bank.ID()])
|
||||
{
|
||||
if (DramExtension::getRow(*it) == row)
|
||||
if (DramExtension::getRow(it) == row)
|
||||
{
|
||||
rowHitCounter++;
|
||||
if (rowHitCounter == 2)
|
||||
|
||||
@@ -90,17 +90,17 @@ DRAMSys::DRAMSys(const sc_module_name &name,
|
||||
+ "configs/memspecs/"
|
||||
+ std::string(simulationdoc["simulation"]["memspec"]));
|
||||
|
||||
Configuration::getInstance().loadMCConfig(Configuration::getInstance(),
|
||||
Configuration::loadMCConfig(Configuration::getInstance(),
|
||||
pathToResources
|
||||
+ "configs/mcconfigs/"
|
||||
+ std::string(simulationdoc["simulation"]["mcconfig"]));
|
||||
|
||||
Configuration::getInstance().loadSimConfig(Configuration::getInstance(),
|
||||
Configuration::loadSimConfig(Configuration::getInstance(),
|
||||
pathToResources
|
||||
+ "configs/simulator/"
|
||||
+ std::string(simulationdoc["simulation"]["simconfig"]));
|
||||
|
||||
Configuration::getInstance().loadTemperatureSimConfig(Configuration::getInstance(),
|
||||
Configuration::loadTemperatureSimConfig(Configuration::getInstance(),
|
||||
pathToResources
|
||||
+ "configs/thermalsim/"
|
||||
+ std::string(simulationdoc["simulation"]["thermalconfig"]));
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#ifndef EXAMPLEINITIATOR_H
|
||||
#define EXAMPLEINITIATOR_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include "MemoryManager.h"
|
||||
@@ -50,7 +50,7 @@ struct ExampleInitiator : sc_module
|
||||
|
||||
SC_CTOR(ExampleInitiator)
|
||||
: socket("socket"),
|
||||
request_in_progress(0),
|
||||
request_in_progress(nullptr),
|
||||
m_peq(this, &ExampleInitiator::peq_cb)
|
||||
{
|
||||
socket.register_nb_transport_bw(this, &ExampleInitiator::nb_transport_bw);
|
||||
@@ -67,8 +67,8 @@ struct ExampleInitiator : sc_module
|
||||
init_mem();
|
||||
dump_mem();
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
data[i] = 0x55;
|
||||
for (unsigned char &i : data)
|
||||
i = 0x55;
|
||||
|
||||
// Generate 2 write transactions
|
||||
for (int i = 0; i < 2; i++) {
|
||||
@@ -80,14 +80,14 @@ struct ExampleInitiator : sc_module
|
||||
trans = m_mm.allocate();
|
||||
trans->acquire();
|
||||
|
||||
trans->set_command( cmd );
|
||||
trans->set_address( adr );
|
||||
trans->set_data_ptr( reinterpret_cast<unsigned char *>(&data[0]) );
|
||||
trans->set_data_length( 64 );
|
||||
trans->set_streaming_width( 4 );
|
||||
trans->set_byte_enable_ptr( 0 );
|
||||
trans->set_dmi_allowed( false );
|
||||
trans->set_response_status( tlm::TLM_INCOMPLETE_RESPONSE );
|
||||
trans->set_command(cmd);
|
||||
trans->set_address(adr);
|
||||
trans->set_data_ptr(reinterpret_cast<unsigned char *>(&data[0]));
|
||||
trans->set_data_length(64);
|
||||
trans->set_streaming_width(4);
|
||||
trans->set_byte_enable_ptr(nullptr);
|
||||
trans->set_dmi_allowed(false);
|
||||
trans->set_response_status(tlm::TLM_INCOMPLETE_RESPONSE);
|
||||
|
||||
// ExampleInitiator must honor BEGIN_REQ/END_REQ exclusion rule
|
||||
if (request_in_progress)
|
||||
@@ -116,7 +116,7 @@ struct ExampleInitiator : sc_module
|
||||
m_peq.notify( *trans, phase, delay );
|
||||
} else if (status == tlm::TLM_COMPLETED) {
|
||||
// The completion of the transaction necessarily ends the BEGIN_REQ phase
|
||||
request_in_progress = 0;
|
||||
request_in_progress = nullptr;
|
||||
|
||||
// The target has terminated the transaction
|
||||
check_transaction( *trans );
|
||||
@@ -134,12 +134,11 @@ struct ExampleInitiator : sc_module
|
||||
sc_stop();
|
||||
}
|
||||
|
||||
void init_mem()
|
||||
static void init_mem()
|
||||
{
|
||||
unsigned char buffer[64];
|
||||
for (int i = 0; i < 64; i++) {
|
||||
buffer[i] = 0xff;
|
||||
}
|
||||
for (unsigned char &i : buffer)
|
||||
i = 0xff;
|
||||
|
||||
for (int addr = 0; addr < 128; addr += 64) {
|
||||
tlm::tlm_generic_payload trans;
|
||||
@@ -152,7 +151,7 @@ struct ExampleInitiator : sc_module
|
||||
}
|
||||
}
|
||||
|
||||
void dump_mem()
|
||||
static void dump_mem()
|
||||
{
|
||||
for (int addr = 0; addr < 128; addr += 64) {
|
||||
unsigned char buffer[64];
|
||||
@@ -187,7 +186,7 @@ struct ExampleInitiator : sc_module
|
||||
if (phase == tlm::END_REQ || (&trans == request_in_progress
|
||||
&& phase == tlm::BEGIN_RESP)) {
|
||||
// The end of the BEGIN_REQ phase
|
||||
request_in_progress = 0;
|
||||
request_in_progress = nullptr;
|
||||
end_request_event.notify();
|
||||
} else if (phase == tlm::BEGIN_REQ || phase == tlm::END_RESP)
|
||||
SC_REPORT_FATAL("TLM-2", "Illegal transaction phase received by initiator");
|
||||
|
||||
@@ -44,9 +44,9 @@ class MemoryManager : public tlm::tlm_mm_interface
|
||||
{
|
||||
public:
|
||||
MemoryManager();
|
||||
virtual ~MemoryManager();
|
||||
virtual tlm::tlm_generic_payload *allocate();
|
||||
virtual void free(tlm::tlm_generic_payload *payload);
|
||||
~MemoryManager() override;
|
||||
tlm::tlm_generic_payload *allocate();
|
||||
void free(tlm::tlm_generic_payload *payload) override;
|
||||
|
||||
private:
|
||||
uint64_t numberOfAllocations;
|
||||
|
||||
@@ -174,7 +174,7 @@ void StlPlayer::parseTraceFile()
|
||||
SC_REPORT_FATAL("StlPlayer",
|
||||
("Malformed trace file. Timestamp could not be found (line " + std::to_string(
|
||||
lineCnt) + ").").c_str());
|
||||
content.sendingTime = std::stoull(time) * playerClk;
|
||||
content.sendingTime = playerClk * static_cast<double>(std::stoull(time));
|
||||
|
||||
// Get the command.
|
||||
iss >> command;
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
using json = nlohmann::json;
|
||||
#endif
|
||||
|
||||
std::string pathOfFile(std::string file)
|
||||
std::string pathOfFile(const std::string &file)
|
||||
{
|
||||
return file.substr(0, file.find_last_of('/'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user