From ae85f6cd832160e804bb556714222b80173252e8 Mon Sep 17 00:00:00 2001 From: Lukas Steiner Date: Wed, 21 Apr 2021 09:38:22 +0200 Subject: [PATCH] New oldest cmd mux working. --- .../library/src/controller/cmdmux/CmdMuxIF.h | 2 +- .../src/controller/cmdmux/CmdMuxOldest.cpp | 69 ++++++++++--------- .../src/controller/cmdmux/CmdMuxOldest.h | 5 +- .../src/controller/cmdmux/CmdMuxStrict.cpp | 69 ++++++++++--------- .../src/controller/cmdmux/CmdMuxStrict.h | 5 +- 5 files changed, 79 insertions(+), 71 deletions(-) diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h index 49e0318c..7134f3cb 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxIF.h @@ -45,7 +45,7 @@ class CmdMuxIF { public: virtual ~CmdMuxIF() {} - virtual CommandTuple::Type selectCommand(ReadyCommands &) = 0; + virtual CommandTuple::Type selectCommand(const ReadyCommands &) = 0; }; #endif // CMDMUXIF_H diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp index 9bbc825b..657d1abe 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.cpp @@ -40,7 +40,7 @@ using namespace tlm; CmdMuxOldest::CmdMuxOldest() : memSpec(Configuration::getInstance().memSpec) {} -CommandTuple::Type CmdMuxOldest::selectCommand(ReadyCommands &readyCommands) +CommandTuple::Type CmdMuxOldest::selectCommand(const ReadyCommands &readyCommands) { auto result = readyCommands.cend(); uint64_t lastPayloadID = UINT64_MAX; @@ -51,7 +51,7 @@ CommandTuple::Type CmdMuxOldest::selectCommand(ReadyCommands &readyCommands) for (auto it = readyCommands.cbegin(); it != readyCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newTimestamp < lastTimestamp) @@ -84,7 +84,7 @@ CmdMuxOldestRasCas::CmdMuxOldestRasCas() : memSpec(Configuration::getInstance(). readyCasCommands.reserve(memSpec->numberOfBanks); } -CommandTuple::Type CmdMuxOldestRasCas::selectCommand(ReadyCommands &readyCommands) +CommandTuple::Type CmdMuxOldestRasCas::selectCommand(const ReadyCommands &readyCommands) { readyRasCommands.clear(); readyCasCommands.clear(); @@ -97,6 +97,7 @@ CommandTuple::Type CmdMuxOldestRasCas::selectCommand(ReadyCommands &readyCommand readyCasCommands.emplace_back(it); } + auto result = readyCommands.cend(); auto resultRas = readyRasCommands.cend(); auto resultCas = readyCasCommands.cend(); @@ -108,7 +109,7 @@ CommandTuple::Type CmdMuxOldestRasCas::selectCommand(ReadyCommands &readyCommand for (auto it = readyRasCommands.cbegin(); it != readyRasCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newTimestamp < lastTimestamp) @@ -133,7 +134,7 @@ CommandTuple::Type CmdMuxOldestRasCas::selectCommand(ReadyCommands &readyCommand for (auto it = readyCasCommands.cbegin(); it != readyCasCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newTimestamp < lastTimestamp) @@ -152,38 +153,40 @@ CommandTuple::Type CmdMuxOldestRasCas::selectCommand(ReadyCommands &readyCommand } } - if (resultRas != readyRasCommands.cend() && resultCas != readyCasCommands.cend()) + readyRasCasCommands.clear(); + + if (resultRas != readyRasCommands.cend()) + readyRasCasCommands.emplace_back(*resultRas); + if (resultCas != readyCasCommands.cend()) + readyRasCasCommands.emplace_back(*resultCas); + + lastPayloadID = UINT64_MAX; + lastTimestamp = sc_max_time(); + + for (auto it = readyRasCasCommands.cbegin(); it != readyRasCasCommands.cend(); it++) { - if (std::get(*resultRas) == sc_time_stamp() - && std::get(*resultCas) == sc_time_stamp()) + newTimestamp = std::get(*it); + newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); + + if (newTimestamp < lastTimestamp) { - if (DramExtension::getChannelPayloadID(std::get(*resultRas)) - <= DramExtension::getChannelPayloadID(std::get(*resultCas))) - return *resultRas; - else - return *resultCas; + lastTimestamp = newTimestamp; + lastPayloadID = newPayloadID; + result = it; + } + else if (newTimestamp == lastTimestamp) + { + if (newPayloadID < lastPayloadID) + { + lastPayloadID = newPayloadID; + result = it; + } } - else if (std::get(*resultRas) == sc_time_stamp()) - return *resultRas; - else if (std::get(*resultCas) == sc_time_stamp()) - return *resultCas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); - } - else if (resultRas != readyRasCommands.cend()) - { - if (std::get(*resultRas) == sc_time_stamp()) - return *resultRas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); - } - else if (resultCas != readyCasCommands.cend()) - { - if (std::get(*resultCas) == sc_time_stamp()) - return *resultCas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); } + + if (result != readyCommands.cend() && + std::get(*result) == sc_time_stamp()) + return *result; else return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); } diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h index 06e07c44..5f8ce661 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxOldest.h @@ -42,7 +42,7 @@ class CmdMuxOldest : public CmdMuxIF { public: CmdMuxOldest(); - CommandTuple::Type selectCommand(ReadyCommands &); + virtual CommandTuple::Type selectCommand(const ReadyCommands &) override; private: const MemSpec *memSpec; @@ -53,12 +53,13 @@ class CmdMuxOldestRasCas : public CmdMuxIF { public: CmdMuxOldestRasCas(); - CommandTuple::Type selectCommand(ReadyCommands &); + virtual CommandTuple::Type selectCommand(const ReadyCommands &) override; private: const MemSpec *memSpec; ReadyCommands readyRasCommands; ReadyCommands readyCasCommands; + ReadyCommands readyRasCasCommands; }; #endif // CMDMUXOLDEST_H diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp index f895f635..12a167be 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.cpp @@ -40,7 +40,7 @@ using namespace tlm; CmdMuxStrict::CmdMuxStrict() : memSpec(Configuration::getInstance().memSpec) {} -CommandTuple::Type CmdMuxStrict::selectCommand(ReadyCommands &readyCommands) +CommandTuple::Type CmdMuxStrict::selectCommand(const ReadyCommands &readyCommands) { auto result = readyCommands.cend(); uint64_t lastPayloadID = UINT64_MAX; @@ -51,7 +51,7 @@ CommandTuple::Type CmdMuxStrict::selectCommand(ReadyCommands &readyCommands) for (auto it = readyCommands.cbegin(); it != readyCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newTimestamp < lastTimestamp) @@ -111,7 +111,7 @@ CmdMuxStrictRasCas::CmdMuxStrictRasCas() : memSpec(Configuration::getInstance(). readyCasCommands.reserve(memSpec->numberOfBanks); } -CommandTuple::Type CmdMuxStrictRasCas::selectCommand(ReadyCommands &readyCommands) +CommandTuple::Type CmdMuxStrictRasCas::selectCommand(const ReadyCommands &readyCommands) { readyRasCommands.clear(); readyCasCommands.clear(); @@ -124,6 +124,7 @@ CommandTuple::Type CmdMuxStrictRasCas::selectCommand(ReadyCommands &readyCommand readyCasCommands.emplace_back(it); } + auto result = readyCommands.cend(); auto resultRas = readyRasCommands.cend(); auto resultCas = readyCasCommands.cend(); @@ -135,7 +136,7 @@ CommandTuple::Type CmdMuxStrictRasCas::selectCommand(ReadyCommands &readyCommand for (auto it = readyRasCommands.cbegin(); it != readyRasCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newTimestamp < lastTimestamp) @@ -160,7 +161,7 @@ CommandTuple::Type CmdMuxStrictRasCas::selectCommand(ReadyCommands &readyCommand for (auto it = readyCasCommands.cbegin(); it != readyCasCommands.cend(); it++) { newTimestamp = std::get(*it) + - memSpec->getCommandLength(std::get(*it)) - memSpec->tCK; + memSpec->getCommandLength(std::get(*it)); newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); if (newPayloadID == nextPayloadID) @@ -182,38 +183,40 @@ CommandTuple::Type CmdMuxStrictRasCas::selectCommand(ReadyCommands &readyCommand } } - if (resultRas != readyRasCommands.cend() && resultCas != readyCasCommands.cend()) + readyRasCasCommands.clear(); + + if (resultRas != readyRasCommands.cend()) + readyRasCasCommands.emplace_back(*resultRas); + if (resultCas != readyCasCommands.cend()) + readyRasCasCommands.emplace_back(*resultCas); + + lastPayloadID = UINT64_MAX; + lastTimestamp = sc_max_time(); + + for (auto it = readyRasCasCommands.cbegin(); it != readyRasCasCommands.cend(); it++) { - if (std::get(*resultRas) == sc_time_stamp() - && std::get(*resultCas) == sc_time_stamp()) + newTimestamp = std::get(*it); + newPayloadID = DramExtension::getChannelPayloadID(std::get(*it)); + + if (newTimestamp < lastTimestamp) { - if (DramExtension::getChannelPayloadID(std::get(*resultRas)) - <= DramExtension::getChannelPayloadID(std::get(*resultCas))) - return *resultRas; - else - return *resultCas; + lastTimestamp = newTimestamp; + lastPayloadID = newPayloadID; + result = it; + } + else if (newTimestamp == lastTimestamp) + { + if (newPayloadID < lastPayloadID) + { + lastPayloadID = newPayloadID; + result = it; + } } - else if (std::get(*resultRas) == sc_time_stamp()) - return *resultRas; - else if (std::get(*resultCas) == sc_time_stamp()) - return *resultCas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); - } - else if (resultRas != readyRasCommands.cend()) - { - if (std::get(*resultRas) == sc_time_stamp()) - return *resultRas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); - } - else if (resultCas != readyCasCommands.cend()) - { - if (std::get(*resultCas) == sc_time_stamp()) - return *resultCas; - else - return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); } + + if (result != readyCommands.cend() && + std::get(*result) == sc_time_stamp()) + return *result; else return CommandTuple::Type(Command::NOP, nullptr, sc_max_time()); } diff --git a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h index 6ed6afd8..f7c42380 100644 --- a/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h +++ b/DRAMSys/library/src/controller/cmdmux/CmdMuxStrict.h @@ -42,7 +42,7 @@ class CmdMuxStrict : public CmdMuxIF { public: CmdMuxStrict(); - CommandTuple::Type selectCommand(ReadyCommands &); + virtual CommandTuple::Type selectCommand(const ReadyCommands &) override; private: uint64_t nextPayloadID = 1; @@ -53,13 +53,14 @@ class CmdMuxStrictRasCas : public CmdMuxIF { public: CmdMuxStrictRasCas(); - CommandTuple::Type selectCommand(ReadyCommands &); + virtual CommandTuple::Type selectCommand(const ReadyCommands &) override; private: uint64_t nextPayloadID = 1; const MemSpec *memSpec; ReadyCommands readyRasCommands; ReadyCommands readyCasCommands; + ReadyCommands readyRasCasCommands; }; #endif // CMDMUXSTRICT_H