From 41e3beb440f241c2eaf04c547d75a0f35caa6d49 Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 3 Nov 2024 16:05:25 -0500 Subject: [PATCH] add init-freq to clock This allow us to simulate RRIP by setting the frequency of newly inserted object to be a value larger than 0. Current results show that n-bit-counter=2, init-freq=0 reduces miss ratio on most workloads, however, when init-freq=1, it increases miss ratio compared to n-bit-counter=1. --- libCacheSim/cache/eviction/Clock.c | 41 ++++++++----------- .../include/libCacheSim/evictionAlgo.h | 5 ++- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/libCacheSim/cache/eviction/Clock.c b/libCacheSim/cache/eviction/Clock.c index 6c68effa..1ce15624 100644 --- a/libCacheSim/cache/eviction/Clock.c +++ b/libCacheSim/cache/eviction/Clock.c @@ -20,7 +20,7 @@ extern "C" { // #define USE_BELADY #undef USE_BELADY -static const char *DEFAULT_PARAMS = "n-bit-counter=1"; +static const char *DEFAULT_PARAMS = "init-freq=0,n-bit-counter=1"; // *********************************************************************** // **** **** @@ -28,12 +28,10 @@ static const char *DEFAULT_PARAMS = "n-bit-counter=1"; // **** **** // *********************************************************************** -static void Clock_parse_params(cache_t *cache, - const char *cache_specific_params); +static void Clock_parse_params(cache_t *cache, const char *cache_specific_params); static void Clock_free(cache_t *cache); static bool Clock_get(cache_t *cache, const request_t *req); -static cache_obj_t *Clock_find(cache_t *cache, const request_t *req, - const bool update_cache); +static cache_obj_t *Clock_find(cache_t *cache, const request_t *req, const bool update_cache); static cache_obj_t *Clock_insert(cache_t *cache, const request_t *req); static cache_obj_t *Clock_to_evict(cache_t *cache, const request_t *req); static void Clock_evict(cache_t *cache, const request_t *req); @@ -51,10 +49,8 @@ static bool Clock_remove(cache_t *cache, const obj_id_t obj_id); * @param ccache_params some common cache parameters * @param cache_specific_params Clock specific parameters as a string */ -cache_t *Clock_init(const common_cache_params_t ccache_params, - const char *cache_specific_params) { - cache_t *cache = - cache_struct_init("Clock", ccache_params, cache_specific_params); +cache_t *Clock_init(const common_cache_params_t ccache_params, const char *cache_specific_params) { + cache_t *cache = cache_struct_init("Clock", ccache_params, cache_specific_params); cache->cache_init = Clock_init; cache->cache_free = Clock_free; cache->get = Clock_get; @@ -86,8 +82,7 @@ cache_t *Clock_init(const common_cache_params_t ccache_params, } if (params->n_bit_counter != 1) { - snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "Clock-%d", - params->n_bit_counter); + snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "Clock-%d-%d", params->n_bit_counter, params->init_freq); } return cache; @@ -122,9 +117,7 @@ static void Clock_free(cache_t *cache) { * @param req * @return true if cache hit, false if cache miss */ -static bool Clock_get(cache_t *cache, const request_t *req) { - return cache_get_base(cache, req); -} +static bool Clock_get(cache_t *cache, const request_t *req) { return cache_get_base(cache, req); } // *********************************************************************** // **** **** @@ -142,8 +135,7 @@ static bool Clock_get(cache_t *cache, const request_t *req) { * and if the object is expired, it is removed from the cache * @return true on hit, false on miss */ -static cache_obj_t *Clock_find(cache_t *cache, const request_t *req, - const bool update_cache) { +static cache_obj_t *Clock_find(cache_t *cache, const request_t *req, const bool update_cache) { Clock_params_t *params = (Clock_params_t *)cache->eviction_params; cache_obj_t *obj = cache_find_base(cache, req, update_cache); if (obj != NULL && update_cache) { @@ -174,7 +166,7 @@ static cache_obj_t *Clock_insert(cache_t *cache, const request_t *req) { cache_obj_t *obj = cache_insert_base(cache, req); prepend_obj_to_head(¶ms->q_head, ¶ms->q_tail, obj); - obj->clock.freq = 0; + obj->clock.freq = params->init_freq; #ifdef USE_BELADY obj->next_access_vtime = req->next_access_vtime; #endif @@ -289,16 +281,14 @@ static bool Clock_remove(cache_t *cache, const obj_id_t obj_id) { // **** parameter set up functions **** // **** **** // *********************************************************************** -static const char *Clock_current_params(cache_t *cache, - Clock_params_t *params) { +static const char *Clock_current_params(cache_t *cache, Clock_params_t *params) { static __thread char params_str[128]; snprintf(params_str, 128, "n-bit-counter=%d\n", params->n_bit_counter); return params_str; } -static void Clock_parse_params(cache_t *cache, - const char *cache_specific_params) { +static void Clock_parse_params(cache_t *cache, const char *cache_specific_params) { Clock_params_t *params = (Clock_params_t *)cache->eviction_params; char *params_str = strdup(cache_specific_params); char *old_params_str = params_str; @@ -321,12 +311,17 @@ static void Clock_parse_params(cache_t *cache, if (strlen(end) > 2) { ERROR("param parsing error, find string \"%s\" after number\n", end); } + } else if (strcasecmp(key, "init-freq") == 0) { + params->init_freq = (int)strtol(value, &end, 0); + if (strlen(end) > 2) { + ERROR("param parsing error, find string \"%s\" after number\n", end); + } } else if (strcasecmp(key, "print") == 0) { printf("current parameters: %s\n", Clock_current_params(cache, params)); exit(0); } else { - ERROR("%s does not have parameter %s, example parameters %s\n", - cache->cache_name, key, Clock_current_params(cache, params)); + ERROR("%s does not have parameter %s, example parameters %s\n", cache->cache_name, key, + Clock_current_params(cache, params)); exit(1); } } diff --git a/libCacheSim/include/libCacheSim/evictionAlgo.h b/libCacheSim/include/libCacheSim/evictionAlgo.h index 7eb6b9f2..bb35c91a 100644 --- a/libCacheSim/include/libCacheSim/evictionAlgo.h +++ b/libCacheSim/include/libCacheSim/evictionAlgo.h @@ -29,9 +29,10 @@ typedef struct { cache_obj_t *q_head; cache_obj_t *q_tail; // clock uses one-bit counter - int n_bit_counter; + int32_t n_bit_counter; // max_freq = 1 << (n_bit_counter - 1) - int max_freq; + int32_t max_freq; + int32_t init_freq; int64_t n_obj_rewritten; int64_t n_byte_rewritten;