diff --git a/bsg_test/bsg_dramsim3.cpp b/bsg_test/bsg_dramsim3.cpp index dab556edd..7ceac4c4a 100644 --- a/bsg_test/bsg_dramsim3.cpp +++ b/bsg_test/bsg_dramsim3.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#define DEBUG #define __stringify(x) \ #x @@ -36,10 +38,8 @@ class BSGDRAMSim3 { static constexpr bool READ = false; BSGDRAMSim3(int num_channels_p, char *config_p): - _read_done(num_channels_p, 0), - _read_done_addr(num_channels_p, 0), - _write_done(num_channels_p, 0), - _write_done_addr(num_channels_p, 0) + _read_done_addr(num_channels_p, std::deque()), + _write_done_addr(num_channels_p, std::deque()) { // construct path to the configuration file @@ -53,19 +53,14 @@ class BSGDRAMSim3 { auto read_done = [this](uint64_t addr) { int ch = _memory_system->GetConfig()->AddressMapping(addr).channel; pr_dbg("read_done called: ch=%d, addr=0x%010" PRIx64 "\n", ch, addr); - if (_read_done[ch]) { - pr_dbg("WARNING: read done called twice in the same cycle. ch=%d\n", ch); - } - _read_done[ch]++; - _read_done_addr[ch] = addr; + _read_done_addr[ch].push_back(addr); }; /* called when write completes */ auto write_done = [this](uint64_t addr) { int ch = _memory_system->GetConfig()->AddressMapping(addr).channel; pr_dbg("write_done called: ch=%d, addr=0x%010" PRIx64 "\n", ch, addr); - _write_done[ch] = true; - _write_done_addr[ch] = addr; + _write_done_addr[ch].push_back(addr); }; _memory_system = std::unique_ptr(new MemorySystem(config_file, output_dir, read_done, write_done)); @@ -150,8 +145,8 @@ class BSGDRAMSim3 { //////////////// void clockTick() { for (int ch = 0; ch < _memory_system->GetConfig()->channels; ch++) { - if (_read_done[ch] > 0) _read_done[ch]--; - if (_write_done[ch] > 0) _write_done[ch]--; + if (!_read_done_addr[ch].empty()) _read_done_addr[ch].pop_front(); + if (!_write_done_addr[ch].empty()) _write_done_addr[ch].pop_front(); } _memory_system->ClockTick(); } @@ -171,28 +166,26 @@ class BSGDRAMSim3 { // Query completed requests // ////////////////////////////// bool getReadDone(int channel) const { - return _read_done[channel] > 0; + return !_read_done_addr[channel].empty(); } bool getWriteDone(int channel) const { - return _write_done[channel] > 0; + return !_write_done_addr[channel].empty(); } addr_t getReadDoneAddr(int channel) const { - return _read_done_addr[channel]; + return _read_done_addr[channel].front(); } addr_t getWriteDoneAddr(int channel) const { - return _write_done_addr[channel]; + return _write_done_addr[channel].front(); } private: - std::unique_ptr _memory_system; - std::vector _read_done; - std::vector _read_done_addr; - std::vector _write_done; - std::vector _write_done_addr; + std::unique_ptr _memory_system; + std::vector> _read_done_addr; + std::vector> _write_done_addr; };