Skip to content

Commit

Permalink
minor updates with several bug fixes (#46)
Browse files Browse the repository at this point in the history
1. fix warnings 
2. fix turning off zstd not working
3. fix bugs at several places
4. it is still challenging to build on macos
  • Loading branch information
1a1a11a committed Jan 4, 2024
1 parent 290101d commit 4d47e20
Show file tree
Hide file tree
Showing 68 changed files with 400 additions and 422 deletions.
34 changes: 23 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 3.12)
project(libCacheSim)
set(DESCRIPTION "a high performance cache simulation library")
set(PROJECT_WEB "http://cachesim.com")
Expand All @@ -9,6 +9,9 @@ set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_RELEASE_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR})
set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_RELEASE_VERSION}.${${PROJECT_NAME}_VERSION_PATCH})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)

########################################
# define options #
Expand All @@ -19,7 +22,7 @@ option(USE_HUGEPAGE "use transparent hugepage" ON)
option(ENABLE_TESTS "whether enable test" ON)
option(ENABLE_GLCACHE "enable group-learned cache" OFF)
option(SUPPORT_TTL "whether support TTL" OFF)
option(SUPPORT_ZSTD_TRACE "whether support zstd trace" ON)
option(OPT_SUPPORT_ZSTD_TRACE "whether support zstd trace" ON)
option(ENABLE_LRB "enable LRB" OFF)
set(LOG_LEVEL NONE CACHE STRING "change the logging level")
set_property(CACHE LOG_LEVEL PROPERTY STRINGS INFO WARN ERROR DEBUG VERBOSE VVERBOSE VVVERBOSE)
Expand Down Expand Up @@ -102,7 +105,7 @@ endif()
message(STATUS "CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}")
# string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")

message(STATUS "SUPPORT TTL ${SUPPORT_TTL}, USE_HUGEPAGE ${USE_HUGEPAGE}, LOGLEVEL ${LOG_LEVEL}, ENABLE_GLCACHE ${ENABLE_GLCACHE}, ENABLE_LRB ${ENABLE_LRB}, SUPPORT_ZSTD_TRACE ${SUPPORT_ZSTD_TRACE}")
message(STATUS "SUPPORT TTL ${SUPPORT_TTL}, USE_HUGEPAGE ${USE_HUGEPAGE}, LOGLEVEL ${LOG_LEVEL}, ENABLE_GLCACHE ${ENABLE_GLCACHE}, ENABLE_LRB ${ENABLE_LRB}, OPT_SUPPORT_ZSTD_TRACE ${OPT_SUPPORT_ZSTD_TRACE}")

# add_compile_options(-fsanitize=address)
# add_link_options(-fsanitize=address)
Expand All @@ -114,13 +117,12 @@ message(STATUS "SUPPORT TTL ${SUPPORT_TTL}, USE_HUGEPAGE ${USE_HUGEPAGE}, LOGLEV
set(CFLAGS "$ENV{CFLAGS} "
"-Wall -Wshadow -Winline "
"-Wno-unused "
"-Wstrict-prototypes -Wmissing-prototypes "
"-Wstrict-prototypes "
# "-Wmissing-prototypes "
"-Wmissing-declarations "
"-Wredundant-decls "
"-Wunused-value -Wunused-variable "
"-std=c11 "
"-fno-strict-aliasing "
"-O0 "
)


Expand All @@ -147,7 +149,7 @@ set(LIBS ${LIBS} ${GLib_LIBRARY})
# link_libraries(${GLib2_LDFLAGS})
#endif()

if (SUPPORT_ZSTD_TRACE)
if (OPT_SUPPORT_ZSTD_TRACE)
add_compile_definitions(SUPPORT_ZSTD_TRACE=1)
find_package(ZSTD)
if ("${ZSTD_LIBRARIES}" STREQUAL "")
Expand All @@ -157,7 +159,7 @@ if (SUPPORT_ZSTD_TRACE)
message(STATUS "ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIRS}, ZSTD_LIBRARIES ${ZSTD_LIBRARIES}")
else()
remove_definitions(SUPPORT_ZSTD_TRACE)
endif(SUPPORT_ZSTD_TRACE)
endif(OPT_SUPPORT_ZSTD_TRACE)


# libgoogle-perftools-dev google-perftools
Expand Down Expand Up @@ -311,10 +313,20 @@ if (ENABLE_LRB)
)
endif(ENABLE_LRB)

file(GLOB reader_source
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/*.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/*.c
set(reader_source
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/reader.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/binary.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/csv.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/lcs.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/libcsv.c
${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/txt.c
)
if (OPT_SUPPORT_ZSTD_TRACE)
set (reader_source
${reader_source} ${PROJECT_SOURCE_DIR}/libCacheSim/traceReader/generalReader/zstdReader.c
)
endif(OPT_SUPPORT_ZSTD_TRACE)

file(GLOB dataStructure_source
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/*.c
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/hashtable/*.c
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/bin/cachesim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char **argv) {
"%s %32s cache size %8ld%s, %lld req, miss ratio %.4lf, byte miss "
"ratio %.4lf\n",
output_filename, result[i].cache_name,
(long)result[i].cache_size / size_unit, size_unit_str,
(long)(result[i].cache_size / size_unit), size_unit_str,
(long long)result[i].n_req,
(double)result[i].n_miss / (double)result[i].n_req,
(double)result[i].n_miss_byte / (double)result[i].n_req_byte);
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/cache/admission/adaptsize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void adaptsize_admissioner_parse_params(
const char *init_params, adaptsize_admission_params_t *pa) {
if (init_params == NULL) {
pa->adaptsize_threshold = INT64_MAX;
INFO("use default adaptsize admission: %ld", pa->adaptsize_threshold);
INFO("use default adaptsize admission: %ld", (long) pa->adaptsize_threshold);
} else {
char *params_str = strdup(init_params);
char *old_params_str = params_str;
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/cache/admission/size.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void size_admissioner_parse_params(const char *init_params,
size_admission_params_t *pa) {
if (init_params == NULL) {
pa->size_threshold = INT64_MAX;
INFO("use default size admission: %ld", pa->size_threshold);
INFO("use default size admission: %ld", (long)pa->size_threshold);
} else {
char *params_str = strdup(init_params);
char *old_params_str = params_str;
Expand Down
7 changes: 3 additions & 4 deletions libCacheSim/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Created by Juncheng Yang on 6/20/20.
//

#include "../include/libCacheSim/cache.h"

#include "../dataStructure/hashtable/hashtable.h"
#include "../include/libCacheSim/cache.h"
#include "../include/libCacheSim/prefetchAlgo.h"

/** this file contains both base function, which should be called by all
Expand Down Expand Up @@ -145,15 +144,15 @@ bool cache_can_insert_default(cache_t *cache, const request_t *req) {
if (admissioner->admit(admissioner, req) == false) {
DEBUG_ONCE(
"admission algorithm does not admit: req %ld, obj %lu, size %lu\n",
cache->n_req, (unsigned long)req->obj_id,
(long)cache->n_req, (unsigned long)req->obj_id,
(unsigned long)req->obj_size);
return false;
}
}

if (req->obj_size + cache->obj_md_size > cache->cache_size) {
WARN_ONCE("%ld req, obj %lu, size %lu larger than cache size %lu\n",
cache->n_req, (unsigned long)req->obj_id,
(long)cache->n_req, (unsigned long)req->obj_id,
(unsigned long)req->obj_size, (unsigned long)cache->cache_size);
return false;
}
Expand Down
14 changes: 5 additions & 9 deletions libCacheSim/cache/eviction/ARC.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ static void ARC_free(cache_t *cache) {
* @return true if cache hit, false if cache miss
*/
static bool ARC_get(cache_t *cache, const request_t *req) {
ARC_params_t *params = (ARC_params_t *)(cache->eviction_params);
#ifdef DEBUG_MODE
return ARC_get_debug(cache, req);
#else
Expand Down Expand Up @@ -520,7 +519,6 @@ static void _ARC_evict_L2_ghost(cache_t *cache, const request_t *req) {
static void _ARC_replace(cache_t *cache, const request_t *req) {
ARC_params_t *params = (ARC_params_t *)(cache->eviction_params);

cache_obj_t *obj = NULL;

bool cond1 = params->L1_data_size > 0;
bool cond2 = params->L1_data_size > params->p;
Expand Down Expand Up @@ -613,13 +611,12 @@ static void ARC_parse_params(cache_t *cache,

char *params_str = strdup(cache_specific_params);
char *old_params_str = params_str;
char *end;

while (params_str != NULL && params_str[0] != '\0') {
/* different parameters are separated by comma,
* key and value are separated by = */
char *key = strsep((char **)&params_str, "=");
char *value = strsep((char **)&params_str, ",");
// char *value = strsep((char **)&params_str, ",");

// skip the white space
while (params_str != NULL && *params_str == ' ') {
Expand Down Expand Up @@ -649,31 +646,31 @@ static void print_cache(cache_t *cache) {
cache_obj_t *obj = params->L1_data_head;
printf("T1: ");
while (obj != NULL) {
printf("%ld ", obj->obj_id);
printf("%ld ", (long)obj->obj_id);
obj = obj->queue.next;
}
printf("\n");

obj = params->L1_ghost_head;
printf("B1: ");
while (obj != NULL) {
printf("%ld ", obj->obj_id);
printf("%ld ", (long)obj->obj_id);
obj = obj->queue.next;
}
printf("\n");

obj = params->L2_data_head;
printf("T2: ");
while (obj != NULL) {
printf("%ld ", obj->obj_id);
printf("%ld ", (long)obj->obj_id);
obj = obj->queue.next;
}
printf("\n");

obj = params->L2_ghost_head;
printf("B2: ");
while (obj != NULL) {
printf("%ld ", obj->obj_id);
printf("%ld ", (long)obj->obj_id);
obj = obj->queue.next;
}
printf("\n");
Expand Down Expand Up @@ -773,7 +770,6 @@ static inline void _ARC_sanity_check_full(cache_t *cache,
}

static bool ARC_get_debug(cache_t *cache, const request_t *req) {
ARC_params_t *params = (ARC_params_t *)(cache->eviction_params);

cache->n_req += 1;

Expand Down
13 changes: 7 additions & 6 deletions libCacheSim/cache/eviction/ARCv0.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ static bool ARCv0_get_debug(cache_t *cache, const request_t *req);
*/
cache_t *ARCv0_init(const common_cache_params_t ccache_params,
const char *cache_specific_params) {
cache_t *cache = cache_struct_init("ARCv0", ccache_params, cache_specific_params);
cache_t *cache =
cache_struct_init("ARCv0", ccache_params, cache_specific_params);
cache->cache_init = ARCv0_init;
cache->cache_free = ARCv0_free;
cache->get = ARCv0_get;
Expand Down Expand Up @@ -186,7 +187,7 @@ static void ARCv0_free(cache_t *cache) {
* @return true if cache hit, false if cache miss
*/
static bool ARCv0_get(cache_t *cache, const request_t *req) {
ARCv0_params_t *params = (ARCv0_params_t *)(cache->eviction_params);
// ARCv0_params_t *params = (ARCv0_params_t *)(cache->eviction_params);
#ifdef DEBUG_MODE
return ARCv0_get_debug(cache, req);
#else
Expand Down Expand Up @@ -257,7 +258,7 @@ static cache_obj_t *ARCv0_find(cache_t *cache, const request_t *req,
}
#ifdef QUICK_DEMOTION
// params->p = MIN(params->p, cache->cache_size/10);
params->p = cache->cache_size/10;
params->p = cache->cache_size / 10;
#endif
} else {
// cache hit, case I: x in L1_data or L2_data
Expand Down Expand Up @@ -534,13 +535,12 @@ static void ARCv0_parse_params(cache_t *cache,

char *params_str = strdup(cache_specific_params);
char *old_params_str = params_str;
char *end;

while (params_str != NULL && params_str[0] != '\0') {
/* different parameters are separated by comma,
* key and value are separated by = */
char *key = strsep((char **)&params_str, "=");
char *value = strsep((char **)&params_str, ",");
// char *value = strsep((char **)&params_str, ",");

// skip the white space
while (params_str != NULL && *params_str == ' ') {
Expand Down Expand Up @@ -581,7 +581,8 @@ static bool ARCv0_get_debug(cache_t *cache, const request_t *req) {

cache->n_req += 1;

printf("%ld obj_id %ld: p %.2lf\n", cache->n_req, req->obj_id, params->p);
printf("%ld obj_id %ld: p %.2lf\n", (long)cache->n_req, (long)req->obj_id,
params->p);
print_cache(cache);
printf("==================================\n");

Expand Down
5 changes: 2 additions & 3 deletions libCacheSim/cache/eviction/Cacheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ static void Cacheus_evict(cache_t *cache, const request_t *req) {
cache_t *lfu = params->LFU;
cache_t *lru_g = params->LRU_g;
cache_t *lfu_g = params->LFU_g;
SR_LRU_params_t *params_LRU = (SR_LRU_params_t *)(lru->eviction_params);

// If two voters decide the same:
cache_obj_t *lru_to_evict = lru->to_evict(lru, req);
Expand Down Expand Up @@ -390,8 +389,8 @@ static void update_lr(cache_t *cache, const request_t *req) {
// self.learning_rate = 0.9
// elif self.learning_rate <= 0.001:
// self.learning_rate = 0.005
if (params->lr + sign * abs(params->lr * delta_lr) > 0.001)
params->lr = params->lr + sign * abs(params->lr * delta_lr);
if (params->lr + sign * fabs(params->lr * delta_lr) > 0.001)
params->lr = params->lr + sign * fabs(params->lr * delta_lr);
else
params->lr = 0.0001;
params->unlearn_count = 0;
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 @@ -53,7 +53,8 @@ static bool Clock_remove(cache_t *cache, const obj_id_t obj_id);
*/
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 *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 @@ -231,7 +232,7 @@ static void Clock_evict(cache_t *cache, const request_t *req) {
move_obj_to_head(&params->q_head, &params->q_tail, obj_to_evict);
obj_to_evict = params->q_tail;
}

remove_obj_from_list(&params->q_head, &params->q_tail, obj_to_evict);
cache_evict_base(cache, obj_to_evict, true);
}
Expand Down Expand Up @@ -291,8 +292,7 @@ static bool Clock_remove(cache_t *cache, const obj_id_t obj_id) {
static const char *Clock_current_params(cache_t *cache,
Clock_params_t *params) {
static __thread char params_str[128];
int n =
snprintf(params_str, 128, "n-bit-counter=%d\n", params->n_bit_counter);
snprintf(params_str, 128, "n-bit-counter=%d\n", params->n_bit_counter);

return params_str;
}
Expand Down
4 changes: 3 additions & 1 deletion libCacheSim/cache/eviction/FIFO_Merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void FIFO_Merge_evict(cache_t *cache, const request_t *req) {

if (cache->n_obj <= params->n_exam_obj) {
// just evict one object - this is fifo
cache_obj_t *cache_obj = params->q_tail;
cache_obj = params->q_tail;
params->next_to_exam = NULL;
remove_obj_from_list(&params->q_head, &params->q_tail, cache_obj);
cache_evict_base(cache, cache_obj, true);
Expand Down Expand Up @@ -451,6 +451,8 @@ static double retain_metric(cache_t *cache, cache_obj_t *cache_obj) {
default:
break;
}
abort();
return -1;
}

#ifdef __cplusplus
Expand Down
3 changes: 2 additions & 1 deletion libCacheSim/cache/eviction/FIFO_Reinsertion.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static void FIFO_Reinsertion_evict(cache_t *cache, const request_t *req) {

if (cache->n_obj <= params->n_exam_obj) {
// just evict one object
cache_obj_t *cache_obj = params->next_to_merge->queue.prev;
cache_obj = params->next_to_merge->queue.prev;
FIFO_Reinsertion_remove_obj(cache, params->next_to_merge);
params->next_to_merge = cache_obj;

Expand Down Expand Up @@ -473,6 +473,7 @@ static double retain_metric(cache_t *cache, cache_obj_t *cache_obj) {
default:
break;
}
abort();
}

#ifdef __cplusplus
Expand Down
1 change: 0 additions & 1 deletion libCacheSim/cache/eviction/LFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ void LFU_remove_obj(cache_t *cache, cache_obj_t *obj) {
* cache
*/
bool LFU_remove(cache_t *cache, obj_id_t obj_id) {
LFU_params_t *params = (LFU_params_t *)(cache->eviction_params);
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
if (obj == NULL) {
return false;
Expand Down
1 change: 0 additions & 1 deletion libCacheSim/cache/eviction/LFUDA.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ static void LFUDA_remove_obj(cache_t *cache, cache_obj_t *obj) {
* cache
*/
static bool LFUDA_remove(cache_t *cache, obj_id_t obj_id) {
LFUDA_params_t *params = (LFUDA_params_t *)(cache->eviction_params);
cache_obj_t *obj = hashtable_find_obj_id(cache->hashtable, obj_id);
if (obj == NULL) {
return false;
Expand Down
9 changes: 1 addition & 8 deletions libCacheSim/cache/eviction/LHD/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
file(GLOB src *.cpp)
add_library (LHD ${src})

set_target_properties(LHD
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO
)


set_property(LHD CXX_STANDARD 17)
5 changes: 4 additions & 1 deletion libCacheSim/cache/eviction/LHD/candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ struct candidate_t {
#endif

static candidate_t make(const request_t* req) {
return candidate_t{DEFAULT_APP_ID, static_cast<int64_t>(req->obj_id)};
candidate_t c;
c.appId = DEFAULT_APP_ID;
c.id = static_cast<int64_t>(req->obj_id);
return c;
}

inline bool operator==(const candidate_t& that) const {
Expand Down

0 comments on commit 4d47e20

Please sign in to comment.