Skip to content

Commit

Permalink
node058:fix clock and batch
Browse files Browse the repository at this point in the history
  • Loading branch information
bobob committed Aug 17, 2024
1 parent 7c19534 commit c050377
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion libCacheSim/cache/eviction/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ 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) {
Clock_params_t *params = (Clock_params_t *)cache->eviction_params;
params->vtime += 1;
cache_obj_t *obj = cache_find_base(cache, req, update_cache);
if (obj != NULL && update_cache) {
if (obj->clock.freq < params->max_freq) {
obj->clock.freq += 1;
}
obj->clock.next_access_vtime = req->next_access_vtime;
#ifdef USE_BELADY
obj->next_access_vtime = req->next_access_vtime;
#endif
Expand All @@ -170,8 +172,10 @@ static cache_obj_t *Clock_find(cache_t *cache, const request_t *req,
*/
static cache_obj_t *Clock_insert(cache_t *cache, const request_t *req) {
Clock_params_t *params = (Clock_params_t *)cache->eviction_params;
params ->miss += 1;

cache_obj_t *obj = cache_insert_base(cache, req);
obj->clock.next_access_vtime = req->next_access_vtime;
prepend_obj_to_head(&params->q_head, &params->q_tail, obj);

obj->clock.freq = 0;
Expand Down Expand Up @@ -223,15 +227,21 @@ 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) {
Clock_params_t *params = (Clock_params_t *)cache->eviction_params;
double miss_ratio;
miss_ratio = (double)params->miss / (double)params->vtime;
double expected_reuse_distance = (double)cache -> cache_size / miss_ratio;

cache_obj_t *obj_to_evict = params->q_tail;
while (obj_to_evict->clock.freq >= 1) {
int64_t reuse_distance = obj_to_evict->clock.next_access_vtime - params->vtime;
while (reuse_distance != INT64_MAX && reuse_distance <= expected_reuse_distance && obj_to_evict->clock.check_time != params->vtime) {
obj_to_evict->clock.freq -= 1;
params->n_obj_rewritten += 1;
params->n_byte_rewritten += obj_to_evict->obj_size;
move_obj_to_head(&params->q_head, &params->q_tail, obj_to_evict);
cache->n_promotion += 1;
obj_to_evict->clock.check_time = params->vtime;
obj_to_evict = params->q_tail;
reuse_distance = obj_to_evict->clock.next_access_vtime - params->vtime;
}

remove_obj_from_list(&params->q_head, &params->q_tail, obj_to_evict);
Expand Down
9 changes: 5 additions & 4 deletions libCacheSim/cache/eviction/lpFIFO_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ static void lpFIFO_batch_promote_all(cache_t *cache, const request_t *req, uint6
// create an empty hash table because we don't want the duplicate objects
// to be promoted
hashtable_t *duplicate_table = create_hashtable(8);

for (int i = 0; i < count; i++) {
obj_to_promote = buff[pos % params->buffer_size];
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_to_promote);
if (obj != NULL && hashtable_find_obj_id(duplicate_table, obj_to_promote) == NULL) {
hashtable_f_insert_obj(duplicate_table, obj);
if (obj != NULL) {
move_obj_to_head(&params->q_head, &params->q_tail, obj);
cache -> n_promotion += 1;
if (hashtable_find_obj_id(duplicate_table, obj_to_promote) == NULL){
hashtable_f_insert_obj(duplicate_table, obj);
cache -> n_promotion += 1;
}
}
pos += 1;
}
Expand Down

0 comments on commit c050377

Please sign in to comment.