Skip to content

Commit 4a2627d

Browse files
authored
[Fix]: Tiny possible issues (#283)
* Fix tiny possible issues * Add default param string for consistency
1 parent de81f7b commit 4a2627d

3 files changed

Lines changed: 17 additions & 6 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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ typedef struct LRU_Prob_params {
2525
int threshold;
2626
} LRU_Prob_params_t;
2727

28+
static const char *DEFAULT_CACHE_PARAMS = "prob=0.5";
29+
2830
// ***********************************************************************
2931
// **** ****
3032
// **** function declarations ****
@@ -77,8 +79,10 @@ cache_t *LRU_Prob_init(const common_cache_params_t ccache_params,
7779
cache->eviction_params =
7880
(LRU_Prob_params_t *)malloc(sizeof(LRU_Prob_params_t));
7981
LRU_Prob_params_t *params = (LRU_Prob_params_t *)(cache->eviction_params);
80-
params->prob = 0.5;
82+
params->q_head = NULL;
83+
params->q_tail = NULL;
8184

85+
LRU_Prob_parse_params(cache, DEFAULT_CACHE_PARAMS);
8286
if (cache_specific_params != NULL) {
8387
LRU_Prob_parse_params(cache, cache_specific_params);
8488
}
@@ -169,6 +173,7 @@ static cache_obj_t *LRU_Prob_find(cache_t *cache, const request_t *req,
169173
*/
170174
static cache_obj_t *LRU_Prob_insert(cache_t *cache, const request_t *req) {
171175
LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params;
176+
172177
cache_obj_t *obj = cache_insert_base(cache, req);
173178
prepend_obj_to_head(&params->q_head, &params->q_tail, obj);
174179

@@ -203,6 +208,8 @@ static cache_obj_t *LRU_Prob_to_evict(cache_t *cache, const request_t *req) {
203208
static void LRU_Prob_evict(cache_t *cache, const request_t *req) {
204209
LRU_Prob_params_t *params = (LRU_Prob_params_t *)cache->eviction_params;
205210
cache_obj_t *obj_to_evict = params->q_tail;
211+
DEBUG_ASSERT(params->q_tail != NULL);
212+
206213
remove_obj_from_list(&params->q_head, &params->q_tail, obj_to_evict);
207214
cache_remove_obj_base(cache, obj_to_evict, true);
208215
}

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)