From 011e1a99eace629860caae8456faf7e94790daab Mon Sep 17 00:00:00 2001 From: Janik Schlemminger Date: Thu, 13 Mar 2014 15:46:19 -0700 Subject: [PATCH] Added: PrechargeChecker, ActivateChecker, ReadChecker, WriteChecker Implemented: ActivateChecker Added functionality to Bus (InternalScheduler) --- DRAM/.cproject | 4 +- .../org.eclipse.ltk.core.refactoring.prefs | 2 + DRAM/main.cpp | 2 +- DRAM/src/common/dramextension.cpp | 5 ++ DRAM/src/common/dramextension.h | 1 + DRAM/src/core/Configuration.h | 5 +- DRAM/src/core/Controller.cpp | 16 ++++ DRAM/src/core/Controller.h | 9 ++- DRAM/src/core/TimingConfiguration.h | 15 ++-- DRAM/src/core/Utils.cpp | 15 ---- DRAM/src/core/Utils.h | 16 ---- DRAM/src/core/refresh/IRefreshManager.h | 2 +- DRAM/src/core/refresh/RefreshManager.cpp | 4 +- DRAM/src/core/scheduling/Command.h | 2 + DRAM/src/core/scheduling/CommandBus.cpp | 76 +++++++++++++++++++ DRAM/src/core/scheduling/CommandBus.h | 45 +++++++++++ DRAM/src/core/scheduling/CommandSchedule.h | 11 ++- .../scheduling/CommandSequenceGenerator.h | 2 - .../scheduling/CommandSequenceScheduler.cpp | 12 ++- .../scheduling/CommandSequenceScheduler.h | 7 +- DRAM/src/core/scheduling/IInternalScheduler.h | 22 ++++++ .../src/core/scheduling/InternalScheduler.cpp | 32 -------- DRAM/src/core/scheduling/InternalScheduler.h | 39 ---------- DRAM/src/core/scheduling/ScheduledCommand.h | 11 ++- .../scheduling/checker/ActivateChecker.cpp | 70 +++++++++++++++++ .../core/scheduling/checker/ActivateChecker.h | 41 ++++++++++ .../core/scheduling/checker/ICommandChecker.h | 28 +++++++ .../scheduling/checker/PrechargeChecker.cpp | 20 +++++ .../scheduling/checker/PrechargeChecker.h | 32 ++++++++ .../core/scheduling/checker/ReadChecker.cpp | 20 +++++ .../src/core/scheduling/checker/ReadChecker.h | 32 ++++++++ .../core/scheduling/checker/WriteChecker.cpp | 20 +++++ .../core/scheduling/checker/WriteChecker.h | 32 ++++++++ DRAM/src/core/utils/RingBuffer.h | 61 +++++++++++++++ DRAM/src/core/utils/Utils.cpp | 33 ++++++++ DRAM/src/core/utils/Utils.h | 22 ++++++ DRAM/testing/ActivateChecker_test.cpp | 12 +++ DRAM/testing/BankwiseRefreshManager_test.cpp | 70 +++++++++++++++++ DRAM/testing/PrechargeChecker_test.cpp | 12 +++ DRAM/testing/ReadChecker_test.cpp | 12 +++ DRAM/testing/RefreshManager_test.cpp | 16 ++-- DRAM/testing/WriteChecker_test.cpp | 12 +++ 42 files changed, 767 insertions(+), 133 deletions(-) create mode 100644 DRAM/.settings/org.eclipse.ltk.core.refactoring.prefs delete mode 100644 DRAM/src/core/Utils.cpp delete mode 100644 DRAM/src/core/Utils.h create mode 100644 DRAM/src/core/scheduling/CommandBus.cpp create mode 100644 DRAM/src/core/scheduling/CommandBus.h create mode 100644 DRAM/src/core/scheduling/IInternalScheduler.h delete mode 100644 DRAM/src/core/scheduling/InternalScheduler.cpp delete mode 100644 DRAM/src/core/scheduling/InternalScheduler.h create mode 100644 DRAM/src/core/scheduling/checker/ActivateChecker.cpp create mode 100644 DRAM/src/core/scheduling/checker/ActivateChecker.h create mode 100644 DRAM/src/core/scheduling/checker/ICommandChecker.h create mode 100644 DRAM/src/core/scheduling/checker/PrechargeChecker.cpp create mode 100644 DRAM/src/core/scheduling/checker/PrechargeChecker.h create mode 100644 DRAM/src/core/scheduling/checker/ReadChecker.cpp create mode 100644 DRAM/src/core/scheduling/checker/ReadChecker.h create mode 100644 DRAM/src/core/scheduling/checker/WriteChecker.cpp create mode 100644 DRAM/src/core/scheduling/checker/WriteChecker.h create mode 100644 DRAM/src/core/utils/RingBuffer.h create mode 100644 DRAM/src/core/utils/Utils.cpp create mode 100644 DRAM/src/core/utils/Utils.h create mode 100644 DRAM/testing/ActivateChecker_test.cpp create mode 100644 DRAM/testing/PrechargeChecker_test.cpp create mode 100644 DRAM/testing/ReadChecker_test.cpp create mode 100644 DRAM/testing/WriteChecker_test.cpp diff --git a/DRAM/.cproject b/DRAM/.cproject index 619d9447..856f3c3b 100644 --- a/DRAM/.cproject +++ b/DRAM/.cproject @@ -60,9 +60,7 @@ - - - + diff --git a/DRAM/.settings/org.eclipse.ltk.core.refactoring.prefs b/DRAM/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 00000000..b196c64a --- /dev/null +++ b/DRAM/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/DRAM/main.cpp b/DRAM/main.cpp index 1247e277..76f435c8 100644 --- a/DRAM/main.cpp +++ b/DRAM/main.cpp @@ -12,7 +12,7 @@ #include #include #include - +#include using namespace std; using namespace testing; diff --git a/DRAM/src/common/dramextension.cpp b/DRAM/src/common/dramextension.cpp index fd168765..2db16157 100644 --- a/DRAM/src/common/dramextension.cpp +++ b/DRAM/src/common/dramextension.cpp @@ -50,6 +50,11 @@ bool operator !=(const Bank& lhs, const Bank& rhs) return !(lhs == rhs); } +bool operator <(const Bank& lhs, const Bank& rhs) +{ + return lhs.ID() < rhs.ID(); +} + const Row Row::NO_ROW; bool operator ==(const Row& lhs, const Row& rhs) diff --git a/DRAM/src/common/dramextension.h b/DRAM/src/common/dramextension.h index 9fe53a20..8d934451 100644 --- a/DRAM/src/common/dramextension.h +++ b/DRAM/src/common/dramextension.h @@ -55,6 +55,7 @@ bool operator==(const Thread &lhs, const Thread &rhs); bool operator!=(const Thread &lhs, const Thread &rhs); bool operator==(const Bank &lhs, const Bank &rhs); bool operator!=(const Bank &lhs, const Bank &rhs); +bool operator<(const Bank &lhs, const Bank &rhs); bool operator==(const Row &lhs, const Row &rhs); bool operator!=(const Row &lhs, const Row &rhs); bool operator==(const Column &lhs, const Column &rhs); diff --git a/DRAM/src/core/Configuration.h b/DRAM/src/core/Configuration.h index a4396d00..2dfe1511 100644 --- a/DRAM/src/core/Configuration.h +++ b/DRAM/src/core/Configuration.h @@ -15,10 +15,13 @@ namespace controller{ struct Configuration { - unsigned int numberOfBanks; + Configuration():Timings(numberOfBanks){} + unsigned int numberOfBanks = 8; TimingConfiguration Timings; bool RefreshBankwise = false; + + unsigned int nActivate = 4; }; } /* namespace controller */ diff --git a/DRAM/src/core/Controller.cpp b/DRAM/src/core/Controller.cpp index 2489c504..b6b36e62 100644 --- a/DRAM/src/core/Controller.cpp +++ b/DRAM/src/core/Controller.cpp @@ -9,5 +9,21 @@ namespace controller { +/*Controller::Controller() +{ + //create command scheduler +} + +Controller::~Controller() +{ + //delete command scheduler +}*/ + +bool Controller::schedule(sc_time currentTime, + tlm::tlm_generic_payload* externalTransaction) +{ + bus.cleanUpPendingBusCommands(currentTime); +} } /* namespace controller */ + diff --git a/DRAM/src/core/Controller.h b/DRAM/src/core/Controller.h index 38566a5b..930a7dfa 100644 --- a/DRAM/src/core/Controller.h +++ b/DRAM/src/core/Controller.h @@ -10,11 +10,13 @@ #include #include "scheduling/CommandSequenceGenerator.h" -#include "scheduling/InternalScheduler.h" +#include "scheduling/CommandBus.h" #include "Configuration.h" #include "scheduling/CommandSequenceScheduler.h" #include "refresh/RefreshManager.h" #include "powerdown/PowerDownManager.h" +#include +#include "scheduling/checker/ICommandChecker.h" namespace controller { @@ -24,17 +26,18 @@ public: Controller(); virtual ~Controller(); - bool schedule(tlm::tlm_generic_payload* externalTransaction); //return TLM status?? + bool schedule( sc_time currentTime, tlm::tlm_generic_payload* externalTransaction); //return TLM status?? private: Configuration config; ControllerState state; CommandSequenceGenerator commandGenerator; + std::map commandScheduler; CommandSequenceScheduler commandSequenceScheduler; RefreshManager refreshManager; PowerDownManager powerDownManager; - InternalScheduler internalScheduler; + CommandBus bus; }; } /* namespace controller */ diff --git a/DRAM/src/core/TimingConfiguration.h b/DRAM/src/core/TimingConfiguration.h index d9247a94..f175a5cc 100644 --- a/DRAM/src/core/TimingConfiguration.h +++ b/DRAM/src/core/TimingConfiguration.h @@ -9,6 +9,7 @@ #define TIMINGS_H_ #include +#include "core/utils/Utils.h" namespace controller{ @@ -21,9 +22,8 @@ struct RefreshTiming struct TimingConfiguration { - TimingConfiguration() + TimingConfiguration(unsigned int numberOfBanks) { - unsigned int numberOfBanks = 8; for (unsigned int i = 0; i < numberOfBanks; ++i) { sc_time tRFC = 18*clk; @@ -35,9 +35,14 @@ struct TimingConfiguration sc_time clk = sc_time(6.0, SC_NS); // 166MHz - sc_time tRP = 3*clk; - sc_time tRAS = 6*clk; - sc_time tRC = tRP + tRAS; + sc_time tRP = 3*clk; //precharge-time (pre -> act same bank) + sc_time tRAS = 6*clk; //active-time (act -> pre same bank) + + sc_time tRC = tRP + tRAS; //RAS-cycle-time (min time bw 2 succesive ACT to same bank) + sc_time tRRD = 2*clk; //(min time bw 2 succesive ACT to different banks) + sc_time tRCD = 5*clk; //act -> read/write + + sc_time tTAW = clkAlign(sc_time(50, SC_NS), clk, Alignment::UP); //Refresh //sc_time tRFC = 18*clk; diff --git a/DRAM/src/core/Utils.cpp b/DRAM/src/core/Utils.cpp deleted file mode 100644 index ea38acc9..00000000 --- a/DRAM/src/core/Utils.cpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Utils.cpp - * - * Created on: Mar 12, 2014 - * Author: jonny - */ - -#include "Utils.h" - -using namespace common; - -unsigned int getStartAddress(Bank bank) -{ - return 0; -} diff --git a/DRAM/src/core/Utils.h b/DRAM/src/core/Utils.h deleted file mode 100644 index c6af8080..00000000 --- a/DRAM/src/core/Utils.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Utils.h - * - * Created on: Mar 10, 2014 - * Author: jonny - */ - -#ifndef UTILS_H_ -#define UTILS_H_ - -#include "common/dramextension.h" - -unsigned int getStartAddress(common::Bank bank); - - -#endif /* UTILS_H_ */ diff --git a/DRAM/src/core/refresh/IRefreshManager.h b/DRAM/src/core/refresh/IRefreshManager.h index 0e2fb564..6d8b0e0a 100644 --- a/DRAM/src/core/refresh/IRefreshManager.h +++ b/DRAM/src/core/refresh/IRefreshManager.h @@ -10,7 +10,7 @@ #include #include -#include "core/scheduling/InternalScheduler.h" +#include "core/scheduling/CommandBus.h" #include "core/Configuration.h" #include "core/scheduling/ScheduledCommand.h" diff --git a/DRAM/src/core/refresh/RefreshManager.cpp b/DRAM/src/core/refresh/RefreshManager.cpp index 2745e1d8..c1813f07 100644 --- a/DRAM/src/core/refresh/RefreshManager.cpp +++ b/DRAM/src/core/refresh/RefreshManager.cpp @@ -6,7 +6,7 @@ */ #include -#include "core/Utils.h" +#include "core/utils/Utils.h" using namespace common; @@ -24,7 +24,7 @@ RefreshManager::RefreshManager(const RefreshTiming& refreshTiming, RefreshManager::RefreshManager(const RefreshTiming& refreshTiming, IInternalScheduler& internalScheduler, Bank bank) : refreshTiming(refreshTiming), internalScheduler(internalScheduler), nextPlannedRefresh( - refreshTransaction, Command::Refresh, sc_time(65, SC_MS), refreshTiming.tRFC) + refreshTransaction, Command::Refresh, SC_ZERO_TIME, refreshTiming.tRFC) { setupTransaction(refreshTransaction, bank); planNextRefresh(nextPlannedRefresh); diff --git a/DRAM/src/core/scheduling/Command.h b/DRAM/src/core/scheduling/Command.h index 66411727..cdaa83e0 100644 --- a/DRAM/src/core/scheduling/Command.h +++ b/DRAM/src/core/scheduling/Command.h @@ -12,6 +12,8 @@ namespace controller { enum class Command {Precharge, PrechargeAll, Activate, Read, Write, ReadA, WriteA, Refresh}; +typedef std::vector CommandSequence; + } /* namespace controller */ #endif /* COMMAND_H_ */ diff --git a/DRAM/src/core/scheduling/CommandBus.cpp b/DRAM/src/core/scheduling/CommandBus.cpp new file mode 100644 index 00000000..52375946 --- /dev/null +++ b/DRAM/src/core/scheduling/CommandBus.cpp @@ -0,0 +1,76 @@ +/* + * InternalScheduler.cpp + * + * Created on: Mar 9, 2014 + * Author: jonny + */ + +#include "CommandBus.h" +#include + +namespace controller { + +void CommandBus::scheduleCommand(const ScheduledCommand& command) +{ + if(command.getCommand() == Command::Refresh) + { + scheduleRefresh(command); + lastCommandsOnBus.at(Command::Activate).at(command.getBank()) = command.getStart(); + } + + assert(pendingBusCommands.count(command.getStart()) == 0); + pendingBusCommands.insert(command.getStart()); +} + +void CommandBus::scheduleTrigger(const Trigger command, sc_time time) +{ + +} + +sc_time CommandBus::getLastCommand(Command command, common::Bank bank) +{ + return lastCommandsOnBus[command][bank]; +} + +sc_time CommandBus::getLastCommand(Command command) +{ + sc_time max; + for(unsigned int i = 0; i < config.numberOfBanks; ++i) + { + sc_time current = getLastCommand(command, common::Bank(i)); + if(current > max) + max = current; + } + return max; +} + +bool CommandBus::notYetScheduled(Command command) const +{ + return (lastCommandsOnBus.count(command) == 0); +} + +sc_time CommandBus::getEarliestStartTime(const ScheduledCommand& command) const +{ + sc_time newStart = command.getStart(); + + std::set::iterator it = pendingBusCommands.begin(); + while(it != pendingBusCommands.end() && *it <= newStart) + { + if(*it == newStart) + newStart += config.Timings.clk; + ++it; + } + return newStart; +} + +void CommandBus::cleanUpPendingBusCommands(sc_time currentTime) +{ + pendingBusCommands.erase(pendingBusCommands.begin(), pendingBusCommands.lower_bound(currentTime)); +} + +void CommandBus::scheduleRefresh(const ScheduledCommand& command) +{ + state.bankStates.closeAllRowBuffers(); +} + +} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/CommandBus.h b/DRAM/src/core/scheduling/CommandBus.h new file mode 100644 index 00000000..46cf3cc5 --- /dev/null +++ b/DRAM/src/core/scheduling/CommandBus.h @@ -0,0 +1,45 @@ +/* + * InternalScheduler.h + * + * Created on: Mar 6, 2014 + * Author: jonny + */ + +#ifndef INTERNALSCHEDULER_H_ +#define INTERNALSCHEDULER_H_ + +#include "CommandSchedule.h" +#include "core/ControllerState.h" +#include "core/scheduling/Trigger.h" +#include "IInternalScheduler.h" +#include "core/Configuration.h" +#include +#include + +namespace controller{ + +class CommandBus : public IInternalScheduler +{ +public: + CommandBus(controller::ControllerState& state, const Configuration& config) : state(state), config(config) {} + virtual void scheduleCommand(const ScheduledCommand& command); + virtual void scheduleTrigger(const Trigger trigger, sc_time time); + + void cleanUpPendingBusCommands(sc_time currentTime); + + sc_time getLastCommand(Command command, common::Bank bank);//TODO simple way to make it const? + sc_time getLastCommand(Command command); + bool notYetScheduled(Command command) const; + sc_time getEarliestStartTime(const ScheduledCommand& command) const; +private: + controller::ControllerState& state; + const Configuration& config; + + std::map> lastCommandsOnBus; + void scheduleRefresh(const controller::ScheduledCommand& command); + + std::set pendingBusCommands; +}; +} + +#endif /* INTERNALSCHEDULER_H_ */ diff --git a/DRAM/src/core/scheduling/CommandSchedule.h b/DRAM/src/core/scheduling/CommandSchedule.h index 9ebdc8f9..4d72de06 100644 --- a/DRAM/src/core/scheduling/CommandSchedule.h +++ b/DRAM/src/core/scheduling/CommandSchedule.h @@ -12,7 +12,6 @@ #include "common/dramextension.h" #include "ScheduledCommand.h" -using namespace common; namespace controller { @@ -27,6 +26,12 @@ public: scheduledCommands.push_back(ScheduledCommand(transaction, command, time, executionTime)); } + void add(ScheduledCommand scheduledCommand) + { + assert(&scheduledCommand.getTransaction() == &transaction); + scheduledCommands.push_back(scheduledCommand); + } + const std::vector& getScheduledCommands() const { return scheduledCommands; @@ -47,9 +52,9 @@ public: return scheduledCommands.back().getEnd() - scheduledCommands.front().getStart(); } - Bank getBank() const + common::Bank getBank() const { - return DramExtension::getExtension(&transaction).getBank(); + return common::DramExtension::getExtension(&transaction).getBank(); } private: diff --git a/DRAM/src/core/scheduling/CommandSequenceGenerator.h b/DRAM/src/core/scheduling/CommandSequenceGenerator.h index d4dedc68..51b69fbb 100644 --- a/DRAM/src/core/scheduling/CommandSequenceGenerator.h +++ b/DRAM/src/core/scheduling/CommandSequenceGenerator.h @@ -15,8 +15,6 @@ namespace controller { -typedef std::vector CommandSequence; - class CommandSequenceGenerator { public: CommandSequenceGenerator(const ControllerState& controllerState) : controllerState(controllerState) {} diff --git a/DRAM/src/core/scheduling/CommandSequenceScheduler.cpp b/DRAM/src/core/scheduling/CommandSequenceScheduler.cpp index 73b4da69..bab61737 100644 --- a/DRAM/src/core/scheduling/CommandSequenceScheduler.cpp +++ b/DRAM/src/core/scheduling/CommandSequenceScheduler.cpp @@ -15,9 +15,17 @@ CommandSequenceScheduler::CommandSequenceScheduler() } -CommandSequenceScheduler::~CommandSequenceScheduler() +CommandSchedule CommandSequenceScheduler::prepareSchedule(tlm::tlm_generic_payload& transaction, CommandSequence commands) { - // TODO Auto-generated destructor stub + CommandSchedule schedule(transaction); + for(unsigned int i = 0; i < commands.size(); ++i) + { + Command command = commands.at(i); + sc_time start; + sc_time executionTime; + schedule.add(command, start, executionTime); + } + return schedule; } } /* namespace controller */ diff --git a/DRAM/src/core/scheduling/CommandSequenceScheduler.h b/DRAM/src/core/scheduling/CommandSequenceScheduler.h index 939c5ef1..3264ab49 100644 --- a/DRAM/src/core/scheduling/CommandSequenceScheduler.h +++ b/DRAM/src/core/scheduling/CommandSequenceScheduler.h @@ -8,13 +8,18 @@ #ifndef COMMANDSEQUENCESCHEDULER_H_ #define COMMANDSEQUENCESCHEDULER_H_ +#include "CommandSchedule.h" +#include "Command.h" + namespace controller { class CommandSequenceScheduler { public: CommandSequenceScheduler(); - virtual ~CommandSequenceScheduler(); + virtual ~CommandSequenceScheduler(){} + + CommandSchedule prepareSchedule(tlm::tlm_generic_payload& transaction, CommandSequence commands); }; } /* namespace controller */ diff --git a/DRAM/src/core/scheduling/IInternalScheduler.h b/DRAM/src/core/scheduling/IInternalScheduler.h new file mode 100644 index 00000000..b21e13fe --- /dev/null +++ b/DRAM/src/core/scheduling/IInternalScheduler.h @@ -0,0 +1,22 @@ +/* + * IInternalScheduler.h + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#ifndef IINTERNALSCHEDULER_H_ +#define IINTERNALSCHEDULER_H_ + +namespace controller +{ +class IInternalScheduler +{ +public: + virtual ~IInternalScheduler() {} + virtual void scheduleCommand(const controller::ScheduledCommand& command) = 0; + virtual void scheduleTrigger(const controller::Trigger trigger, sc_time time) = 0; +}; +} + +#endif /* IINTERNALSCHEDULER_H_ */ diff --git a/DRAM/src/core/scheduling/InternalScheduler.cpp b/DRAM/src/core/scheduling/InternalScheduler.cpp deleted file mode 100644 index 6c8bd304..00000000 --- a/DRAM/src/core/scheduling/InternalScheduler.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * InternalScheduler.cpp - * - * Created on: Mar 9, 2014 - * Author: jonny - */ - -#include "InternalScheduler.h" - -namespace controller { - -void InternalScheduler::scheduleCommand(const ScheduledCommand& command) -{ - if(command.getCommand() == Command::Refresh) - { - scheduleRefresh(command); - } -} - -void InternalScheduler::scheduleTrigger(const Trigger command, sc_time time) -{ - -} - -void InternalScheduler::scheduleRefresh(const ScheduledCommand& command) -{ - state.bankStates.closeAllRowBuffers(); - - -} - -} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/InternalScheduler.h b/DRAM/src/core/scheduling/InternalScheduler.h deleted file mode 100644 index 58dfbce1..00000000 --- a/DRAM/src/core/scheduling/InternalScheduler.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * InternalScheduler.h - * - * Created on: Mar 6, 2014 - * Author: jonny - */ - -#ifndef INTERNALSCHEDULER_H_ -#define INTERNALSCHEDULER_H_ - -#include "CommandSchedule.h" -#include "core/ControllerState.h" -#include "core/scheduling/Trigger.h" - -namespace controller{ - -class IInternalScheduler -{ -public: - virtual ~IInternalScheduler() {} - virtual void scheduleCommand(const controller::ScheduledCommand& command) = 0; - virtual void scheduleTrigger(const controller::Trigger trigger, sc_time time) = 0; -}; - -class InternalScheduler : public IInternalScheduler -{ -public: - InternalScheduler(controller::ControllerState& state) : state(state) {} - virtual void scheduleCommand(const controller::ScheduledCommand& command); - virtual void scheduleTrigger(const controller::Trigger trigger, sc_time time); - -private: - controller::ControllerState& state; - - void scheduleRefresh(const controller::ScheduledCommand& command); -}; -} - -#endif /* INTERNALSCHEDULER_H_ */ diff --git a/DRAM/src/core/scheduling/ScheduledCommand.h b/DRAM/src/core/scheduling/ScheduledCommand.h index a09b9e3f..978c4608 100644 --- a/DRAM/src/core/scheduling/ScheduledCommand.h +++ b/DRAM/src/core/scheduling/ScheduledCommand.h @@ -8,8 +8,10 @@ #ifndef SCHEDULEDCOMMAND_H_ #define SCHEDULEDCOMMAND_H_ -#include "Command.h" #include +#include +#include "Command.h" +#include "common/dramextension.h" namespace controller { @@ -52,6 +54,11 @@ public: return transaction; } + common::Bank getBank() const + { + return common::DramExtension::getExtension(&transaction).getBank(); + } + inline bool operator==(const ScheduledCommand& b) const { return b.command == command && b.start == start && b.executionTime == executionTime @@ -62,7 +69,7 @@ private: const tlm::tlm_generic_payload& transaction; const Command command; sc_time start; - const sc_time executionTime; + sc_time executionTime; }; diff --git a/DRAM/src/core/scheduling/checker/ActivateChecker.cpp b/DRAM/src/core/scheduling/checker/ActivateChecker.cpp new file mode 100644 index 00000000..ea079ac7 --- /dev/null +++ b/DRAM/src/core/scheduling/checker/ActivateChecker.cpp @@ -0,0 +1,70 @@ +/* + * ActivateScheduler.cpp + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#include +#include +#include "core/utils/Utils.h" +#include + +using namespace common; + +namespace controller { + +void ActivateChecker::check(ScheduledCommand& command) const +{ + if (command.getCommand() != Command::Activate) + return; + check_activateToActivate(command); + check_nActivateWindow(command); + check_bus(command); +} + +void ActivateChecker::check_activateToActivate(ScheduledCommand& command) const +{ + if (bus.notYetScheduled(Command::Activate)) + return; + + sc_time lastActivate = bus.getLastCommand(Command::Activate); + sc_time lastActivateOnBank = bus.getLastCommand(Command::Activate, command.getBank()); + + command.delayStart(delayByConstraint(lastActivate, command.getStart(), config.Timings.tRRD)); + command.delayStart( + delayByConstraint(lastActivateOnBank, command.getStart(), config.Timings.tRC)); +} + +void ActivateChecker::check_prechargeToActivate(ScheduledCommand& command) const +{ + sc_time lastPrechargeOnBank = std::max( + bus.getLastCommand(Command::Precharge, command.getBank()), + bus.getLastCommand(Command::PrechargeAll, command.getBank())); + command.delayStart( + delayByConstraint(lastPrechargeOnBank, command.getStart(), config.Timings.tRC)); +} + +void ActivateChecker::check_nActivateWindow(ScheduledCommand& command) const +{ + if (!nActivateWindow.isFull()) + return; + command.delayStart( + delayByConstraint(nActivateWindow.getOldest(), command.getStart(), + config.Timings.tTAW)); +} + +void ActivateChecker::check_bus(ScheduledCommand& command) const +{ + command.delayStart(bus.getEarliestStartTime(command) - command.getStart()); +} + +void ActivateChecker::cb_IInternalScheduler(const ScheduledCommand& command) +{ + if (command.getCommand() == Command::Activate) + { + nActivateWindow.put(command.getStart()); + } +} + +} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/checker/ActivateChecker.h b/DRAM/src/core/scheduling/checker/ActivateChecker.h new file mode 100644 index 00000000..7acccced --- /dev/null +++ b/DRAM/src/core/scheduling/checker/ActivateChecker.h @@ -0,0 +1,41 @@ +/* + * ActivateScheduler.h + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#ifndef ACTIVATESCHEDULER_H_ +#define ACTIVATESCHEDULER_H_ + +#include +#include "core/scheduling/checker/ICommandChecker.h" +#include "core/Configuration.h" +#include "core/utils/RingBuffer.h" +#include "core/scheduling/CommandBus.h" + +namespace controller { + +class ActivateChecker: public controller::ICommandChecker +{ +public: + ActivateChecker(Configuration& config, CommandBus& commandBus) : config(config), bus(commandBus), nActivateWindow(config.nActivate - 1){} + virtual ~ActivateChecker(){} + + virtual void check(ScheduledCommand& command) const; + virtual void cb_IInternalScheduler(const ScheduledCommand& command); +private: + const Configuration& config; + CommandBus& bus;//should be const .. but fucking map access operator!!!! + + void check_activateToActivate(ScheduledCommand& command) const; + void check_prechargeToActivate(ScheduledCommand& command) const; + void check_nActivateWindow(ScheduledCommand& command) const; + void check_bus(ScheduledCommand& command) const; + + RingBuffer nActivateWindow; +}; + +} /* namespace controller */ + +#endif /* ACTIVATESCHEDULER_H_ */ diff --git a/DRAM/src/core/scheduling/checker/ICommandChecker.h b/DRAM/src/core/scheduling/checker/ICommandChecker.h new file mode 100644 index 00000000..c7d22bb0 --- /dev/null +++ b/DRAM/src/core/scheduling/checker/ICommandChecker.h @@ -0,0 +1,28 @@ +/* + * ICommandScheduler.h + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#ifndef ICOMMANDSCHEDULER_H_ +#define ICOMMANDSCHEDULER_H_ + +#include "systemc.h" +#include "core/scheduling/ScheduledCommand.h" + +namespace controller { + +class ICommandChecker +{ +public: + virtual ~ICommandChecker() {} + + virtual void schedule(ScheduledCommand& command) const = 0; + virtual void cb_IInternalScheduler(const ScheduledCommand& command) = 0; +}; + +} /* namespace controller */ + + +#endif /* ICOMMANDSCHEDULER_H_ */ diff --git a/DRAM/src/core/scheduling/checker/PrechargeChecker.cpp b/DRAM/src/core/scheduling/checker/PrechargeChecker.cpp new file mode 100644 index 00000000..3866edca --- /dev/null +++ b/DRAM/src/core/scheduling/checker/PrechargeChecker.cpp @@ -0,0 +1,20 @@ +/* + * PrechargeChecker.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +void controller::PrechargeChecker::check(ScheduledCommand& command) const +{ +} + +void controller::PrechargeChecker::cb_IInternalScheduler(const ScheduledCommand& command) +{ +} + +} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/checker/PrechargeChecker.h b/DRAM/src/core/scheduling/checker/PrechargeChecker.h new file mode 100644 index 00000000..4ef266f8 --- /dev/null +++ b/DRAM/src/core/scheduling/checker/PrechargeChecker.h @@ -0,0 +1,32 @@ +/* + * PrechargeChecker.h + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#ifndef PRECHARGECHECKER_H_ +#define PRECHARGECHECKER_H_ + +#include +#include "core/Configuration.h" +#include "core/scheduling/CommandBus.h" + +namespace controller { + +class PrechargeChecker: public controller::ICommandChecker +{ +public: + PrechargeChecker(const Configuration& config, const CommandBus& commandBus) : config(config), bus(commandBus) {} + virtual ~PrechargeChecker() {} + + virtual void check(ScheduledCommand& command) const; + virtual void cb_IInternalScheduler(const ScheduledCommand& command); +private: + const Configuration& config; + const CommandBus& bus; +}; + +} /* namespace controller */ + +#endif /* PRECHARGECHECKER_H_ */ diff --git a/DRAM/src/core/scheduling/checker/ReadChecker.cpp b/DRAM/src/core/scheduling/checker/ReadChecker.cpp new file mode 100644 index 00000000..11ed9a9c --- /dev/null +++ b/DRAM/src/core/scheduling/checker/ReadChecker.cpp @@ -0,0 +1,20 @@ +/* + * ReadChecker.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +void ReadChecker::check(ScheduledCommand& command) const +{ +} + +void ReadChecker::cb_IInternalScheduler(const ScheduledCommand& command) +{ +} + +} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/checker/ReadChecker.h b/DRAM/src/core/scheduling/checker/ReadChecker.h new file mode 100644 index 00000000..0630584a --- /dev/null +++ b/DRAM/src/core/scheduling/checker/ReadChecker.h @@ -0,0 +1,32 @@ +/* + * ReadChecker.h + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#ifndef READCHECKER_H_ +#define READCHECKER_H_ + +#include +#include "core/Configuration.h" +#include "core/scheduling/CommandBus.h" + +namespace controller { + +class ReadChecker: public controller::ICommandChecker +{ +public: + ReadChecker(const Configuration& config, const CommandBus& commandBus) : config(config), bus(commandBus) {} + virtual ~ReadChecker() {} + + virtual void check(ScheduledCommand& command) const; + virtual void cb_IInternalScheduler(const ScheduledCommand& command); +private: + const Configuration& config; + const CommandBus& bus; +}; + +} /* namespace controller */ + +#endif /* READCHECKER_H_ */ diff --git a/DRAM/src/core/scheduling/checker/WriteChecker.cpp b/DRAM/src/core/scheduling/checker/WriteChecker.cpp new file mode 100644 index 00000000..1106fbc2 --- /dev/null +++ b/DRAM/src/core/scheduling/checker/WriteChecker.cpp @@ -0,0 +1,20 @@ +/* + * WriteChecker.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +void WriteChecker::check(ScheduledCommand& command) const +{ +} + +void WriteChecker::cb_IInternalScheduler(const ScheduledCommand& command) +{ +} + +} /* namespace controller */ diff --git a/DRAM/src/core/scheduling/checker/WriteChecker.h b/DRAM/src/core/scheduling/checker/WriteChecker.h new file mode 100644 index 00000000..360c5776 --- /dev/null +++ b/DRAM/src/core/scheduling/checker/WriteChecker.h @@ -0,0 +1,32 @@ +/* + * WriteChecker.h + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#ifndef WRITECHECKER_H_ +#define WRITECHECKER_H_ + +#include +#include "core/Configuration.h" +#include "core/scheduling/CommandBus.h" + +namespace controller { + +class WriteChecker: public controller::ICommandChecker +{ +public: + WriteChecker(const Configuration& config, const CommandBus& commandBus) : config(config), bus(commandBus) {} + virtual ~WriteChecker() {} + + virtual void check(ScheduledCommand& command) const; + virtual void cb_IInternalScheduler(const ScheduledCommand& command); +private: + const Configuration& config; + const CommandBus& bus; +}; + +} /* namespace controller */ + +#endif /* WRITECHECKER_H_ */ diff --git a/DRAM/src/core/utils/RingBuffer.h b/DRAM/src/core/utils/RingBuffer.h new file mode 100644 index 00000000..27c43aa0 --- /dev/null +++ b/DRAM/src/core/utils/RingBuffer.h @@ -0,0 +1,61 @@ +/* + * RingBuffer.h + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#ifndef RINGBUFFER_H_ +#define RINGBUFFER_H_ + +#include + +class RingBuffer +{ + +public: + RingBuffer(unsigned int maxSize) : maxSize(maxSize) {} + + void put(sc_time t) + { + buffer.push_front(t); + if(getSize()>maxSize) + buffer.pop_back(); + } + + sc_time getOldest() const + { + return buffer.front(); + } + + sc_time getNewest() const + { + return buffer.back(); + } + + bool isFull() const + { + return getSize() == maxSize; + } + + bool isEmpty() const + { + return buffer.empty(); + } + + unsigned int getSize() const + { + return buffer.size(); + } + + const sc_time get(unsigned int i) const + { + return buffer.at(i); + } + +private: + std::deque buffer; + unsigned int maxSize; +}; + +#endif /* RINGBUFFER_H_ */ diff --git a/DRAM/src/core/utils/Utils.cpp b/DRAM/src/core/utils/Utils.cpp new file mode 100644 index 00000000..87e4914e --- /dev/null +++ b/DRAM/src/core/utils/Utils.cpp @@ -0,0 +1,33 @@ +/* + * Utils.cpp + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#include "Utils.h" + +using namespace common; + +unsigned int getStartAddress(Bank bank) +{ + return 0; +} + +sc_time delayByConstraint(sc_time previous, sc_time start, sc_time constraint) +{ + assert(start > previous); + sc_time distance = start - previous; + if(distance < constraint) + return constraint - distance; + else + return SC_ZERO_TIME; +} + +sc_time clkAlign(sc_time time, sc_time clk, Alignment alignment) +{ + if(alignment == Alignment::UP) + return ceil(time/clk)*clk; + else + return floor(time/clk)*clk; +} diff --git a/DRAM/src/core/utils/Utils.h b/DRAM/src/core/utils/Utils.h new file mode 100644 index 00000000..0992ef0a --- /dev/null +++ b/DRAM/src/core/utils/Utils.h @@ -0,0 +1,22 @@ +/* + * Utils.h + * + * Created on: Mar 10, 2014 + * Author: jonny + */ + +#ifndef UTILS_H_ +#define UTILS_H_ + +#include "common/dramextension.h" +#include + +unsigned int getStartAddress(common::Bank bank); + +sc_time delayByConstraint(sc_time previous, sc_time start, sc_time constraint); + +enum class Alignment {UP, DOWN}; + +sc_time clkAlign(sc_time time, sc_time clk, Alignment alignment = Alignment::UP); + +#endif /* UTILS_H_ */ diff --git a/DRAM/testing/ActivateChecker_test.cpp b/DRAM/testing/ActivateChecker_test.cpp new file mode 100644 index 00000000..de42c3c0 --- /dev/null +++ b/DRAM/testing/ActivateChecker_test.cpp @@ -0,0 +1,12 @@ +/* + * ActivateScheduler_test.cpp + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +} /* namespace controller */ diff --git a/DRAM/testing/BankwiseRefreshManager_test.cpp b/DRAM/testing/BankwiseRefreshManager_test.cpp index ab5996cf..6f7ae459 100644 --- a/DRAM/testing/BankwiseRefreshManager_test.cpp +++ b/DRAM/testing/BankwiseRefreshManager_test.cpp @@ -5,8 +5,78 @@ * Author: jonny */ +#include +#include #include +#include "testUtils.h" +#include "common/dramextension.h" + +using namespace testing; +using namespace common; namespace controller { +class MockInternalScheduler: public IInternalScheduler +{ +public: + MOCK_METHOD1(scheduleCommand, void (const ScheduledCommand& command)); + MOCK_METHOD2(scheduleTrigger, void (const Trigger command, sc_time time)); +}; + +class BankwiseRefreshManagerTest: public Test +{ +public: + BankwiseRefreshManagerTest(){} + + Configuration config; + MockInternalScheduler internalScheduler; + std::shared_ptr transaction; + + CommandSchedule getCollidingWithFirstRefreshOnBank(unsigned int i) + { + transaction = createDummyPayload(Thread(0), Bank(i)); + CommandSchedule colliding(*transaction.get()); + sc_time tREFI = config.Timings.refreshTimings.at(i).tREFI; + sc_time clk = config.Timings.clk; + + colliding.add(Command::Read, tREFI - 1 * clk, 2 * clk); + return colliding; + }; + + CommandSchedule getNonCollidingWithFirstRefreshOnBank(unsigned int i) + { + transaction = createDummyPayload(Thread(0), Bank(i)); + CommandSchedule non_colliding(*transaction.get()); + sc_time tREFI = config.Timings.refreshTimings.at(i).tREFI; + sc_time clk = config.Timings.clk; + + non_colliding.add(Command::Read, tREFI - 3 * clk, 2 * clk); + return non_colliding; + }; +}; + +TEST_F(BankwiseRefreshManagerTest, RefreshsAreScheduledAfterStartup) +{ + + EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(config.numberOfBanks * 2); + EXPECT_CALL(internalScheduler, scheduleCommand(_)).Times(config.numberOfBanks); + + //first trigger for each bank is scheduled + BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); + + //first refresh for each bank is scheduled, second trigger is scheduled + manager.scheduleRefresh(config.Timings.refreshTimings.at(0).tREFI);//call back from wrapper +} + +TEST_F(BankwiseRefreshManagerTest, hasCollisionExpectCollisionOnBank2) +{ + BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); + EXPECT_TRUE(manager.hasCollision(getCollidingWithFirstRefreshOnBank(2))); +} + +TEST_F(BankwiseRefreshManagerTest, hasCollisionExpectNoCollisionOnBank2) +{ + BankwiseRefreshManager manager(config.Timings.refreshTimings, internalScheduler); + EXPECT_FALSE(manager.hasCollision(getNonCollidingWithFirstRefreshOnBank(2))); +} } /* namespace controller */ diff --git a/DRAM/testing/PrechargeChecker_test.cpp b/DRAM/testing/PrechargeChecker_test.cpp new file mode 100644 index 00000000..5d92b8eb --- /dev/null +++ b/DRAM/testing/PrechargeChecker_test.cpp @@ -0,0 +1,12 @@ +/* + * PrechargeChecker_test.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +} /* namespace controller */ diff --git a/DRAM/testing/ReadChecker_test.cpp b/DRAM/testing/ReadChecker_test.cpp new file mode 100644 index 00000000..ebe3b0fb --- /dev/null +++ b/DRAM/testing/ReadChecker_test.cpp @@ -0,0 +1,12 @@ +/* + * ReadChecker_test.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +} /* namespace controller */ diff --git a/DRAM/testing/RefreshManager_test.cpp b/DRAM/testing/RefreshManager_test.cpp index bbed519c..86ba7eef 100644 --- a/DRAM/testing/RefreshManager_test.cpp +++ b/DRAM/testing/RefreshManager_test.cpp @@ -8,12 +8,17 @@ #include #include #include "core/refresh/RefreshManager.h" +#include "testUtils.h" using ::testing::_; using ::testing::AtLeast; using ::testing::Expectation; using namespace testing; +#include + +const double lowest_double = -DBL_MAX; + constexpr unsigned int numberOfBanks = 8; namespace controller { @@ -33,10 +38,12 @@ public: Configuration config; MockInternalScheduler internalScheduler; + std::shared_ptr transaction; + CommandSchedule getCollidingWithFirstRefresh() { - tlm::tlm_generic_payload transaction; - CommandSchedule colliding(transaction); + transaction = createDummyPayload(); + CommandSchedule colliding(*transaction.get()); sc_time tREFI = config.Timings.refreshTimings.at(0).tREFI; sc_time clk = config.Timings.clk; @@ -46,8 +53,8 @@ public: CommandSchedule getNonCollidingWithFirstRefresh() { - tlm::tlm_generic_payload transaction; - CommandSchedule non_colliding(transaction); + transaction = createDummyPayload(); + CommandSchedule non_colliding(*transaction.get()); sc_time tREFI = config.Timings.refreshTimings.at(0).tREFI; sc_time clk = config.Timings.clk; @@ -59,7 +66,6 @@ public: TEST_F(RefreshManagerTest, RefreshIsScheduledAfterStartup) { - EXPECT_CALL(internalScheduler, scheduleTrigger(Trigger::RefreshTrigger, _)).Times(2); EXPECT_CALL(internalScheduler, scheduleCommand(_)); diff --git a/DRAM/testing/WriteChecker_test.cpp b/DRAM/testing/WriteChecker_test.cpp new file mode 100644 index 00000000..2ba76e6c --- /dev/null +++ b/DRAM/testing/WriteChecker_test.cpp @@ -0,0 +1,12 @@ +/* + * WriteChecker_test.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ + +#include + +namespace controller { + +} /* namespace controller */