Refactor Configuration and add warnings when invalid values are provided

This commit is contained in:
2023-04-13 11:10:03 +02:00
parent 8f6e55f9fa
commit b343ea821f
2 changed files with 164 additions and 134 deletions

View File

@@ -2,7 +2,7 @@
"simconfig": {
"AddressOffset": 0,
"CheckTLM2Protocol": false,
"DatabaseRecording": true,
"DatabaseRecording": false,
"Debug": false,
"EnableWindowing": false,
"PowerAnalysis": false,

View File

@@ -87,164 +87,194 @@ enum sc_time_unit string2TimeUnit(const std::string &s)
void Configuration::loadSimConfig(const DRAMSys::Config::SimConfig &simConfig)
{
if (const auto& _addressOffset = simConfig.AddressOffset)
addressOffset = *_addressOffset;
addressOffset = simConfig.AddressOffset.value_or(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)
checkTLM2Protocol = *_checkTLM2Protocol;
if (const auto& _databaseRecording = simConfig.DatabaseRecording)
databaseRecording = *_databaseRecording;
if (const auto& _debug = simConfig.Debug)
debug = *_debug;
if (const auto& _enableWindowing = simConfig.EnableWindowing)
enableWindowing = *_enableWindowing;
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;
if (const auto &_storeMode = simConfig.StoreMode)
storeMode = [=]
{
switch (*_storeMode)
{
case DRAMSys::Config::StoreModeType::NoStorage:
return StoreMode::NoStorage;
case DRAMSys::Config::StoreModeType::Store:
return StoreMode::Store;
default:
SC_REPORT_FATAL("Configuration", "Invalid StoreMode");
return StoreMode::NoStorage; // Silence Warning
}
}();
windowSize = simConfig.WindowSize.value_or(windowSize);
if (windowSize == 0)
SC_REPORT_FATAL("Configuration", "Minimum window size is 1");
if (const auto& _storeMode = simConfig.StoreMode)
storeMode = [=] {
if (_storeMode == DRAMSys::Config::StoreModeType::NoStorage)
return StoreMode::NoStorage;
else // (_storeMode == DRAMSys::Config::StoreMode::Store)
return StoreMode::Store;
}();
powerAnalysis = simConfig.PowerAnalysis.value_or(powerAnalysis);
#ifndef DRAMPOWER
if (powerAnalysis)
SC_REPORT_FATAL("Configuration", "Power analysis is only supported with included DRAMPower library!");
#endif
}
void Configuration::loadMCConfig(const DRAMSys::Config::McConfig &mcConfig)
{
if (const auto& _pagePolicy = mcConfig.PagePolicy)
pagePolicy = [=] {
if (_pagePolicy == DRAMSys::Config::PagePolicyType::Open)
if (const auto &_pagePolicy = mcConfig.PagePolicy)
pagePolicy = [=]
{
switch (*_pagePolicy)
{
case DRAMSys::Config::PagePolicyType::Open:
return PagePolicy::Open;
else if (_pagePolicy == DRAMSys::Config::PagePolicyType::OpenAdaptive)
case DRAMSys::Config::PagePolicyType::OpenAdaptive:
return PagePolicy::OpenAdaptive;
else if (_pagePolicy == DRAMSys::Config::PagePolicyType::Closed)
case DRAMSys::Config::PagePolicyType::Closed:
return PagePolicy::Closed;
else
case DRAMSys::Config::PagePolicyType::ClosedAdaptive:
return PagePolicy::ClosedAdaptive;
default:
SC_REPORT_FATAL("Configuration", "Invalid PagePolicy");
return PagePolicy::Open; // Silence Warning
}
}();
if (const auto& _scheduler = mcConfig.Scheduler)
scheduler = [=] {
if (_scheduler == DRAMSys::Config::SchedulerType::Fifo)
return Scheduler::Fifo;
else if (_scheduler == DRAMSys::Config::SchedulerType::FrFcfs)
return Scheduler::FrFcfs;
else if (_scheduler == DRAMSys::Config::SchedulerType::FrFcfsGrp)
return Scheduler::FrFcfsGrp;
else if (_scheduler == DRAMSys::Config::SchedulerType::GrpFrFcfs)
return Scheduler::GrpFrFcfs;
else
return Scheduler::GrpFrFcfsWm;
if (const auto &_scheduler = mcConfig.Scheduler)
scheduler = [=]
{
switch (*_scheduler)
{
case DRAMSys::Config::SchedulerType::Fifo:
return Scheduler::Fifo;
case DRAMSys::Config::SchedulerType::FrFcfs:
return Scheduler::FrFcfs;
case DRAMSys::Config::SchedulerType::FrFcfsGrp:
return Scheduler::FrFcfsGrp;
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)
highWatermark = *mcConfig.HighWatermark;
if (const auto& _lowWatermark = mcConfig.LowWatermark)
lowWatermark = *mcConfig.LowWatermark;
if (const auto& _schedulerBuffer = mcConfig.SchedulerBuffer)
schedulerBuffer = [=] {
if (_schedulerBuffer == DRAMSys::Config::SchedulerBufferType::Bankwise)
if (const auto &_schedulerBuffer = mcConfig.SchedulerBuffer)
schedulerBuffer = [=]
{
switch (*_schedulerBuffer)
{
case DRAMSys::Config::SchedulerBufferType::Bankwise:
return SchedulerBuffer::Bankwise;
else if (_schedulerBuffer == DRAMSys::Config::SchedulerBufferType::ReadWrite)
case DRAMSys::Config::SchedulerBufferType::ReadWrite:
return SchedulerBuffer::ReadWrite;
else
case DRAMSys::Config::SchedulerBufferType::Shared:
return SchedulerBuffer::Shared;
default:
SC_REPORT_FATAL("Configuration", "Invalid SchedulerBuffer");
return SchedulerBuffer::Bankwise; // Silence Warning
}
}();
if (const auto& _requestBufferSize = mcConfig.RequestBufferSize)
requestBufferSize = *mcConfig.RequestBufferSize;
if (const auto &_cmdMux = mcConfig.CmdMux)
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)
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)
{
arbitrationDelayFw = std::round(sc_time(*_arbitrationDelayFw, SC_NS) / memSpec->tCK) * memSpec->tCK;