Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ endif()


# Define shared compiler flags for all targets
set(LIBCACHESIM_C_FLAGS
-Wall -Wextra -Werror
-Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable
-Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings
set(LIBCACHESIM_C_FLAGS
-Wall -Wextra -Werror
-Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable
-Wpedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings
-Wstrict-prototypes -Wold-style-definition -Wredundant-decls -Wnested-externs -Wmissing-include-dirs
)

set(LIBCACHESIM_CXX_FLAGS
-Wall -Wextra -Werror
-Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable
set(LIBCACHESIM_CXX_FLAGS
-Wall -Wextra -Werror
-Wno-deprecated-copy -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable
-Wno-pedantic -Wformat=2 -Wformat-security -Wshadow -Wwrite-strings -Wmissing-include-dirs
)

Expand All @@ -119,10 +119,18 @@ list(APPEND dependency_libs ${CMAKE_THREAD_LIBS_INIT})
# Link standard math and dl libraries universally
list(APPEND dependency_libs m dl)

find_package(GLib REQUIRED)
# Find GLib using pkg-config
find_package(PkgConfig REQUIRED)

# Find glib-2.0 using pkg-config
pkg_check_modules(GLib REQUIRED glib-2.0)

# Add GLib library directories to the linker search path
link_directories(${GLib_LIBRARY_DIRS})

# Don't add GLib includes globally - add them to specific targets
# include_directories(${GLib_INCLUDE_DIRS})
list(APPEND dependency_libs ${GLib_LIBRARY})
list(APPEND dependency_libs ${GLib_LIBRARIES})

find_package(argp REQUIRED)
# Don't add argp includes globally
Expand Down Expand Up @@ -334,4 +342,4 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Find${PROJECT_NAME}.cmake
install(EXPORT ${PROJECT_NAME}Targets
FILE ${PROJECT_NAME}Targets.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
)
25 changes: 13 additions & 12 deletions libCacheSim/cache/eviction/QDLP.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,25 @@ static cache_obj_t *QDLP_to_evict(cache_t *cache, const request_t *req) {
static void QDLP_evict(cache_t *cache, const request_t *req) {
QDLP_params_t *params = (QDLP_params_t *)cache->eviction_params;

cache_t *fifo = params->fifo;
cache_t *ghost = params->fifo_ghost;
cache_t *main = params->main_cache;
cache_t *small_fifo = params->fifo;
cache_t *ghost_fifo = params->fifo_ghost;
Comment thread
haochengxia marked this conversation as resolved.
Outdated
cache_t *main_cache = params->main_cache;

if (fifo->get_occupied_byte(fifo) == 0) {
if (small_fifo->get_occupied_byte(small_fifo) == 0) {
#if defined(TRACK_EVICTION_V_AGE)
cache_obj_t *obj = main->to_evict(main, req);
cache_obj_t *obj = main_cache->to_evict(main_cache, req);
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
#endif

assert(main->get_occupied_byte(main) <= cache->cache_size);
assert(main_cache->get_occupied_byte(main_cache) <= cache->cache_size);
// evict from main cache
main->evict(main, req);
main_cache->evict(main_cache, req);

return;
}

// evict from FIFO
cache_obj_t *obj = fifo->to_evict(fifo, req);
cache_obj_t *obj = small_fifo->to_evict(small_fifo, req);
assert(obj != NULL);
// need to copy the object before it is evicted
copy_cache_obj_to_request(params->req_local, obj);
Expand All @@ -361,21 +361,22 @@ static void QDLP_evict(cache_t *cache, const request_t *req) {

params->main_cache->get(params->main_cache, params->req_local);
#if defined(TRACK_EVICTION_V_AGE)
main->find(main, params->req_local, false)->create_time = obj->create_time;
main_cache->find(main_cache, params->req_local, false)->create_time =
obj->create_time;
} else {
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
#else
} else {
#endif
// insert to ghost
if (ghost != NULL) {
ghost->get(ghost, params->req_local);
if (ghost_fifo != NULL) {
ghost_fifo->get(ghost_fifo, params->req_local);
}
}

// remove from fifo, but do not update stat
// bool removed = fifo->remove(fifo, params->req_local->obj_id);
fifo->evict(fifo, req);
small_fifo->evict(small_fifo, req);
}

/**
Expand Down
46 changes: 23 additions & 23 deletions libCacheSim/cache/eviction/S3FIFO.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,24 @@ static cache_obj_t *S3FIFO_insert(cache_t *cache, const request_t *req) {
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
cache_obj_t *obj = NULL;

cache_t *small = params->small_fifo;
cache_t *main = params->main_fifo;
cache_t *small_fifo = params->small_fifo;
cache_t *main_fifo = params->main_fifo;

if (params->hit_on_ghost) {
/* insert into main FIFO */
params->hit_on_ghost = false;
obj = main->insert(main, req);
obj = main_fifo->insert(main_fifo, req);
} else {
/* insert into small fifo */
if (req->obj_size >= small->cache_size) {
if (req->obj_size >= small_fifo->cache_size) {
return NULL;
}

if (!params->has_evicted &&
small->get_occupied_byte(small) >= small->cache_size) {
obj = main->insert(main, req);
small_fifo->get_occupied_byte(small_fifo) >= small_fifo->cache_size) {
obj = main_fifo->insert(main_fifo, req);
} else {
obj = small->insert(small, req);
obj = small_fifo->insert(small_fifo, req);
}
}

Expand All @@ -299,19 +299,19 @@ static cache_obj_t *S3FIFO_to_evict(cache_t *cache, const request_t *req) {

static void S3FIFO_evict_small(cache_t *cache, const request_t *req) {
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
cache_t *small = params->small_fifo;
cache_t *small_fifo = params->small_fifo;
cache_t *ghost = params->ghost_fifo;
cache_t *main = params->main_fifo;
cache_t *main_fifo = params->main_fifo;

bool has_evicted = false;
while (!has_evicted && small->get_occupied_byte(small) > 0) {
cache_obj_t *obj_to_evict = small->to_evict(small, req);
while (!has_evicted && small_fifo->get_occupied_byte(small_fifo) > 0) {
cache_obj_t *obj_to_evict = small_fifo->to_evict(small_fifo, req);
DEBUG_ASSERT(obj_to_evict != NULL);
// need to copy the object before it is evicted
copy_cache_obj_to_request(params->req_local, obj_to_evict);

if (obj_to_evict->S3FIFO.freq >= params->move_to_main_threshold) {
main->insert(main, params->req_local);
main_fifo->insert(main_fifo, params->req_local);
} else {
// insert to ghost
if (ghost != NULL) {
Expand All @@ -321,32 +321,32 @@ static void S3FIFO_evict_small(cache_t *cache, const request_t *req) {
}

// remove from small fifo, but do not update stat
bool removed = small->remove(small, params->req_local->obj_id);
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
DEBUG_ASSERT(removed);
}
}

static void S3FIFO_evict_main(cache_t *cache, const request_t *req) {
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
cache_t *main = params->main_fifo;
cache_t *main_fifo = params->main_fifo;

bool has_evicted = false;
while (!has_evicted && main->get_occupied_byte(main) > 0) {
cache_obj_t *obj_to_evict = main->to_evict(main, req);
while (!has_evicted && main_fifo->get_occupied_byte(main_fifo) > 0) {
cache_obj_t *obj_to_evict = main_fifo->to_evict(main_fifo, req);
DEBUG_ASSERT(obj_to_evict != NULL);
int freq = obj_to_evict->S3FIFO.freq;
copy_cache_obj_to_request(params->req_local, obj_to_evict);
if (freq >= 1) {
// we need to evict first because the object to insert has the same obj_id
main->remove(main, obj_to_evict->obj_id);
main_fifo->remove(main_fifo, obj_to_evict->obj_id);
obj_to_evict = NULL;

cache_obj_t *new_obj = main->insert(main, params->req_local);
cache_obj_t *new_obj = main_fifo->insert(main_fifo, params->req_local);
// clock with 2-bit counter
new_obj->S3FIFO.freq = MIN(freq, 3) - 1;

} else {
bool removed = main->remove(main, obj_to_evict->obj_id);
bool removed = main_fifo->remove(main_fifo, obj_to_evict->obj_id);
DEBUG_ASSERT(removed);

has_evicted = true;
Expand All @@ -367,11 +367,11 @@ static void S3FIFO_evict(cache_t *cache, const request_t *req) {
S3FIFO_params_t *params = (S3FIFO_params_t *)cache->eviction_params;
params->has_evicted = true;

cache_t *small = params->small_fifo;
cache_t *main = params->main_fifo;
cache_t *small_fifo = params->small_fifo;
cache_t *main_fifo = params->main_fifo;

if (main->get_occupied_byte(main) > main->cache_size ||
small->get_occupied_byte(small) == 0) {
if (main_fifo->get_occupied_byte(main_fifo) > main_fifo->cache_size ||
small_fifo->get_occupied_byte(small_fifo) == 0) {
S3FIFO_evict_main(cache, req);
} else {
S3FIFO_evict_small(cache, req);
Expand Down
36 changes: 18 additions & 18 deletions libCacheSim/cache/eviction/S3FIFOd.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,50 +399,50 @@ static cache_obj_t *S3FIFOd_to_evict(cache_t *cache, const request_t *req) {
static void S3FIFOd_evict(cache_t *cache, const request_t *req) {
S3FIFOd_params_t *params = (S3FIFOd_params_t *)cache->eviction_params;

cache_t *fifo = params->fifo;
cache_t *small_fifo = params->fifo;
cache_t *ghost = params->fifo_ghost;
cache_t *main = params->main_cache;
cache_t *main_cache = params->main_cache;

if (fifo->get_occupied_byte(fifo) == 0) {
assert(main->get_occupied_byte(main) <= cache->cache_size);
if (small_fifo->get_occupied_byte(small_fifo) == 0) {
assert(main_cache->get_occupied_byte(main_cache) <= cache->cache_size);
// evict from main cache
cache_obj_t *obj = main->to_evict(main, req);
cache_obj_t *obj = main_cache->to_evict(main_cache, req);
#if defined(TRACK_EVICTION_V_AGE)
record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
#endif
copy_cache_obj_to_request(params->req_local, obj);
params->main_cache_eviction->get(params->main_cache_eviction,
params->req_local);
main->evict(main, req);
main_cache->evict(main_cache, req);
return;
}

// evict from FIFO
cache_obj_t *obj = fifo->to_evict(fifo, req);
cache_obj_t *obj = small_fifo->to_evict(small_fifo, req);
assert(obj != NULL);
// need to copy the object before it is evicted
copy_cache_obj_to_request(params->req_local, obj);

#if defined(TRACK_EVICTION_V_AGE)
if (obj->misc.freq >= params->move_to_main_threshold) {
// promote to main cache
cache_obj_t *new_obj = main->insert(main, params->req_local);
cache_obj_t *new_obj = main_cache->insert(main_cache, params->req_local);
new_obj->create_time = obj->create_time;
// evict from fifo, must be after copy eviction age
bool removed = fifo->remove(fifo, params->req_local->obj_id);
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
assert(removed);

while (main->get_occupied_byte(main) > main->cache_size) {
while (main_cache->get_occupied_byte(main_cache) > main_cache->cache_size) {
// evict from main cache
obj = main->to_evict(main, req);
obj = main_cache->to_evict(main_cache, req);
copy_cache_obj_to_request(params->req_local, obj);
params->main_cache_eviction->get(params->main_cache_eviction,
params->req_local);
main->evict(main, req);
main_cache->evict(main_cache, req);
}
} else {
// evict from fifo, must be after copy eviction age
bool removed = fifo->remove(fifo, params->req_local->obj_id);
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
assert(removed);

record_eviction_age(cache, obj, CURR_TIME(cache, req) - obj->create_time);
Expand All @@ -453,20 +453,20 @@ static void S3FIFOd_evict(cache_t *cache, const request_t *req) {

#else
// evict from fifo
bool removed = fifo->remove(fifo, params->req_local->obj_id);
bool removed = small_fifo->remove(small_fifo, params->req_local->obj_id);
assert(removed);

if (obj->misc.freq >= params->move_to_main_threshold) {
// promote to main cache
main->insert(main, params->req_local);
main_cache->insert(main_cache, params->req_local);

while (main->get_occupied_byte(main) > main->cache_size) {
while (main_cache->get_occupied_byte(main_cache) > main_cache->cache_size) {
// evict from main cache
obj = main->to_evict(main, req);
obj = main_cache->to_evict(main_cache, req);
copy_cache_obj_to_request(params->req_local, obj);
params->main_cache_eviction->get(params->main_cache_eviction,
params->req_local);
main->evict(main, req);
main_cache->evict(main_cache, req);
}
} else {
// insert to ghost
Expand Down
Loading
Loading