diff options
author | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-03-11 15:54:22 -0400 |
---|---|---|
committer | Siddarth-Suresh <65844402+Siddarth-Suresh@users.noreply.github.com> | 2025-03-11 15:54:22 -0400 |
commit | 7eea92651e3f7c1a60726b3646dc96fe6118c1d7 (patch) | |
tree | 16b169816c5475ab07bc0c2df2ebd50b6884acc8 | |
parent | 21187ae663a8450553881851e8450315c8d9ca1c (diff) |
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
-rw-r--r-- | inc/cache.h | 3 | ||||
-rw-r--r-- | inc/operation.h | 9 | ||||
-rw-r--r-- | src/storage/cache.cc | 13 |
3 files changed, 19 insertions, 6 deletions
diff --git a/inc/cache.h b/inc/cache.h index 20a40c2..7a1a380 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -1,6 +1,7 @@ #ifndef CACHE_H #define CACHE_H #include "definitions.h" +#include "operation.h" #include "storage.h" #include <array> #include <ostream> @@ -42,7 +43,7 @@ class Cache : public Storage * cache level to true, and the victim line is chosen/written back. * @param the address that must be present in cache. */ - void fetch_resource(int address); + void fetch_resource(Operation op, int address); /** * An array of metadata about elements in `data`. * If the first value of an element is negative, the corresponding diff --git a/inc/operation.h b/inc/operation.h new file mode 100644 index 0000000..a35344e --- /dev/null +++ b/inc/operation.h @@ -0,0 +1,9 @@ +#ifndef OPERATION_H +#define OPERATION_H + +enum Operation { + READ, + WRITE +}; + +#endif /* OPERATION_H_INCLUDED */
\ No newline at end of file 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<signed int, LINE_SIZE> 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::array<signed int, LINE 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) { @@ -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); |