From 1fb7a9bd5eb41e87871bcbb3423caaabdd8ce1d9 Mon Sep 17 00:00:00 2001 From: bd Date: Fri, 11 Apr 2025 21:22:18 -0400 Subject: First part of storage rework (see description) - Removed response enum. - Removed messy ostream override, and cli.cc test class - Removed accessor enum, and instead used unique pointer to identify accessor. - Simplified storage by removing is_waiting variables. - Rewrote DRAM and Cache to use Storage constructor. --- inc/cache.h | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'inc/cache.h') diff --git a/inc/cache.h b/inc/cache.h index 88fd352..0f15536 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -3,8 +3,8 @@ #include "definitions.h" #include "storage.h" #include -#include #include +#include class Cache : public Storage { @@ -21,55 +21,52 @@ class Cache : public Storage Cache(Storage *lower, int delay); ~Cache(); - Response - write_word(Accessor accessor, signed int data, int address) override; - Response write_line( - Accessor accessor, - std::array data_line, - int address) override; - Response read_line( - Accessor accessor, - int address, - std::array &data_line) override; - Response - read_word(Accessor accessor, int address, signed int &data) override; + int + write_word(void *, signed int, int) override; + int + write_line(void *, std::array, int) override; + int + read_line(void *, int, std::array &) override; + int + read_word(void *, int, signed int &) override; /** * Getter for the meta attribute. * TODO this doesn't seem like good object-oriented practice. * @return this->meta */ - std::array, L1_CACHE_LINES> get_meta() const; + std::array, L1_CACHE_LINES> + get_meta() const; private: /** * Helper for all access methods. - * Calls `request_handler` when `accessor` is allowed to complete its + * Calls `request_handler` when `id` is allowed to complete its * request cycle. * @param the source making the request * @param the address to write to * @param the function to call when an access should be completed */ - Response process( - Accessor accessor, - int address, - std::function request_handler); + int + process(void *id, int address, std::function request_handler); /** - * Returns OK if `accessor` is allowed to complete its request this cycle. - * Handles cache misses, wait times, and setting the current accessor this + * Returns OK if `id` is allowed to complete its request this cycle. + * Handles cache misses, wait times, and setting the current id this * storage is serving. - * @param the accessor asking for a resource - * @return whether or not the access can be carried out this function call. + * @param the id asking for a resource + * @return 1 if the access can be carried out this function call, 0 otherwise. */ - Response is_access_cleared(Accessor accessor, int address); + int + is_access_cleared(void *id, int address); /** - * Helper for access_cleared. + * Helper for is_access_cleared. * Fetches `address` from a lower level of storage if it is not already - * present. If it is not, temporarily sets the is_blocked attribute of this - * cache level to true, and the victim line is chosen/written back. + * present. The victim line is chosen/written back. * @param the address that must be present in cache. + * @param 0 if the address is currently in cache, 1 if it is being fetched. */ - void handle_miss(int address); + int + is_address_missing(int address); /** * An array of metadata about elements in `data`. * If the first value of an element is negative, the corresponding @@ -79,6 +76,4 @@ class Cache : public Storage std::array, L1_CACHE_LINES> meta; }; -std::ostream &operator<<(std::ostream &os, const Cache &c); - #endif /* CACHE_H_INCLUDED */ -- cgit v1.2.3