Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/advanced_lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ cache_t *LRU_init(const common_cache_params_t ccache_params,
void LRU_free(cache_t *cache);
bool LRU_get(cache_t *cache, const request_t *req);
cache_obj_t *LRU_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
cache_obj_t *LRU_insert(cache_t *cache, const request_t *req);
cache_obj_t *LRU_to_evict(cache_t *cache, const request_t *req);
void LRU_evict(cache_t *cache, const request_t *req);
bool LRU_remove(cache_t *cache, const obj_id_t obj_id);
bool LRU_remove(cache_t *cache, obj_id_t obj_id);
```

#### Create Cache
Expand Down
4 changes: 2 additions & 2 deletions doc/advanced_lib_extend.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void LRU_free(cache_t *cache);
bool LRU_get(cache_t *cache, const request_t *req);

/* find an object in the cache, return the cache object if found, NULL otherwise, update_cache means whether update the cache state, e.g., moving object to the head of the queue */
cache_obj_t *LRU_find(cache_t *cache, const request_t *req, const bool update_cache);
cache_obj_t *LRU_find(cache_t *cache, const request_t *req, bool update_cache);

/* insert an object to the cache, return the cache object, this assumes the object is not in the cache */
cache_obj_t *LRU_insert(cache_t *cache, const request_t *req);
Expand All @@ -27,7 +27,7 @@ cache_obj_t *LRU_to_evict(cache_t *cache, const request_t *req);
void LRU_evict(cache_t *cache, const request_t *req);

/* remove an object from the cache, return true if the object is found and removed, note that this is used for user-triggered remove, eviction should use evict */
bool LRU_remove(cache_t *cache, const obj_id_t obj_id);
bool LRU_remove(cache_t *cache, obj_id_t obj_id);
```

Specifically, you can following the steps:
Expand Down
4 changes: 2 additions & 2 deletions doc/quickstart_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Your library **must** export the following C-symbols:
| `cache_hit_hook` | `void cache_hit_hook(void *data, const request_t *req);` | A requested object is found in the cache. |
| `cache_miss_hook` | `void cache_miss_hook(void *data, const request_t *req);` | A requested object is **not** in the cache *after* insertion. |
| `cache_eviction_hook` | `obj_id_t cache_eviction_hook(void *data, const request_t *req);` | Cache is full – must return the object-ID to evict. |
| `cache_remove_hook` | `void cache_remove_hook(void *data, const obj_id_t obj_id);` | An object is explicitly removed (not necessarily due to eviction). |
| `cache_remove_hook` | `void cache_remove_hook(void *data, obj_id_t obj_id);` | An object is explicitly removed (not necessarily due to eviction). |

The opaque pointer returned by `cache_init_hook` is passed back to every other hook via the `data` parameter, letting your plugin maintain arbitrary state (linked lists, hash maps, statistics, …). For memory safety, your library can export `cache_free_hook` (`void cache_free_hook(void *data);`) to free the resources used by your cache struct according to your demands.

Expand Down Expand Up @@ -100,7 +100,7 @@ obj_id_t cache_eviction_hook(void *data, const request_t * /*req*/) {
return static_cast<MyPolicy *>(data)->evict();
}

void cache_remove_hook(void *data, const obj_id_t obj_id) {
void cache_remove_hook(void *data, obj_id_t obj_id) {
static_cast<MyPolicy *>(data)->on_remove(obj_id);
}
} // extern "C"
Expand Down
4 changes: 2 additions & 2 deletions example/plugin_v1/plugin_lru.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static bool plugin_lru_get(cache_t *cache, const request_t *req) {
* @return the cache object if found, NULL otherwise
*/
static cache_obj_t *plugin_lru_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
plugin_lru_params_t *params = (plugin_lru_params_t *)cache->eviction_params;
cache_obj_t *cache_obj = cache_find_base(cache, req, update_cache);

Expand Down Expand Up @@ -228,7 +228,7 @@ static void plugin_lru_remove_obj(cache_t *cache, cache_obj_t *obj) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool plugin_lru_remove(cache_t *cache, const obj_id_t obj_id) {
static bool plugin_lru_remove(cache_t *cache, obj_id_t obj_id) {
request_t req = {.obj_id = obj_id, .obj_size = 0};
cache_obj_t *obj = cache_find_base(cache, &req, false);

Expand Down
2 changes: 1 addition & 1 deletion example/plugin_v2/plugin_lru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ obj_id_t cache_eviction_hook(void *data, const request_t *req) {
}

// implement the cache remove hook
void cache_remove_hook(void *data, const obj_id_t obj_id) {
void cache_remove_hook(void *data, obj_id_t obj_id) {
// remove object from the cache
StandaloneLRU *lru_cache = (StandaloneLRU *)data;
lru_cache->cache_remove(obj_id);
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ bool cache_can_insert_default(cache_t *cache, const request_t *req) {
* @return the found cache_obj_t* or NULL if not found
*/
cache_obj_t *cache_find_base(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
cache_obj_t *cache_obj = hashtable_find(cache->hashtable, req);

// "update_cache = true" means that it is a real user request, use handle_find
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ static void ThreeLCache_free(cache_t *cache);
static bool ThreeLCache_get(cache_t *cache, const request_t *req);

static cache_obj_t *ThreeLCache_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *ThreeLCache_insert(cache_t *cache, const request_t *req);
static cache_obj_t *ThreeLCache_to_evict(cache_t *cache, const request_t *req);
static void ThreeLCache_evict(cache_t *cache, const request_t *req);
static bool ThreeLCache_remove(cache_t *cache, const obj_id_t obj_id);
static bool ThreeLCache_remove(cache_t *cache, obj_id_t obj_id);
static int64_t ThreeLCache_get_occupied_byte(const cache_t *cache);
static int64_t ThreeLCache_get_n_obj(const cache_t *cache);

Expand Down Expand Up @@ -181,7 +181,7 @@ static bool ThreeLCache_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *ThreeLCache_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
auto *params = static_cast<ThreeLCache_params_t *>(cache->eviction_params);
auto *ThreeLCache =
static_cast<ThreeLCache::ThreeLCacheCache *>(params->ThreeLCache_cache);
Expand Down Expand Up @@ -288,7 +288,7 @@ static void ThreeLCache_evict(cache_t *cache, const request_t *req) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool ThreeLCache_remove(cache_t *cache, const obj_id_t obj_id) {
static bool ThreeLCache_remove(cache_t *cache, obj_id_t obj_id) {
auto *params = static_cast<ThreeLCache_params_t *>(cache->eviction_params);
auto *ThreeLCache =
static_cast<ThreeLCache::ThreeLCacheCache *>(params->ThreeLCache_cache);
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/ARC.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ static void ARC_parse_params(cache_t *cache, const char *cache_specific_params);
static void ARC_free(cache_t *cache);
static bool ARC_get(cache_t *cache, const request_t *req);
static cache_obj_t *ARC_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *ARC_insert(cache_t *cache, const request_t *req);
static cache_obj_t *ARC_to_evict(cache_t *cache, const request_t *req);
static void ARC_evict(cache_t *cache, const request_t *req);
static bool ARC_remove(cache_t *cache, const obj_id_t obj_id);
static bool ARC_remove(cache_t *cache, obj_id_t obj_id);

/* internal functions */
/* this is the case IV in the paper */
Expand Down Expand Up @@ -217,7 +217,7 @@ static bool ARC_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *ARC_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
ARC_params_t *params = (ARC_params_t *)(cache->eviction_params);

cache_obj_t *obj = cache_find_base(cache, req, update_cache);
Expand Down Expand Up @@ -384,7 +384,7 @@ static void ARC_evict(cache_t *cache, const request_t *req) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool ARC_remove(cache_t *cache, const obj_id_t obj_id) {
static bool ARC_remove(cache_t *cache, obj_id_t obj_id) {
ARC_params_t *params = (ARC_params_t *)(cache->eviction_params);
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);

Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/ARCv0.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ static void ARCv0_parse_params(cache_t *cache,
static void ARCv0_free(cache_t *cache);
static bool ARCv0_get(cache_t *cache, const request_t *req);
static cache_obj_t *ARCv0_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *ARCv0_insert(cache_t *cache, const request_t *req);
static cache_obj_t *ARCv0_to_evict(cache_t *cache, const request_t *req);
static void ARCv0_evict(cache_t *cache, const request_t *req);
static bool ARCv0_remove(cache_t *cache, const obj_id_t obj_id);
static bool ARCv0_remove(cache_t *cache, obj_id_t obj_id);
static int64_t ARCv0_get_occupied_byte(const cache_t *cache);
static int64_t ARCv0_get_n_obj(const cache_t *cache);

Expand Down Expand Up @@ -204,7 +204,7 @@ static bool ARCv0_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *ARCv0_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
ARCv0_params_t *params = (ARCv0_params_t *)(cache->eviction_params);

cache_obj_t *obj_t1 = params->T1->find(params->T1, req, false);
Expand Down Expand Up @@ -358,7 +358,7 @@ static void ARCv0_evict(cache_t *cache, const request_t *req) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool ARCv0_remove(cache_t *cache, const obj_id_t obj_id) {
static bool ARCv0_remove(cache_t *cache, obj_id_t obj_id) {
ARCv0_params_t *params = (ARCv0_params_t *)(cache->eviction_params);
bool removed = false;
removed |= params->T1->remove(params->T1, obj_id);
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/Belady.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ typedef struct Belady_params {
static void Belady_free(cache_t *cache);
static bool Belady_get(cache_t *cache, const request_t *req);
static cache_obj_t *Belady_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *Belady_insert(cache_t *cache, const request_t *req);
static cache_obj_t *Belady_to_evict(cache_t *cache, const request_t *req);
static void Belady_evict(cache_t *cache, const request_t *req);
static bool Belady_remove(cache_t *cache, const obj_id_t obj_id);
static bool Belady_remove(cache_t *cache, obj_id_t obj_id);
static void Belady_remove_obj(cache_t *cache, cache_obj_t *obj);

// ***********************************************************************
Expand Down Expand Up @@ -139,7 +139,7 @@ static bool Belady_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *Belady_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
Belady_params_t *params = cache->eviction_params;
cache_obj_t *cached_obj = cache_find_base(cache, req, update_cache);

Expand Down Expand Up @@ -270,7 +270,7 @@ static void Belady_remove_obj(cache_t *cache, cache_obj_t *obj) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool Belady_remove(cache_t *cache, const obj_id_t obj_id) {
static bool Belady_remove(cache_t *cache, obj_id_t obj_id) {
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
if (obj == NULL) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/BeladySize.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ static void BeladySize_parse_params(cache_t *cache,
static void BeladySize_free(cache_t *cache);
static bool BeladySize_get(cache_t *cache, const request_t *req);
static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *BeladySize_insert(cache_t *cache, const request_t *req);
static cache_obj_t *BeladySize_to_evict(cache_t *cache, const request_t *req);
static void BeladySize_evict(cache_t *cache, const request_t *req);
static bool BeladySize_remove(cache_t *cache, const obj_id_t obj_id);
static bool BeladySize_remove(cache_t *cache, obj_id_t obj_id);
static void BeladySize_remove_obj(cache_t *cache, cache_obj_t *obj);

// ***********************************************************************
Expand Down Expand Up @@ -130,7 +130,7 @@ static bool BeladySize_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *BeladySize_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
cache_obj_t *obj = cache_find_base(cache, req, update_cache);

if (!update_cache) {
Expand Down Expand Up @@ -265,7 +265,7 @@ static void BeladySize_evict(cache_t *cache, const request_t *req) {
cache_evict_base(cache, obj_to_evict, true);
}

bool BeladySize_remove(cache_t *cache, const obj_id_t obj_id) {
bool BeladySize_remove(cache_t *cache, obj_id_t obj_id) {
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
if (obj == NULL) {
return false;
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/CAR.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ static void CAR_parse_params(cache_t *cache, const char *cache_specific_params);
static void CAR_free(cache_t *cache);
static bool CAR_get(cache_t *cache, const request_t *req);
static cache_obj_t *CAR_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *CAR_insert(cache_t *cache, const request_t *req);
static cache_obj_t *CAR_to_evict(cache_t *cache, const request_t *req);
static void CAR_evict(cache_t *cache, const request_t *req);
static bool CAR_remove(cache_t *cache, const obj_id_t obj_id);
static bool CAR_remove(cache_t *cache, obj_id_t obj_id);

static void _CAR_discard_LRU_L1_ghost(cache_t *cache, const request_t *req);
static void _CAR_discard_LRU_L2_ghost(cache_t *cache, const request_t *req);
Expand Down Expand Up @@ -118,7 +118,7 @@ cache_t *CAR_init(const common_cache_params_t ccache_params,
* @param cache_specific_params Clock specific parameters as a string
*/
static cache_obj_t *CAR_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
CAR_params_t *params = (CAR_params_t *)(cache->eviction_params);
cache_obj_t *obj = cache_find_base(cache, req, update_cache);

Expand Down Expand Up @@ -304,7 +304,7 @@ static void CAR_evict(cache_t *cache, const request_t *req) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool CAR_remove(cache_t *cache, const obj_id_t obj_id) {
static bool CAR_remove(cache_t *cache, obj_id_t obj_id) {
CAR_params_t *params = (CAR_params_t *)(cache->eviction_params);
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);

Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/CR_LFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ static void CR_LFU_parse_params(cache_t *cache,
static void CR_LFU_free(cache_t *cache);
static bool CR_LFU_get(cache_t *cache, const request_t *req);
static cache_obj_t *CR_LFU_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *CR_LFU_insert(cache_t *cache, const request_t *req);
static cache_obj_t *CR_LFU_to_evict(cache_t *cache, const request_t *req);
static void CR_LFU_evict(cache_t *cache, const request_t *req);
static bool CR_LFU_remove(cache_t *cache, const obj_id_t obj_id);
static bool CR_LFU_remove(cache_t *cache, obj_id_t obj_id);

static void free_list_node(void *list_node) {
my_free(sizeof(freq_node_t), list_node);
Expand Down Expand Up @@ -137,7 +137,7 @@ static bool CR_LFU_get(cache_t *cache, const request_t *req) {
* @return the object or NULL if not found
*/
static cache_obj_t *CR_LFU_find(cache_t *cache, const request_t *req,
const bool update_cache) {
bool update_cache) {
cache_obj_t *cache_obj = cache_find_base(cache, req, update_cache);

if (cache_obj && likely(update_cache)) {
Expand Down Expand Up @@ -381,7 +381,7 @@ static void CR_LFU_evict(cache_t *cache, const request_t *req) {
}
}

static bool CR_LFU_remove(cache_t *cache, const obj_id_t obj_id) {
static bool CR_LFU_remove(cache_t *cache, obj_id_t obj_id) {
CR_LFU_params_t *params = (CR_LFU_params_t *)(cache->eviction_params);

cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
Expand Down
6 changes: 3 additions & 3 deletions libCacheSim/cache/eviction/Cacheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ typedef struct Cacheus_params {
static void Cacheus_free(cache_t *cache);
static bool Cacheus_get(cache_t *cache, const request_t *req);
static cache_obj_t *Cacheus_find(cache_t *cache, const request_t *req,
const bool update_cache);
bool update_cache);
static cache_obj_t *Cacheus_insert(cache_t *cache, const request_t *req);
static cache_obj_t *Cacheus_to_evict(cache_t *cache, const request_t *req);
static void Cacheus_evict(cache_t *cache, const request_t *req);
static bool Cacheus_remove(cache_t *cache, const obj_id_t obj_id);
static bool Cacheus_remove(cache_t *cache, obj_id_t obj_id);

static inline int64_t Cacheus_get_occupied_byte(const cache_t *cache);
static inline int64_t Cacheus_get_n_obj(const cache_t *cache);
Expand Down Expand Up @@ -315,7 +315,7 @@ static void Cacheus_evict(cache_t *cache, const request_t *req) {
cache->to_evict_candidate_gen_vtime = -1;
}

static bool Cacheus_remove(cache_t *cache, const obj_id_t obj_id) {
static bool Cacheus_remove(cache_t *cache, obj_id_t obj_id) {
Cacheus_params_t *params = (Cacheus_params_t *)(cache->eviction_params);
params->req_local->obj_id = obj_id;
bool lru_removed = params->LRU->remove(params->LRU, obj_id);
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/cache/eviction/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ static void Clock_parse_params(cache_t *cache,
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);
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);
static bool Clock_remove(cache_t *cache, const obj_id_t obj_id);
static bool Clock_remove(cache_t *cache, obj_id_t obj_id);

// ***********************************************************************
// **** ****
Expand Down Expand Up @@ -143,7 +143,7 @@ static bool Clock_get(cache_t *cache, const request_t *req) {
* @return true on hit, false on miss
*/
static cache_obj_t *Clock_find(cache_t *cache, const request_t *req,
const bool update_cache) {
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 @@ -273,7 +273,7 @@ static void Clock_remove_obj(cache_t *cache, cache_obj_t *obj) {
* @return true if the object is removed, false if the object is not in the
* cache
*/
static bool Clock_remove(cache_t *cache, const obj_id_t obj_id) {
static bool Clock_remove(cache_t *cache, obj_id_t obj_id) {
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
if (obj == NULL) {
return false;
Expand Down
Loading
Loading