diff --git a/DRAM/.cproject b/DRAM/.cproject index 0aea2ac1..e0f0123c 100644 --- a/DRAM/.cproject +++ b/DRAM/.cproject @@ -1,18 +1,16 @@ - - - + - + @@ -85,11 +83,11 @@ - + diff --git a/DRAM/.settings/language.settings.xml b/DRAM/.settings/language.settings.xml index 57de1927..80ac5003 100644 --- a/DRAM/.settings/language.settings.xml +++ b/DRAM/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + @@ -14,7 +14,7 @@ - + diff --git a/DRAM/src/core/Controller.cpp b/DRAM/src/core/Controller.cpp index 39a28d3f..6bc90e08 100644 --- a/DRAM/src/core/Controller.cpp +++ b/DRAM/src/core/Controller.cpp @@ -14,10 +14,9 @@ namespace core { -DramController::DramController(IControllerWrapper& wrapper) : - config(), state(config.numberOfBanks), commandSequenceGenerator(state), commandChecker(), commandSequenceScheduler( - commandChecker), refreshManager(config.Timings.refreshTimings[0], bus), bus(config, state, - allCommandChecker, wrapper) +DramController::DramController(IControllerWrapper& wrapper): + config(),state(config.numberOfBanks), commandSequenceGenerator(state), commandChecker(),allCommandChecker(),commandSequenceScheduler( + commandChecker), bus(config, state, allCommandChecker, wrapper), refreshManager(config.Timings.refreshTimings[0], bus) { addCommandChecker(Activate, new ActivateChecker(config, bus)); addCommandChecker(Precharge, new PrechargeChecker(config, bus)); @@ -25,35 +24,44 @@ DramController::DramController(IControllerWrapper& wrapper) : addCommandChecker(Write, new WriteChecker(config, bus)); } + +DramController::~DramController() +{ + for (std::vector::iterator it = allCommandChecker.begin(); it != allCommandChecker.end();++it) + { + delete *it; + } + +} + +void DramController::scheduleRefresh(sc_time time) +{ + refreshManager.scheduleRefresh(time); +} + void DramController::addCommandChecker(Command command, ICommandChecker* checker) { commandChecker[command] = checker; allCommandChecker.push_back(checker); } -DramController::~DramController() -{ - std::map::iterator it = commandChecker.begin(); - while (it != commandChecker.end()) - { - delete it->second; - } - commandChecker.clear(); -} void DramController::schedule(sc_time currentTime, tlm::tlm_generic_payload& externalTransaction) { bus.cleanUpBus(currentTime); - CommandSequence sequence = commandSequenceGenerator.generateCommandSequence(externalTransaction); - CommandSchedule schedule = commandSequenceScheduler.prepareSchedule(currentTime, externalTransaction, sequence); + CommandSequence sequence = commandSequenceGenerator.generateCommandSequence( + externalTransaction); + CommandSchedule schedule = commandSequenceScheduler.prepareSchedule(currentTime, + externalTransaction, sequence); - while(refreshManager.hasCollision(schedule)) + while (refreshManager.hasCollision(schedule)) { refreshManager.scheduleRefresh(currentTime); sequence = commandSequenceGenerator.generateCommandSequence(externalTransaction); - schedule = commandSequenceScheduler.prepareSchedule(currentTime, externalTransaction, sequence); - assert(schedule.getExecutionTime() < config.Timings.refreshTimings[0].tREFI);//TODO make nice + schedule = commandSequenceScheduler.prepareSchedule(currentTime, externalTransaction, + sequence); + assert(schedule.getExecutionTime() < config.Timings.refreshTimings[0].tREFI); //TODO make nice } bus.schedule(schedule); diff --git a/DRAM/src/core/Controller.h b/DRAM/src/core/Controller.h index 8b07ba82..b59fc872 100644 --- a/DRAM/src/core/Controller.h +++ b/DRAM/src/core/Controller.h @@ -25,13 +25,12 @@ class DramController { public: DramController(IControllerWrapper& wrapper); - virtual ~DramController(); + virtual ~DramController() ; void schedule(sc_time currentTime, tlm::tlm_generic_payload& externalTransaction); + void scheduleRefresh(sc_time time); const ICommandChecker& getChecker(Command command) const; - Configuration config; - RefreshManager refreshManager; private: ControllerState state; @@ -41,6 +40,8 @@ private: CommandSequenceScheduler commandSequenceScheduler; //PowerDownManager powerDownManager; CommandBus bus; + RefreshManager refreshManager; + void addCommandChecker(Command command, ICommandChecker* checker); }; diff --git a/DRAM/testing/CommandBus_test.cpp b/DRAM/testing/CommandBus_test.cpp index 24b00035..b7e3a2b6 100644 --- a/DRAM/testing/CommandBus_test.cpp +++ b/DRAM/testing/CommandBus_test.cpp @@ -1,116 +1,125 @@ -///* -// * CommandBus_test.cpp -// * -// * Created on: Mar 13, 2014 -// * Author: jonny -// */ -//#include -//#include -//#include "testUtils.h" -//#include "core/scheduling/ScheduledCommand.h" -//#include "core/Configuration.h" -//#include "core/ControllerState.h" -//#include "core/CommandBus.h" -// -//using ::testing::_; -//using ::testing::AtLeast; -//using ::testing::Expectation; -//using namespace testing; -//using namespace std; -// -//namespace core { -// -//class CommandBusTest: public Test -//{ -//public: -// CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state, checker), clk(config.Timings.clk){} -// -// Configuration config; -// ControllerState state; -// CommandBus bus; -// -// std::vector checker; -// sc_time clk; -//}; -// -//TEST_F(CommandBusTest, cleanUpBusWorks) -//{ -// shared_ptr dummy = createDummyPayload(); -// ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); -// ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); -// ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); -// ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); -// -// bus.scheduleCommand(cmd1); -// bus.scheduleCommand(cmd2); -// bus.scheduleCommand(cmd3); -// bus.scheduleCommand(cmd4); -// -// EXPECT_EQ(4, bus.getPendingBusCommands().size()); -// -// bus.cleanUpBus(5*clk); -// -// EXPECT_EQ(2, bus.getPendingBusCommands().size()); -//} -// -// -//TEST_F(CommandBusTest, getEarliestStartTimeWorks) -//{ -// shared_ptr dummy = createDummyPayload(); -// ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); -// ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); -// ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); -// ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); -// -// ScheduledCommand collision(*dummy.get(), Read, 3*clk, clk); -// ScheduledCommand noCollision(*dummy.get(), Read, 6*clk, clk); -// -// bus.scheduleCommand(cmd1); -// bus.scheduleCommand(cmd2); -// bus.scheduleCommand(cmd3); -// bus.scheduleCommand(cmd4); -// -// EXPECT_EQ(4*clk, bus.getEarliestStartTime(collision)); -// EXPECT_EQ(6*clk, bus.getEarliestStartTime(noCollision)); -//} -// -// -//TEST_F(CommandBusTest, getESTDiesWithNotClkAligned) -//{ -// shared_ptr dummy = createDummyPayload(); -// ScheduledCommand notAligned(*dummy.get(), Read, 2.5*clk, clk); -// -// EXPECT_DEATH(bus.getEarliestStartTime(notAligned), ".*"); -//} -// -//TEST_F(CommandBusTest, getLastCommandWorks) -//{ -// shared_ptr dummy0 = createDummyPayload(Thread(0), Bank(0)); -// shared_ptr dummy2 = createDummyPayload(Thread(0), Bank(2)); -// -// ScheduledCommand read0(*dummy0.get(), Read, 2*clk, clk); -// ScheduledCommand read2(*dummy2.get(), Read, 3*clk, clk); -// bus.scheduleCommand(read0); -// bus.scheduleCommand(read2); -// -// EXPECT_EQ(read0, bus.getLastCommand(Read, read0.getBank())); -// EXPECT_EQ(read2, bus.getLastCommand(Read, read2.getBank())); -// EXPECT_EQ(read2.getStart(), bus.getLastCommand(Read).getStart()); -//} -// -//TEST_F(CommandBusTest, notYetScheduledWorks) -//{ -// shared_ptr dummy = createDummyPayload(Thread(0), Bank(0)); -// ScheduledCommand read(*dummy.get(), Read, 2*clk, clk); -// -// EXPECT_TRUE(bus.notYetScheduled(Read)); -// bus.scheduleCommand(read); -// EXPECT_FALSE(bus.notYetScheduled(Read)); -//} -// -// -//} /* namespace controller */ -// -// -// -// +/* + * CommandBus_test.cpp + * + * Created on: Mar 13, 2014 + * Author: jonny + */ +#include +#include +#include "testUtils.h" +#include "core/scheduling/ScheduledCommand.h" +#include "core/Configuration.h" +#include "core/ControllerState.h" +#include "core/CommandBus.h" + +using ::testing::_; +using ::testing::AtLeast; +using ::testing::Expectation; +using namespace testing; +using namespace std; + +namespace core { + +class MockWrapper: public IControllerWrapper +{ +public: + MOCK_METHOD3(sendCommand, void (sc_time time, tlm::tlm_generic_payload& payload, Command command)); + MOCK_METHOD2(sendTrigger, void (sc_time time, Trigger trigger)); +}; + + +class CommandBusTest: public Test +{ +public: + CommandBusTest() : config(), state(config.numberOfBanks), bus(config, state, checker, mockControllerWrapper), clk(config.Timings.clk){} + + Configuration config; + ControllerState state; + MockWrapper mockControllerWrapper; + CommandBus bus; + + std::vector checker; + sc_time clk; +}; + +TEST_F(CommandBusTest, cleanUpBusWorks) +{ + shared_ptr dummy = createDummyPayload(); + ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); + ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); + ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); + ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); + + bus.scheduleCommand(cmd1); + bus.scheduleCommand(cmd2); + bus.scheduleCommand(cmd3); + bus.scheduleCommand(cmd4); + + EXPECT_EQ(4, bus.getPendingBusCommands().size()); + + bus.cleanUpBus(5*clk); + + EXPECT_EQ(2, bus.getPendingBusCommands().size()); +} + + +TEST_F(CommandBusTest, getEarliestStartTimeWorks) +{ + shared_ptr dummy = createDummyPayload(); + ScheduledCommand cmd1(*dummy.get(), Read, 2*clk, clk); + ScheduledCommand cmd2(*dummy.get(), Read, 3*clk, clk); + ScheduledCommand cmd3(*dummy.get(), Read, 5*clk, clk); + ScheduledCommand cmd4(*dummy.get(), Read, 7*clk, clk); + + ScheduledCommand collision(*dummy.get(), Read, 3*clk, clk); + ScheduledCommand noCollision(*dummy.get(), Read, 6*clk, clk); + + bus.scheduleCommand(cmd1); + bus.scheduleCommand(cmd2); + bus.scheduleCommand(cmd3); + bus.scheduleCommand(cmd4); + + EXPECT_EQ(4*clk, bus.getEarliestStartTime(collision)); + EXPECT_EQ(6*clk, bus.getEarliestStartTime(noCollision)); +} + + +TEST_F(CommandBusTest, getESTDiesWithNotClkAligned) +{ + shared_ptr dummy = createDummyPayload(); + ScheduledCommand notAligned(*dummy.get(), Read, 2.5*clk, clk); + + EXPECT_DEATH(bus.getEarliestStartTime(notAligned), ".*"); +} + +TEST_F(CommandBusTest, getLastCommandWorks) +{ + shared_ptr dummy0 = createDummyPayload(Thread(0), Bank(0)); + shared_ptr dummy2 = createDummyPayload(Thread(0), Bank(2)); + + ScheduledCommand read0(*dummy0.get(), Read, 2*clk, clk); + ScheduledCommand read2(*dummy2.get(), Read, 3*clk, clk); + bus.scheduleCommand(read0); + bus.scheduleCommand(read2); + + EXPECT_EQ(read0, bus.getLastCommand(Read, read0.getBank())); + EXPECT_EQ(read2, bus.getLastCommand(Read, read2.getBank())); + EXPECT_EQ(read2.getStart(), bus.getLastCommand(Read).getStart()); +} + +TEST_F(CommandBusTest, notYetScheduledWorks) +{ + shared_ptr dummy = createDummyPayload(Thread(0), Bank(0)); + ScheduledCommand read(*dummy.get(), Read, 2*clk, clk); + + EXPECT_TRUE(bus.notYetScheduled(Read)); + bus.scheduleCommand(read); + EXPECT_FALSE(bus.notYetScheduled(Read)); +} + + +} /* namespace controller */ + + + +