diff --git a/dram/src/common/Utils.cpp b/dram/src/common/Utils.cpp index 2b9fd287..c6e6a757 100644 --- a/dram/src/common/Utils.cpp +++ b/dram/src/common/Utils.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "dramExtension.h" using namespace std; using namespace tinyxml2; @@ -139,3 +140,15 @@ string loadTextFileContents(string filename) return ""; } } + +void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank) +{ + payload.set_address(bank.getStartAddress()); + payload.set_command(tlm::TLM_READ_COMMAND); + payload.set_data_length(0); + payload.set_response_status(tlm::TLM_OK_RESPONSE); + payload.set_dmi_allowed(false); + payload.set_byte_enable_length(0); + payload.set_streaming_width(0); + payload.set_extension(new DramExtension(Thread(0), bank, bank.getBankGroup(), Row(0), Column(0))); //payload takes ownership +} diff --git a/dram/src/common/Utils.h b/dram/src/common/Utils.h index 209a54a0..bb0a60cd 100644 --- a/dram/src/common/Utils.h +++ b/dram/src/common/Utils.h @@ -13,7 +13,7 @@ #include #include #include - +#include "dramExtension.h" #include "third_party/tinyxml2.h" template @@ -49,4 +49,6 @@ std::string queryStringParameter(tinyxml2::XMLElement* node, std::string name); bool queryBoolParameter(tinyxml2::XMLElement* node, std::string name); double queryDoubleParameter(tinyxml2::XMLElement* node, std::string name); +void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank); + #endif /* UTILS_COMMON_H_ */ diff --git a/dram/src/core/ControllerState.cpp b/dram/src/core/ControllerState.cpp index c2cb15d0..96234288 100644 --- a/dram/src/core/ControllerState.cpp +++ b/dram/src/core/ControllerState.cpp @@ -7,7 +7,7 @@ #include "ControllerState.h" #include -#include "utils/Utils.h" +#include "TimingCalculation.h" namespace core { diff --git a/dram/src/core/Slots.cpp b/dram/src/core/Slots.cpp index 02079aea..8e1cacc4 100644 --- a/dram/src/core/Slots.cpp +++ b/dram/src/core/Slots.cpp @@ -6,7 +6,7 @@ */ #include "Slots.h" -#include "utils/Utils.h" +#include "TimingCalculation.h" namespace core { diff --git a/dram/src/core/TimingCalculation.cpp b/dram/src/core/TimingCalculation.cpp new file mode 100644 index 00000000..41e1a75e --- /dev/null +++ b/dram/src/core/TimingCalculation.cpp @@ -0,0 +1,117 @@ +/* + * Utils.cpp + * + * Created on: Mar 12, 2014 + * Author: jonny + */ + +#include "TimingCalculation.h" +#include "configuration/TimingConfiguration.h" +#include "ControllerCore.h" +#include "../common/DebugManager.h" +#include "configuration/Configuration.h" +#include "../common/Utils.h" + +namespace core { + + +sc_time getDistance(sc_time a, sc_time b) +{ + if (a > b) + return a - b; + else + return b - a; +} + +sc_time getDelayToMeetConstraint(sc_time previous, sc_time start, sc_time constraint) +{ + if (previous + constraint > start) + return previous + constraint - start; + else + return SC_ZERO_TIME; +} + +const sc_time clkAlign(sc_time time, Alignment alignment) +{ + sc_time clk = Configuration::getInstance().Timings.clk; + if (alignment == UP) + return ceil(time / clk) * clk; + else + return floor(time / clk) * clk; +} + +sc_time getExecutionTime(Command command,tlm::tlm_generic_payload& payload) +{ + TimingConfiguration& config = Configuration::getInstance().Timings; + + if(command == Command::Precharge || command == Command::PrechargeAll) + { + return config.tRP; + } + else if(command == Command::Activate) + { + return config.tRCD; + } + else if(command == Command::Read) + { + return config.tRL + getBurstLengthOnDataStrobe(payload.get_streaming_width()); + } + else if(command == Command::ReadA) + { + return getBurstLengthOnDataStrobe(payload.get_streaming_width()) + + max(config.tRP, config.tRL); + } + else if(command == Command::Write || command == Command::WriteA) + { + sc_time lengthOnDataStrobe = getBurstLengthOnDataStrobe(payload.get_streaming_width()); + if(Configuration::getInstance().DataRate == 1) + lengthOnDataStrobe -= Configuration::getInstance().Timings.clk; + + if (command == Command::Write) + { + return config.tWL + lengthOnDataStrobe; + } + else + { + return config.tWL + lengthOnDataStrobe + config.tWR; + } + } + else if(command == Command::PrechargeAll) + { + return config.tRP; + } + else if(command == Command::AutoRefresh) + { + return getElementFromMap(config.refreshTimings, DramExtension::getExtension(payload).getBank()).tRFC; + } + else + { + SC_REPORT_FATAL("getExecutionTime", "unkown command"); + return SC_ZERO_TIME; + } +} + +bool isClkAligned(sc_time time, sc_time clk) +{ + return !((time / clk) - ceil(time / clk)); +} + +bool TimeInterval::timeIsInInterval(sc_time time) +{ + return (start < time && time < end); +} + +bool TimeInterval::intersects(TimeInterval other) +{ + return other.timeIsInInterval(this->start) || this->timeIsInInterval(other.start); +} + +sc_time getBurstLengthOnDataStrobe(unsigned int burstlength) +{ + Configuration& config = Configuration::getInstance(); + sc_assert((burstlength / config.DataRate) > 0); + + return config.Timings.clk * (burstlength / config.DataRate); +} + +} diff --git a/dram/src/core/utils/Utils.h b/dram/src/core/TimingCalculation.h similarity index 82% rename from dram/src/core/utils/Utils.h rename to dram/src/core/TimingCalculation.h index a153d5da..a6f5bbb3 100644 --- a/dram/src/core/utils/Utils.h +++ b/dram/src/core/TimingCalculation.h @@ -10,11 +10,11 @@ #include #include -#include "../../common/dramExtension.h" +#include "../common/dramExtension.h" +#include "Command.h" namespace core { -unsigned int getStartAddress(const Bank& bank); sc_time getDistance(sc_time a, sc_time b); struct TimeInterval @@ -28,16 +28,14 @@ struct TimeInterval bool intersects(TimeInterval other); }; +sc_time getExecutionTime(Command command, tlm::tlm_generic_payload& payload); sc_time getBurstLengthOnDataStrobe(unsigned int burstlength); - -struct TimingConfiguration; sc_time getDelayToMeetConstraint(sc_time previous, sc_time start, sc_time constraint); enum Alignment {UP, DOWN}; const sc_time clkAlign(sc_time time, Alignment alignment = UP); bool isClkAligned(sc_time time, sc_time clk); -void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank); }; #endif /* UTILS_H_ */ diff --git a/dram/src/core/configuration/TimingConfiguration.h b/dram/src/core/configuration/TimingConfiguration.h index 61ab2571..64c336ed 100644 --- a/dram/src/core/configuration/TimingConfiguration.h +++ b/dram/src/core/configuration/TimingConfiguration.h @@ -9,9 +9,8 @@ #define TIMINGS_H_ #include -#include "../utils/Utils.h" #include - +#include "../../common/dramExtension.h" namespace core{ struct RefreshTiming diff --git a/dram/src/core/powerdown/PowerDownManager.cpp b/dram/src/core/powerdown/PowerDownManager.cpp index 55d343f7..1609f95f 100644 --- a/dram/src/core/powerdown/PowerDownManager.cpp +++ b/dram/src/core/powerdown/PowerDownManager.cpp @@ -8,7 +8,7 @@ #include "PowerDownManager.h" #include "../ControllerCore.h" #include "../../common/Utils.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" using namespace tlm; diff --git a/dram/src/core/powerdown/PowerDownManagerGrouped.cpp b/dram/src/core/powerdown/PowerDownManagerGrouped.cpp index ea232562..db64543d 100644 --- a/dram/src/core/powerdown/PowerDownManagerGrouped.cpp +++ b/dram/src/core/powerdown/PowerDownManagerGrouped.cpp @@ -9,7 +9,7 @@ #include #include "PowerDownManagerGrouped.h" #include "../ControllerCore.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" #include "../../common/DebugManager.h" #include diff --git a/dram/src/core/refresh/RefreshManager.cpp b/dram/src/core/refresh/RefreshManager.cpp index 7e784289..a58e3274 100644 --- a/dram/src/core/refresh/RefreshManager.cpp +++ b/dram/src/core/refresh/RefreshManager.cpp @@ -7,7 +7,8 @@ #include "RefreshManager.h" #include "../ControllerCore.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" +#include "../../common/Utils.h" using namespace tlm; namespace core { diff --git a/dram/src/core/refresh/RefreshManagerBankwise.cpp b/dram/src/core/refresh/RefreshManagerBankwise.cpp index cde123b7..1ec7fbd3 100644 --- a/dram/src/core/refresh/RefreshManagerBankwise.cpp +++ b/dram/src/core/refresh/RefreshManagerBankwise.cpp @@ -7,7 +7,8 @@ #include "RefreshManagerBankwise.h" #include "../ControllerCore.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" +#include "../../common/Utils.h" using namespace std; diff --git a/dram/src/core/scheduling/CommandSequenceScheduler.cpp b/dram/src/core/scheduling/CommandSequenceScheduler.cpp index 825e5c07..fd165a1f 100644 --- a/dram/src/core/scheduling/CommandSequenceScheduler.cpp +++ b/dram/src/core/scheduling/CommandSequenceScheduler.cpp @@ -8,6 +8,7 @@ #include "CommandSequenceScheduler.h" #include "../ControllerCore.h" #include "../../common/DebugManager.h" +#include "../TimingCalculation.h" namespace core { @@ -22,7 +23,7 @@ CommandSchedule CommandSequenceScheduler::schedule(CommandSequence commands, sc_ ICommandChecker& checker = controller.getCommandChecker(cmd); - sc_time executionTime = checker.getExecutionTime(transaction, cmd); + sc_time executionTime = getExecutionTime(cmd,transaction); ScheduledCommand& scheduledCommand = schedule.add(cmd, start, executionTime); checker.delayToSatisfyConstraints(scheduledCommand); diff --git a/dram/src/core/scheduling/ScheduledCommand.cpp b/dram/src/core/scheduling/ScheduledCommand.cpp index f1510b9e..1a78eca4 100644 --- a/dram/src/core/scheduling/ScheduledCommand.cpp +++ b/dram/src/core/scheduling/ScheduledCommand.cpp @@ -5,7 +5,7 @@ * Author: robert */ #include "ScheduledCommand.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" #include "../../common/Utils.h" #include "../configuration/Configuration.h" diff --git a/dram/src/core/scheduling/ScheduledCommand.h b/dram/src/core/scheduling/ScheduledCommand.h index 9141cbe4..44bb4412 100644 --- a/dram/src/core/scheduling/ScheduledCommand.h +++ b/dram/src/core/scheduling/ScheduledCommand.h @@ -13,7 +13,7 @@ #include "../Command.h" #include "../../common/dramExtension.h" #include "../../common/TlmRecorder.h" -#include "../utils/Utils.h" +#include "../TimingCalculation.h" namespace core { diff --git a/dram/src/core/scheduling/checker/ActivateChecker.cpp b/dram/src/core/scheduling/checker/ActivateChecker.cpp index efdd02c2..010852ff 100644 --- a/dram/src/core/scheduling/checker/ActivateChecker.cpp +++ b/dram/src/core/scheduling/checker/ActivateChecker.cpp @@ -8,7 +8,7 @@ #include #include #include "ActivateChecker.h" -#include "../../utils/Utils.h" +#include "../../TimingCalculation.h" #include "../../../common/DebugManager.h" #include "../../Command.h" #include "../../../common/Utils.h" @@ -53,13 +53,6 @@ void ActivateChecker::delayToSatisfyConstraints(ScheduledCommand& command) const } -sc_time ActivateChecker::getExecutionTime(const tlm::tlm_generic_payload& transaction, - Command command) const -{ - assert(command == Command::Activate); - return config.Timings.tRCD; -} - void ActivateChecker::delay_to_satisfy_activateToActivate_sameBank(ScheduledCommand& command) const { ScheduledCommand lastActivateOnBank = state.getLastCommand(Command::Activate, diff --git a/dram/src/core/scheduling/checker/ActivateChecker.h b/dram/src/core/scheduling/checker/ActivateChecker.h index 7888c57e..2a31407c 100644 --- a/dram/src/core/scheduling/checker/ActivateChecker.h +++ b/dram/src/core/scheduling/checker/ActivateChecker.h @@ -22,8 +22,6 @@ public: virtual ~ActivateChecker(){} virtual void delayToSatisfyConstraints(ScheduledCommand& command) const override; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const override; - private: const Configuration& config; ControllerState& state;//TODO make const diff --git a/dram/src/core/scheduling/checker/ICommandChecker.h b/dram/src/core/scheduling/checker/ICommandChecker.h index e9b8cb4c..ae73c5b1 100644 --- a/dram/src/core/scheduling/checker/ICommandChecker.h +++ b/dram/src/core/scheduling/checker/ICommandChecker.h @@ -17,9 +17,7 @@ class ICommandChecker { public: virtual ~ICommandChecker() {} - virtual void delayToSatisfyConstraints(ScheduledCommand& command) const = 0; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const = 0; }; } /* namespace controller */ diff --git a/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp b/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp index 39cf5e97..68cba9ca 100644 --- a/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp +++ b/dram/src/core/scheduling/checker/PrechargeAllChecker.cpp @@ -49,11 +49,4 @@ void PrechargeAllChecker::delayToSatisfyConstraints(ScheduledCommand& command) c state.bus.moveCommandToNextFreeSlot(command); } -sc_time PrechargeAllChecker::getExecutionTime(const tlm::tlm_generic_payload& payload, - Command command) const -{ - sc_assert(command == Command::PrechargeAll); - return config.Timings.tRP; -} - } /* namespace core */ diff --git a/dram/src/core/scheduling/checker/PrechargeAllChecker.h b/dram/src/core/scheduling/checker/PrechargeAllChecker.h index 92a39eec..f536a1a2 100644 --- a/dram/src/core/scheduling/checker/PrechargeAllChecker.h +++ b/dram/src/core/scheduling/checker/PrechargeAllChecker.h @@ -26,8 +26,6 @@ public: } virtual void delayToSatisfyConstraints(ScheduledCommand& command) const override; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const - override; private: const Configuration& config; diff --git a/dram/src/core/scheduling/checker/PrechargeChecker.cpp b/dram/src/core/scheduling/checker/PrechargeChecker.cpp index 85fe737e..56d1e91b 100644 --- a/dram/src/core/scheduling/checker/PrechargeChecker.cpp +++ b/dram/src/core/scheduling/checker/PrechargeChecker.cpp @@ -41,11 +41,4 @@ void PrechargeChecker::delayToSatisfyConstraints(ScheduledCommand& command) cons state.bus.moveCommandToNextFreeSlot(command); } -sc_time PrechargeChecker::getExecutionTime(const tlm::tlm_generic_payload& payload, - Command command) const -{ - sc_assert(command == Command::Precharge || command == Command::PrechargeAll); - return config.Timings.tRP; -} - } /* namespace controller */ diff --git a/dram/src/core/scheduling/checker/PrechargeChecker.h b/dram/src/core/scheduling/checker/PrechargeChecker.h index 81d27817..e93d4b73 100644 --- a/dram/src/core/scheduling/checker/PrechargeChecker.h +++ b/dram/src/core/scheduling/checker/PrechargeChecker.h @@ -19,9 +19,8 @@ class PrechargeChecker: public core::ICommandChecker public: PrechargeChecker(const Configuration& config, ControllerState& state) : config(config), state(state) {} virtual ~PrechargeChecker() {} - virtual void delayToSatisfyConstraints(ScheduledCommand& command) const override; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const override; + private: const Configuration& config; ControllerState& state; diff --git a/dram/src/core/scheduling/checker/ReadChecker.cpp b/dram/src/core/scheduling/checker/ReadChecker.cpp index 7720783e..67675316 100644 --- a/dram/src/core/scheduling/checker/ReadChecker.cpp +++ b/dram/src/core/scheduling/checker/ReadChecker.cpp @@ -6,7 +6,7 @@ */ #include "ReadChecker.h" -#include "../../utils/Utils.h" +#include "../../TimingCalculation.h" #include "../../../common/Utils.h" namespace core { @@ -53,20 +53,6 @@ bool ReadChecker::collidesOnDataStrobe(ScheduledCommand& read) const return false; } -sc_time ReadChecker::getExecutionTime(const tlm::tlm_generic_payload& payload, - Command command) const -{ - if (command == Command::Read) - { - return config.Timings.tRL + getBurstLengthOnDataStrobe(payload.get_streaming_width()); - } - else - { - return getBurstLengthOnDataStrobe(payload.get_streaming_width()) - + max(config.Timings.tRP, config.Timings.tRL); - } -} - bool ReadChecker::collidesWithStrobeCommand(ScheduledCommand& read, ScheduledCommand& strobeCommand) const { diff --git a/dram/src/core/scheduling/checker/ReadChecker.h b/dram/src/core/scheduling/checker/ReadChecker.h index 60c8f514..58af651e 100644 --- a/dram/src/core/scheduling/checker/ReadChecker.h +++ b/dram/src/core/scheduling/checker/ReadChecker.h @@ -21,7 +21,6 @@ public: virtual ~ReadChecker() {} virtual void delayToSatisfyConstraints(ScheduledCommand& command) const override; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const override; private: const Configuration& config; diff --git a/dram/src/core/scheduling/checker/WriteChecker.cpp b/dram/src/core/scheduling/checker/WriteChecker.cpp index b00347aa..a80470c6 100644 --- a/dram/src/core/scheduling/checker/WriteChecker.cpp +++ b/dram/src/core/scheduling/checker/WriteChecker.cpp @@ -6,7 +6,7 @@ */ #include "WriteChecker.h" -#include "../../utils/Utils.h" +#include "../../TimingCalculation.h" #include "../../../common/Utils.h" namespace core { @@ -43,26 +43,6 @@ void WriteChecker::delayToSatisfyConstraints(ScheduledCommand& command) const } } -sc_time WriteChecker::getExecutionTime(const tlm::tlm_generic_payload& payload, - Command command) const -{ - assert(command == Command::Write || command == Command::WriteA); - - sc_time lengthOnDataStrobe = getBurstLengthOnDataStrobe(payload.get_streaming_width()); - if(Configuration::getInstance().DataRate == 1) - lengthOnDataStrobe -= Configuration::getInstance().Timings.clk; - - - if (command == Command::Write) - { - return config.Timings.tWL + lengthOnDataStrobe; - } - else - { - return config.Timings.tWL + lengthOnDataStrobe + config.Timings.tWR; - } -} - bool WriteChecker::collidesOnDataStrobe(ScheduledCommand& write) const { for (ScheduledCommand& strobeCommand : state.lastDataStrobeCommands) diff --git a/dram/src/core/scheduling/checker/WriteChecker.h b/dram/src/core/scheduling/checker/WriteChecker.h index b174bf76..48cc2ed9 100644 --- a/dram/src/core/scheduling/checker/WriteChecker.h +++ b/dram/src/core/scheduling/checker/WriteChecker.h @@ -21,7 +21,6 @@ public: virtual ~WriteChecker() {} virtual void delayToSatisfyConstraints(ScheduledCommand& command) const override; - virtual sc_time getExecutionTime(const tlm::tlm_generic_payload& payload, Command command) const override; private: bool collidesOnDataStrobe(ScheduledCommand& write) const; bool collidesWithStrobeCommand(ScheduledCommand& write, ScheduledCommand& strobeCommand) const; diff --git a/dram/src/core/utils/Utils.cpp b/dram/src/core/utils/Utils.cpp deleted file mode 100644 index 163c2cb7..00000000 --- a/dram/src/core/utils/Utils.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Utils.cpp - * - * Created on: Mar 12, 2014 - * Author: jonny - */ - -#include "Utils.h" -#include "../configuration/TimingConfiguration.h" -#include "../ControllerCore.h" -#include "../../common/DebugManager.h" -#include "../configuration/Configuration.h" - -namespace core { - - -sc_time getDistance(sc_time a, sc_time b) -{ - if (a > b) - return a - b; - else - return b - a; -} - -sc_time getDelayToMeetConstraint(sc_time previous, sc_time start, sc_time constraint) -{ - if (previous + constraint > start) - return previous + constraint - start; - else - return SC_ZERO_TIME; -} - -const sc_time clkAlign(sc_time time, Alignment alignment) -{ - sc_time clk = Configuration::getInstance().Timings.clk; - if (alignment == UP) - return ceil(time / clk) * clk; - else - return floor(time / clk) * clk; -} - -bool isClkAligned(sc_time time, sc_time clk) -{ - return !((time / clk) - ceil(time / clk)); -} - -bool TimeInterval::timeIsInInterval(sc_time time) -{ - return (start < time && time < end); -} - -bool TimeInterval::intersects(TimeInterval other) -{ - return other.timeIsInInterval(this->start) || this->timeIsInInterval(other.start); -} - -sc_time getBurstLengthOnDataStrobe(unsigned int burstlength) -{ - Configuration& config = Configuration::getInstance(); - sc_assert((burstlength / config.DataRate) > 0); - - return config.Timings.clk * (burstlength / config.DataRate); -} - - - -void setUpDummy(tlm::tlm_generic_payload& payload, Bank& bank) -{ - payload.set_address(bank.getStartAddress()); - payload.set_command(tlm::TLM_READ_COMMAND); - payload.set_data_length(0); - payload.set_response_status(tlm::TLM_OK_RESPONSE); - payload.set_dmi_allowed(false); - payload.set_byte_enable_length(0); - payload.set_streaming_width(0); - payload.set_extension(new DramExtension(Thread(0), bank, bank.getBankGroup(), Row(0), Column(0))); //payload takes ownership -} - -} diff --git a/dram/src/simulation/Arbiter.h b/dram/src/simulation/Arbiter.h index 10eb0723..cfc3a4bf 100644 --- a/dram/src/simulation/Arbiter.h +++ b/dram/src/simulation/Arbiter.h @@ -17,7 +17,7 @@ #include #include "../common/xmlAddressdecoder.h" #include "../common/dramExtension.h" -#include "../core/utils/Utils.h" +#include "../core/TimingCalculation.h" #include diff --git a/dram/src/simulation/main.cpp b/dram/src/simulation/main.cpp index 65d05f10..e9adcb64 100644 --- a/dram/src/simulation/main.cpp +++ b/dram/src/simulation/main.cpp @@ -99,7 +99,6 @@ int sc_main(int argc, char **argv) string trace2 = "empty.stl"; string trace1 = "chstone-jpeg_32.stl"; - trace1 = "trace.stl"; if (runSimulation(resources, traceName, setup, { Device(trace1), Device(trace2) })) startTraceAnalyzer(traceName); diff --git a/dram/testing/Utils_test.cpp b/dram/testing/Utils_test.cpp index 070dbbec..6b2ee0d3 100644 --- a/dram/testing/Utils_test.cpp +++ b/dram/testing/Utils_test.cpp @@ -6,7 +6,7 @@ */ #include -#include "core/utils/Utils.h" +#include "core/TimingCalculation.h" #include "core/utils/RingBuffer.h" //using namespace testing;