* @brief initialize the cache * * @param ccache_params some common cache parameters * @param cache_specific_params cache specific parameters, see parse_params * function or use -e "print" with the cachesim binary */
| 72 | * function or use -e "print" with the cachesim binary |
| 73 | */ |
| 74 | cache_t *MClock_init(const common_cache_params_t ccache_params, |
| 75 | const char *cache_specific_params) { |
| 76 | cache_t *cache = cache_struct_init("MClock", ccache_params, cache_specific_params); |
| 77 | cache->cache_init = MClock_init; |
| 78 | cache->cache_free = MClock_free; |
| 79 | cache->get = MClock_get; |
| 80 | cache->find = MClock_find; |
| 81 | cache->insert = MClock_insert; |
| 82 | cache->evict = MClock_evict; |
| 83 | cache->remove = MClock_remove; |
| 84 | cache->to_evict = MClock_to_evict; |
| 85 | cache->get_occupied_byte = MClock_get_occupied_byte; |
| 86 | cache->get_n_obj = MClock_get_n_obj; |
| 87 | cache->can_insert = cache_can_insert_default; |
| 88 | cache->obj_md_size = 0; |
| 89 | |
| 90 | cache->eviction_params = malloc(sizeof(MClock_params_t)); |
| 91 | MClock_params_t *params = (MClock_params_t *)cache->eviction_params; |
| 92 | params->q_head = NULL; |
| 93 | params->q_tail = NULL; |
| 94 | |
| 95 | params->req_local = new_request(); |
| 96 | |
| 97 | // we must parse the default params because the user specified params |
| 98 | // may not have hand-pos and the hand_pos array will not be initialized |
| 99 | MClock_parse_params(cache, DEFAULT_PARAMS); |
| 100 | if (cache_specific_params != NULL) { |
| 101 | MClock_parse_params(cache, cache_specific_params); |
| 102 | } |
| 103 | |
| 104 | snprintf(cache->cache_name, CACHE_NAME_ARRAY_LEN, "MClock-%d-%d", |
| 105 | params->n_hands, params->n_consider_obj); |
| 106 | |
| 107 | return cache; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * free resources used by this cache |
no test coverage detected