MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / cache_struct_init

Function cache_struct_init

libCacheSim/cache/cache.c:28–69  ·  view source on GitHub ↗

* @brief this function is called by all eviction algorithms to initialize the * cache * * @param ccache_params common cache parameters * @param init_params eviction algorithm specific parameters * @return cache_t* pointer to the cache */

Source from the content-addressed store, hash-verified

26 * @return cache_t* pointer to the cache
27 */
28cache_t *cache_struct_init(const char *const cache_name, const common_cache_params_t params,
29 const void *const init_params) {
30 cache_t *cache = my_malloc(cache_t);
31 memset(cache, 0, sizeof(cache_t));
32 strncpy(cache->cache_name, cache_name, CACHE_NAME_ARRAY_LEN-1);
33 cache->cache_name[CACHE_NAME_ARRAY_LEN-1] = '\0';
34 if (init_params != NULL) {
35 strncpy(cache->init_params, init_params, CACHE_INIT_PARAMS_LEN-1);
36 cache->init_params[CACHE_INIT_PARAMS_LEN-1] = '\0';
37 }
38 cache->cache_size = params.cache_size;
39 cache->eviction_params = NULL;
40 cache->admissioner = NULL;
41 cache->prefetcher = NULL;
42 cache->future_stack_dist = NULL;
43 cache->future_stack_dist_array_size = 0;
44 cache->default_ttl = params.default_ttl;
45 cache->n_req = 0;
46 cache->to_evict_candidate = NULL;
47 cache->to_evict_candidate_gen_vtime = -1;
48
49 cache->can_insert = cache_can_insert_default;
50 cache->get_occupied_byte = cache_get_occupied_byte_default;
51 cache->get_n_obj = cache_get_n_obj_default;
52
53 /* this option works only when eviction age tracking
54 * is on in config.h */
55#if defined(TRACK_EVICTION_V_AGE)
56 cache->track_eviction_age = true;
57#endif
58#if defined(TRACK_DEMOTION)
59 cache->track_demotion = true;
60#endif
61
62 int hash_power = HASH_POWER_DEFAULT;
63 if (params.hashpower > 0 && params.hashpower < 40) hash_power = params.hashpower;
64 cache->hashtable = create_hashtable(hash_power);
65 hashtable_add_ptr_to_monitoring(cache->hashtable, &cache->q_head);
66 hashtable_add_ptr_to_monitoring(cache->hashtable, &cache->q_tail);
67
68 return cache;
69}
70
71/**
72 * @brief this function is called by all eviction algorithms to free the cache

Callers 15

ARCv0_initFunction · 0.85
LeCaRv0_initFunction · 0.85
LRU_Prob_initFunction · 0.85
nop_initFunction · 0.85
Clock_initFunction · 0.85
FIFO_initFunction · 0.85
S3FIFO_initFunction · 0.85
LRUv0_initFunction · 0.85
S3FIFOd_initFunction · 0.85
RandomLRU_initFunction · 0.85
QDLP_initFunction · 0.85
LIRS_initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected