From 7eea92651e3f7c1a60726b3646dc96fe6118c1d7 Mon Sep 17 00:00:00 2001 From: Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> Date: Tue, 11 Mar 2025 15:54:22 -0400 Subject: read has to wait until cache has the right line from memory after eviction, write only has to wait until eviction and does not care about line replacement in cache from memory --- src/storage/cache.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/storage/cache.cc b/src/storage/cache.cc index 08699ed..1224aa9 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -34,7 +34,7 @@ Response Cache::write(Accessor accessor, signed int data, int address) this->requester = accessor; if (this->requester == accessor) { - fetch_resource(address); + fetch_resource(WRITE,address); if (this->is_waiting) r = BLOCKED; else if (this->wait_time == 0) { @@ -58,7 +58,7 @@ Response Cache::write_line(Accessor accessor, std::array this->requester = accessor; if (this->requester == accessor) { - fetch_resource(address); + fetch_resource(WRITE,address); if (this->is_waiting) r = BLOCKED; else if (this->wait_time == 0) { @@ -80,7 +80,7 @@ Response Cache::read(Accessor accessor, int address, std::arrayrequester == IDLE) this->requester = accessor; if (this->requester == accessor) { - fetch_resource(address); + fetch_resource(READ,address); if (this->is_waiting) r = BLOCKED; else if (this->wait_time == 0) { @@ -99,7 +99,7 @@ Response Cache::read_word(Accessor accessor, int address, signed int &data) if (this->requester == IDLE) this->requester = accessor; if (this->requester == accessor) { - fetch_resource(address); + fetch_resource(READ,address); if (this->is_waiting) r = BLOCKED; else if (this->wait_time == 0) { @@ -112,7 +112,7 @@ Response Cache::read_word(Accessor accessor, int address, signed int &data) return r; } -void Cache::fetch_resource(int expected) +void Cache::fetch_resource(Operation op, int expected) { Response r = OK; int tag, index, offset; @@ -131,6 +131,9 @@ void Cache::fetch_resource(int expected) r = this->lower->write_line(L1CACHE, actual, ((index << LINE_SPEC) + (meta->at(0) << (L1_CACHE_SPEC + LINE_SPEC)))); if (r == OK) { meta->at(1) = -1; + if(op == READ){ + r = WAIT; //if operation is read, need to wait until cache is loaded with right value from memory address, if operation is write, then this is not necessary + } } } else { r = this->lower->read(L1CACHE, expected, actual); -- cgit v1.2.3