Refactor Configuration and add warnings when invalid values are provided
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"simconfig": {
|
"simconfig": {
|
||||||
"AddressOffset": 0,
|
"AddressOffset": 0,
|
||||||
"CheckTLM2Protocol": false,
|
"CheckTLM2Protocol": false,
|
||||||
"DatabaseRecording": true,
|
"DatabaseRecording": false,
|
||||||
"Debug": false,
|
"Debug": false,
|
||||||
"EnableWindowing": false,
|
"EnableWindowing": false,
|
||||||
"PowerAnalysis": false,
|
"PowerAnalysis": false,
|
||||||
|
|||||||
@@ -86,165 +86,195 @@ enum sc_time_unit string2TimeUnit(const std::string &s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::loadSimConfig(const DRAMSys::Config::SimConfig &simConfig)
|
void Configuration::loadSimConfig(const DRAMSys::Config::SimConfig &simConfig)
|
||||||
{
|
{
|
||||||
if (const auto& _addressOffset = simConfig.AddressOffset)
|
addressOffset = simConfig.AddressOffset.value_or(addressOffset);
|
||||||
addressOffset = *_addressOffset;
|
checkTLM2Protocol = simConfig.CheckTLM2Protocol.value_or(checkTLM2Protocol);
|
||||||
|
databaseRecording = simConfig.DatabaseRecording.value_or(databaseRecording);
|
||||||
|
debug = simConfig.Debug.value_or(debug);
|
||||||
|
enableWindowing = simConfig.EnableWindowing.value_or(enableWindowing);
|
||||||
|
simulationName = simConfig.SimulationName.value_or(simulationName);
|
||||||
|
simulationProgressBar = simConfig.SimulationProgressBar.value_or(simulationProgressBar);
|
||||||
|
useMalloc = simConfig.UseMalloc.value_or(useMalloc);
|
||||||
|
|
||||||
if (const auto& _checkTLM2Protocol = simConfig.CheckTLM2Protocol)
|
if (const auto &_storeMode = simConfig.StoreMode)
|
||||||
checkTLM2Protocol = *_checkTLM2Protocol;
|
storeMode = [=]
|
||||||
|
{
|
||||||
if (const auto& _databaseRecording = simConfig.DatabaseRecording)
|
switch (*_storeMode)
|
||||||
databaseRecording = *_databaseRecording;
|
{
|
||||||
|
case DRAMSys::Config::StoreModeType::NoStorage:
|
||||||
if (const auto& _debug = simConfig.Debug)
|
return StoreMode::NoStorage;
|
||||||
debug = *_debug;
|
case DRAMSys::Config::StoreModeType::Store:
|
||||||
|
return StoreMode::Store;
|
||||||
if (const auto& _enableWindowing = simConfig.EnableWindowing)
|
default:
|
||||||
enableWindowing = *_enableWindowing;
|
SC_REPORT_FATAL("Configuration", "Invalid StoreMode");
|
||||||
|
return StoreMode::NoStorage; // Silence Warning
|
||||||
if (const auto& _powerAnalysis = simConfig.PowerAnalysis)
|
}
|
||||||
{
|
}();
|
||||||
powerAnalysis = *_powerAnalysis;
|
|
||||||
#ifndef DRAMPOWER
|
|
||||||
if (powerAnalysis)
|
|
||||||
SC_REPORT_FATAL("Configuration", "Power analysis is only supported with included DRAMPower library!");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const auto& _simulationName = simConfig.SimulationName)
|
|
||||||
simulationName = *_simulationName;
|
|
||||||
|
|
||||||
if (const auto& _simulationProgressBar = simConfig.SimulationProgressBar)
|
|
||||||
simulationProgressBar = *_simulationProgressBar;
|
|
||||||
|
|
||||||
if (const auto& _useMalloc = simConfig.UseMalloc)
|
|
||||||
useMalloc = *_useMalloc;
|
|
||||||
|
|
||||||
if (const auto& _windowSize = simConfig.WindowSize)
|
|
||||||
windowSize = *_windowSize;
|
|
||||||
|
|
||||||
|
windowSize = simConfig.WindowSize.value_or(windowSize);
|
||||||
if (windowSize == 0)
|
if (windowSize == 0)
|
||||||
SC_REPORT_FATAL("Configuration", "Minimum window size is 1");
|
SC_REPORT_FATAL("Configuration", "Minimum window size is 1");
|
||||||
|
|
||||||
if (const auto& _storeMode = simConfig.StoreMode)
|
powerAnalysis = simConfig.PowerAnalysis.value_or(powerAnalysis);
|
||||||
storeMode = [=] {
|
#ifndef DRAMPOWER
|
||||||
if (_storeMode == DRAMSys::Config::StoreModeType::NoStorage)
|
if (powerAnalysis)
|
||||||
return StoreMode::NoStorage;
|
SC_REPORT_FATAL("Configuration", "Power analysis is only supported with included DRAMPower library!");
|
||||||
else // (_storeMode == DRAMSys::Config::StoreMode::Store)
|
#endif
|
||||||
return StoreMode::Store;
|
|
||||||
}();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Configuration::loadMCConfig(const DRAMSys::Config::McConfig &mcConfig)
|
void Configuration::loadMCConfig(const DRAMSys::Config::McConfig &mcConfig)
|
||||||
{
|
{
|
||||||
if (const auto& _pagePolicy = mcConfig.PagePolicy)
|
if (const auto &_pagePolicy = mcConfig.PagePolicy)
|
||||||
pagePolicy = [=] {
|
pagePolicy = [=]
|
||||||
if (_pagePolicy == DRAMSys::Config::PagePolicyType::Open)
|
{
|
||||||
|
switch (*_pagePolicy)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::PagePolicyType::Open:
|
||||||
return PagePolicy::Open;
|
return PagePolicy::Open;
|
||||||
else if (_pagePolicy == DRAMSys::Config::PagePolicyType::OpenAdaptive)
|
case DRAMSys::Config::PagePolicyType::OpenAdaptive:
|
||||||
return PagePolicy::OpenAdaptive;
|
return PagePolicy::OpenAdaptive;
|
||||||
else if (_pagePolicy == DRAMSys::Config::PagePolicyType::Closed)
|
case DRAMSys::Config::PagePolicyType::Closed:
|
||||||
return PagePolicy::Closed;
|
return PagePolicy::Closed;
|
||||||
else
|
case DRAMSys::Config::PagePolicyType::ClosedAdaptive:
|
||||||
return PagePolicy::ClosedAdaptive;
|
return PagePolicy::ClosedAdaptive;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid PagePolicy");
|
||||||
|
return PagePolicy::Open; // Silence Warning
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (const auto& _scheduler = mcConfig.Scheduler)
|
if (const auto &_scheduler = mcConfig.Scheduler)
|
||||||
scheduler = [=] {
|
scheduler = [=]
|
||||||
if (_scheduler == DRAMSys::Config::SchedulerType::Fifo)
|
{
|
||||||
return Scheduler::Fifo;
|
switch (*_scheduler)
|
||||||
else if (_scheduler == DRAMSys::Config::SchedulerType::FrFcfs)
|
{
|
||||||
return Scheduler::FrFcfs;
|
case DRAMSys::Config::SchedulerType::Fifo:
|
||||||
else if (_scheduler == DRAMSys::Config::SchedulerType::FrFcfsGrp)
|
return Scheduler::Fifo;
|
||||||
return Scheduler::FrFcfsGrp;
|
case DRAMSys::Config::SchedulerType::FrFcfs:
|
||||||
else if (_scheduler == DRAMSys::Config::SchedulerType::GrpFrFcfs)
|
return Scheduler::FrFcfs;
|
||||||
return Scheduler::GrpFrFcfs;
|
case DRAMSys::Config::SchedulerType::FrFcfsGrp:
|
||||||
else
|
return Scheduler::FrFcfsGrp;
|
||||||
return Scheduler::GrpFrFcfsWm;
|
case DRAMSys::Config::SchedulerType::GrpFrFcfs:
|
||||||
|
return Scheduler::GrpFrFcfs;
|
||||||
|
case DRAMSys::Config::SchedulerType::GrpFrFcfsWm:
|
||||||
|
return Scheduler::GrpFrFcfsWm;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid Scheduler");
|
||||||
|
return Scheduler::Fifo; // Silence Warning
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (const auto& _highWatermark = mcConfig.HighWatermark)
|
if (const auto &_schedulerBuffer = mcConfig.SchedulerBuffer)
|
||||||
highWatermark = *mcConfig.HighWatermark;
|
schedulerBuffer = [=]
|
||||||
|
{
|
||||||
if (const auto& _lowWatermark = mcConfig.LowWatermark)
|
switch (*_schedulerBuffer)
|
||||||
lowWatermark = *mcConfig.LowWatermark;
|
{
|
||||||
|
case DRAMSys::Config::SchedulerBufferType::Bankwise:
|
||||||
if (const auto& _schedulerBuffer = mcConfig.SchedulerBuffer)
|
|
||||||
schedulerBuffer = [=] {
|
|
||||||
if (_schedulerBuffer == DRAMSys::Config::SchedulerBufferType::Bankwise)
|
|
||||||
return SchedulerBuffer::Bankwise;
|
return SchedulerBuffer::Bankwise;
|
||||||
else if (_schedulerBuffer == DRAMSys::Config::SchedulerBufferType::ReadWrite)
|
case DRAMSys::Config::SchedulerBufferType::ReadWrite:
|
||||||
return SchedulerBuffer::ReadWrite;
|
return SchedulerBuffer::ReadWrite;
|
||||||
else
|
case DRAMSys::Config::SchedulerBufferType::Shared:
|
||||||
return SchedulerBuffer::Shared;
|
return SchedulerBuffer::Shared;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid SchedulerBuffer");
|
||||||
|
return SchedulerBuffer::Bankwise; // Silence Warning
|
||||||
|
}
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if (const auto& _requestBufferSize = mcConfig.RequestBufferSize)
|
if (const auto &_cmdMux = mcConfig.CmdMux)
|
||||||
requestBufferSize = *mcConfig.RequestBufferSize;
|
cmdMux = [=]
|
||||||
|
{
|
||||||
|
switch (*_cmdMux)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::CmdMuxType::Oldest:
|
||||||
|
return CmdMux::Oldest;
|
||||||
|
case DRAMSys::Config::CmdMuxType::Strict:
|
||||||
|
return CmdMux::Strict;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid CmdMux");
|
||||||
|
return CmdMux::Oldest; // Silence Warning
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (const auto &_respQueue = mcConfig.RespQueue)
|
||||||
|
respQueue = [=]
|
||||||
|
{
|
||||||
|
switch (*_respQueue)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::RespQueueType::Fifo:
|
||||||
|
return RespQueue::Fifo;
|
||||||
|
case DRAMSys::Config::RespQueueType::Reorder:
|
||||||
|
return RespQueue::Reorder;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid RespQueue");
|
||||||
|
return RespQueue::Fifo; // Silence Warning
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (const auto &_refreshPolicy = mcConfig.RefreshPolicy)
|
||||||
|
refreshPolicy = [=]
|
||||||
|
{
|
||||||
|
switch (*_refreshPolicy)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::RefreshPolicyType::NoRefresh:
|
||||||
|
return RefreshPolicy::NoRefresh;
|
||||||
|
case DRAMSys::Config::RefreshPolicyType::AllBank:
|
||||||
|
return RefreshPolicy::AllBank;
|
||||||
|
case DRAMSys::Config::RefreshPolicyType::PerBank:
|
||||||
|
return RefreshPolicy::PerBank;
|
||||||
|
case DRAMSys::Config::RefreshPolicyType::Per2Bank:
|
||||||
|
return RefreshPolicy::Per2Bank;
|
||||||
|
case DRAMSys::Config::RefreshPolicyType::SameBank:
|
||||||
|
return RefreshPolicy::SameBank;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid RefreshPolicy");
|
||||||
|
return RefreshPolicy::NoRefresh; // Silence Warning
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (const auto &_powerDownPolicy = mcConfig.PowerDownPolicy)
|
||||||
|
powerDownPolicy = [=]
|
||||||
|
{
|
||||||
|
switch (*_powerDownPolicy)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::PowerDownPolicyType::NoPowerDown:
|
||||||
|
return PowerDownPolicy::NoPowerDown;
|
||||||
|
case DRAMSys::Config::PowerDownPolicyType::Staggered:
|
||||||
|
return PowerDownPolicy::Staggered;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid PowerDownPolicy");
|
||||||
|
return PowerDownPolicy::NoPowerDown; // Silence Warning
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (const auto &_arbiter = mcConfig.Arbiter)
|
||||||
|
arbiter = [=]
|
||||||
|
{
|
||||||
|
switch (*_arbiter)
|
||||||
|
{
|
||||||
|
case DRAMSys::Config::ArbiterType::Simple:
|
||||||
|
return Arbiter::Simple;
|
||||||
|
case DRAMSys::Config::ArbiterType::Fifo:
|
||||||
|
return Arbiter::Fifo;
|
||||||
|
case DRAMSys::Config::ArbiterType::Reorder:
|
||||||
|
return Arbiter::Reorder;
|
||||||
|
default:
|
||||||
|
SC_REPORT_FATAL("Configuration", "Invalid Arbiter");
|
||||||
|
return Arbiter::Simple; // Silence Warning
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
refreshMaxPostponed = mcConfig.RefreshMaxPostponed.value_or(refreshMaxPostponed);
|
||||||
|
refreshMaxPulledin = mcConfig.RefreshMaxPulledin.value_or(refreshMaxPulledin);
|
||||||
|
highWatermark = mcConfig.HighWatermark.value_or(highWatermark);
|
||||||
|
lowWatermark = mcConfig.LowWatermark.value_or(lowWatermark);
|
||||||
|
maxActiveTransactions = mcConfig.MaxActiveTransactions.value_or(maxActiveTransactions);
|
||||||
|
refreshManagement = mcConfig.RefreshManagement.value_or(refreshManagement);
|
||||||
|
|
||||||
|
requestBufferSize = mcConfig.RequestBufferSize.value_or(requestBufferSize);
|
||||||
if (requestBufferSize == 0)
|
if (requestBufferSize == 0)
|
||||||
SC_REPORT_FATAL("Configuration", "Minimum request buffer size is 1!");
|
SC_REPORT_FATAL("Configuration", "Minimum request buffer size is 1!");
|
||||||
|
|
||||||
if (const auto& _cmdMux = mcConfig.CmdMux)
|
|
||||||
cmdMux = [=] {
|
|
||||||
if (_cmdMux == DRAMSys::Config::CmdMuxType::Oldest)
|
|
||||||
return CmdMux::Oldest;
|
|
||||||
else
|
|
||||||
return CmdMux::Strict;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (const auto& _respQueue = mcConfig.RespQueue)
|
|
||||||
respQueue = [=] {
|
|
||||||
if (_respQueue == DRAMSys::Config::RespQueueType::Fifo)
|
|
||||||
return RespQueue::Fifo;
|
|
||||||
else
|
|
||||||
return RespQueue::Reorder;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (const auto& _refreshPolicy = mcConfig.RefreshPolicy)
|
|
||||||
refreshPolicy = [=] {
|
|
||||||
if (_refreshPolicy == DRAMSys::Config::RefreshPolicyType::NoRefresh)
|
|
||||||
return RefreshPolicy::NoRefresh;
|
|
||||||
else if (_refreshPolicy == DRAMSys::Config::RefreshPolicyType::AllBank)
|
|
||||||
return RefreshPolicy::AllBank;
|
|
||||||
else if (_refreshPolicy == DRAMSys::Config::RefreshPolicyType::PerBank)
|
|
||||||
return RefreshPolicy::PerBank;
|
|
||||||
else if (_refreshPolicy == DRAMSys::Config::RefreshPolicyType::Per2Bank)
|
|
||||||
return RefreshPolicy::Per2Bank;
|
|
||||||
else // if (policy == DRAMSys::Config::RefreshPolicy::SameBank)
|
|
||||||
return RefreshPolicy::SameBank;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (const auto& _refreshMaxPostponed = mcConfig.RefreshMaxPostponed)
|
|
||||||
refreshMaxPostponed = *_refreshMaxPostponed;
|
|
||||||
|
|
||||||
if (const auto& _refreshMaxPulledin = mcConfig.RefreshMaxPulledin)
|
|
||||||
refreshMaxPulledin = *_refreshMaxPulledin;
|
|
||||||
|
|
||||||
if (const auto& _powerDownPolicy = mcConfig.PowerDownPolicy)
|
|
||||||
powerDownPolicy = [=] {
|
|
||||||
if (_powerDownPolicy == DRAMSys::Config::PowerDownPolicyType::NoPowerDown)
|
|
||||||
return PowerDownPolicy::NoPowerDown;
|
|
||||||
else
|
|
||||||
return PowerDownPolicy::Staggered;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (const auto& _arbiter = mcConfig.Arbiter)
|
|
||||||
arbiter = [=] {
|
|
||||||
if (_arbiter == DRAMSys::Config::ArbiterType::Simple)
|
|
||||||
return Arbiter::Simple;
|
|
||||||
else if (_arbiter == DRAMSys::Config::ArbiterType::Fifo)
|
|
||||||
return Arbiter::Fifo;
|
|
||||||
else
|
|
||||||
return Arbiter::Reorder;
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (const auto& _maxActiveTransactions = mcConfig.MaxActiveTransactions)
|
|
||||||
maxActiveTransactions = *_maxActiveTransactions;
|
|
||||||
|
|
||||||
if (const auto& _refreshManagement = mcConfig.RefreshManagement)
|
|
||||||
refreshManagement = *_refreshManagement;
|
|
||||||
|
|
||||||
if (const auto& _arbitrationDelayFw = mcConfig.ArbitrationDelayFw)
|
if (const auto& _arbitrationDelayFw = mcConfig.ArbitrationDelayFw)
|
||||||
{
|
{
|
||||||
arbitrationDelayFw = std::round(sc_time(*_arbitrationDelayFw, SC_NS) / memSpec->tCK) * memSpec->tCK;
|
arbitrationDelayFw = std::round(sc_time(*_arbitrationDelayFw, SC_NS) / memSpec->tCK) * memSpec->tCK;
|
||||||
|
|||||||
Reference in New Issue
Block a user