Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dramsim3 multiple reads proper fix #620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions bsg_test/bsg_dramsim3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <cassert>
#include <cstdio>
#include <inttypes.h>
#include <deque>
#define DEBUG

#define __stringify(x) \
#x
Expand Down Expand Up @@ -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<addr_t>()),
_write_done_addr(num_channels_p, std::deque<addr_t>())
{

// construct path to the configuration file
Expand All @@ -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<MemorySystem>(new MemorySystem(config_file, output_dir, read_done, write_done));
Expand Down Expand Up @@ -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();
}
Expand All @@ -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<MemorySystem> _memory_system;
std::vector<uint8_t> _read_done;
std::vector<addr_t> _read_done_addr;
std::vector<uint8_t> _write_done;
std::vector<addr_t> _write_done_addr;
std::unique_ptr<MemorySystem> _memory_system;
std::vector<std::deque<addr_t>> _read_done_addr;
std::vector<std::deque<addr_t>> _write_done_addr;
};


Expand Down