Skip to content

Commit

Permalink
add init-freq to clock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1a1a11a committed Nov 3, 2024
1 parent 798d54e commit 41e3beb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
41 changes: 18 additions & 23 deletions libCacheSim/cache/eviction/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ 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";

// ***********************************************************************
// **** ****
// **** function declarations ****
// **** ****
// ***********************************************************************

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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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); }

// ***********************************************************************
// **** ****
Expand All @@ -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) {
Expand Down Expand Up @@ -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(&params->q_head, &params->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
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down
5 changes: 3 additions & 2 deletions libCacheSim/include/libCacheSim/evictionAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 41e3beb

Please sign in to comment.