From 59df2aecc6001ee2dbb77c4957bd601a7fdddaa1 Mon Sep 17 00:00:00 2001 From: Percy Date: Thu, 31 Jul 2025 22:01:48 -0400 Subject: [PATCH 1/2] Fix tiny possible issues --- libCacheSim/cache/eviction/ARC.c | 8 ++++---- libCacheSim/cache/eviction/LRUProb.c | 5 +++++ libCacheSim/cache/eviction/SR_LRU.c | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libCacheSim/cache/eviction/ARC.c b/libCacheSim/cache/eviction/ARC.c index 367d5d631..ad82cfd00 100644 --- a/libCacheSim/cache/eviction/ARC.c +++ b/libCacheSim/cache/eviction/ARC.c @@ -222,14 +222,14 @@ static cache_obj_t *ARC_find(cache_t *cache, const request_t *req, cache_obj_t *obj = cache_find_base(cache, req, update_cache); - if (!update_cache) { - return obj->ARC.ghost ? NULL : obj; - } - if (obj == NULL) { return NULL; } + if (!update_cache) { + return obj->ARC.ghost ? NULL : obj; + } + params->curr_obj_in_L1_ghost = false; params->curr_obj_in_L2_ghost = false; diff --git a/libCacheSim/cache/eviction/LRUProb.c b/libCacheSim/cache/eviction/LRUProb.c index b8ca7bd26..a2476aeaf 100644 --- a/libCacheSim/cache/eviction/LRUProb.c +++ b/libCacheSim/cache/eviction/LRUProb.c @@ -77,6 +77,8 @@ cache_t *LRU_Prob_init(const common_cache_params_t ccache_params, cache->eviction_params = (LRU_Prob_params_t *)malloc(sizeof(LRU_Prob_params_t)); LRU_Prob_params_t *params = (LRU_Prob_params_t *)(cache->eviction_params); + params->q_head = NULL; + params->q_tail = NULL; params->prob = 0.5; if (cache_specific_params != NULL) { @@ -169,6 +171,7 @@ static cache_obj_t *LRU_Prob_find(cache_t *cache, const request_t *req, */ static cache_obj_t *LRU_Prob_insert(cache_t *cache, const request_t *req) { LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params; + cache_obj_t *obj = cache_insert_base(cache, req); prepend_obj_to_head(¶ms->q_head, ¶ms->q_tail, obj); @@ -203,6 +206,8 @@ static cache_obj_t *LRU_Prob_to_evict(cache_t *cache, const request_t *req) { static void LRU_Prob_evict(cache_t *cache, const request_t *req) { LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params; cache_obj_t *obj_to_evict = params->q_tail; + DEBUG_ASSERT(params->q_tail != NULL); + remove_obj_from_list(¶ms->q_head, ¶ms->q_tail, obj_to_evict); cache_remove_obj_base(cache, obj_to_evict, true); } diff --git a/libCacheSim/cache/eviction/SR_LRU.c b/libCacheSim/cache/eviction/SR_LRU.c index 86b9e3d14..700992d64 100644 --- a/libCacheSim/cache/eviction/SR_LRU.c +++ b/libCacheSim/cache/eviction/SR_LRU.c @@ -208,9 +208,13 @@ static cache_obj_t *SR_LRU_find(cache_t *cache, const request_t *req, params->C_demoted -= 1; } - if (cache_hit_R || cache_hit_SR) { + if (cache_hit_R || (cache_hit_SR && likely(update_cache))) { + // if not update_cache obj_SR will not be updated to obj_R DEBUG_ASSERT(obj_R != NULL); return obj_R; + } else if (cache_hit_SR) { + // if not update_cache, directly return obj_SR + return obj_SR; } return NULL; } From 95923798e7f02f783b70b6e60569b3479a63a5b2 Mon Sep 17 00:00:00 2001 From: Percy Date: Thu, 31 Jul 2025 22:22:28 -0400 Subject: [PATCH 2/2] Add default param string for consistency --- libCacheSim/cache/eviction/LRUProb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libCacheSim/cache/eviction/LRUProb.c b/libCacheSim/cache/eviction/LRUProb.c index a2476aeaf..5127f1272 100644 --- a/libCacheSim/cache/eviction/LRUProb.c +++ b/libCacheSim/cache/eviction/LRUProb.c @@ -25,6 +25,8 @@ typedef struct LRU_Prob_params { int threshold; } LRU_Prob_params_t; +static const char *DEFAULT_CACHE_PARAMS = "prob=0.5"; + // *********************************************************************** // **** **** // **** function declarations **** @@ -79,8 +81,8 @@ cache_t *LRU_Prob_init(const common_cache_params_t ccache_params, LRU_Prob_params_t *params = (LRU_Prob_params_t *)(cache->eviction_params); params->q_head = NULL; params->q_tail = NULL; - params->prob = 0.5; + LRU_Prob_parse_params(cache, DEFAULT_CACHE_PARAMS); if (cache_specific_params != NULL) { LRU_Prob_parse_params(cache, cache_specific_params); }