Skip to content

Commit 59df2ae

Browse files
committed
Fix tiny possible issues
1 parent de81f7b commit 59df2ae

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

libCacheSim/cache/eviction/ARC.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ static cache_obj_t *ARC_find(cache_t *cache, const request_t *req,
222222

223223
cache_obj_t *obj = cache_find_base(cache, req, update_cache);
224224

225-
if (!update_cache) {
226-
return obj->ARC.ghost ? NULL : obj;
227-
}
228-
229225
if (obj == NULL) {
230226
return NULL;
231227
}
232228

229+
if (!update_cache) {
230+
return obj->ARC.ghost ? NULL : obj;
231+
}
232+
233233
params->curr_obj_in_L1_ghost = false;
234234
params->curr_obj_in_L2_ghost = false;
235235

libCacheSim/cache/eviction/LRUProb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ cache_t *LRU_Prob_init(const common_cache_params_t ccache_params,
7777
cache->eviction_params =
7878
(LRU_Prob_params_t *)malloc(sizeof(LRU_Prob_params_t));
7979
LRU_Prob_params_t *params = (LRU_Prob_params_t *)(cache->eviction_params);
80+
params->q_head = NULL;
81+
params->q_tail = NULL;
8082
params->prob = 0.5;
8183

8284
if (cache_specific_params != NULL) {
@@ -169,6 +171,7 @@ static cache_obj_t *LRU_Prob_find(cache_t *cache, const request_t *req,
169171
*/
170172
static cache_obj_t *LRU_Prob_insert(cache_t *cache, const request_t *req) {
171173
LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params;
174+
172175
cache_obj_t *obj = cache_insert_base(cache, req);
173176
prepend_obj_to_head(&params->q_head, &params->q_tail, obj);
174177

@@ -203,6 +206,8 @@ static cache_obj_t *LRU_Prob_to_evict(cache_t *cache, const request_t *req) {
203206
static void LRU_Prob_evict(cache_t *cache, const request_t *req) {
204207
LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params;
205208
cache_obj_t *obj_to_evict = params->q_tail;
209+
DEBUG_ASSERT(params->q_tail != NULL);
210+
206211
remove_obj_from_list(&params->q_head, &params->q_tail, obj_to_evict);
207212
cache_remove_obj_base(cache, obj_to_evict, true);
208213
}

libCacheSim/cache/eviction/SR_LRU.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ static cache_obj_t *SR_LRU_find(cache_t *cache, const request_t *req,
208208
params->C_demoted -= 1;
209209
}
210210

211-
if (cache_hit_R || cache_hit_SR) {
211+
if (cache_hit_R || (cache_hit_SR && likely(update_cache))) {
212+
// if not update_cache obj_SR will not be updated to obj_R
212213
DEBUG_ASSERT(obj_R != NULL);
213214
return obj_R;
215+
} else if (cache_hit_SR) {
216+
// if not update_cache, directly return obj_SR
217+
return obj_SR;
214218
}
215219
return NULL;
216220
}

0 commit comments

Comments
 (0)