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
6 changes: 1 addition & 5 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Code Quality

on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
on: [push, pull_request]

jobs:
code-quality:
Expand Down
43 changes: 19 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ option(SUPPORT_TTL "whether support TTL" OFF)
option(OPT_SUPPORT_ZSTD_TRACE "whether support zstd trace" ON)
option(ENABLE_LRB "enable LRB" OFF)
option(ENABLE_3L_CACHE "enable 3LCache" 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)
set(LOG_LEVEL "default" CACHE STRING "change the logging level")
set_property(CACHE LOG_LEVEL PROPERTY STRINGS ERROR WARN INFO DEBUG VERBOSE DEFAULT)

# Platform detection
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -41,20 +41,6 @@ else()
message(FATAL_ERROR "unsupported operating system ${CMAKE_SYSTEM_NAME}")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)

if(LOG_LEVEL STREQUAL "NONE")
set(LOG_LEVEL INFO)
endif()
elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug")
if(LOG_LEVEL STREQUAL "NONE")
set(LOG_LEVEL DEBUG)
endif()
else()
set(LOG_LEVEL INFO)
endif()

configure_file(libCacheSim/include/config.h.in libCacheSim/include/config.h)

if(SUPPORT_TTL)
Expand All @@ -65,12 +51,23 @@ if(USE_HUGEPAGE)
add_compile_definitions(USE_HUGEPAGE=1)
endif()

Copy link

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic that sets LOGLEVEL based on unset LOG_LEVEL depends on build type, but CMAKE_BUILD_TYPE is set later. To avoid unexpected defaults, move the set(CMAKE_BUILD_TYPE Release) block before log-level conditions.

Suggested change
set(CMAKE_BUILD_TYPE Release)

Copilot uses AI. Check for mistakes.
if(NOT CMAKE_BUILD_TYPE)
# we can also consider RelWithDebInfo, but it will be too slow for release build
set(CMAKE_BUILD_TYPE Release)
endif()


string(TOLOWER "${LOG_LEVEL}" LOG_LEVEL_LOWER)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)

if(LOG_LEVEL_LOWER STREQUAL "vvverbose")
add_compile_definitions(LOGLEVEL=3)
elseif(LOG_LEVEL_LOWER STREQUAL "vverbose")
add_compile_definitions(LOGLEVEL=4)
if(LOG_LEVEL_LOWER STREQUAL "default")
if(CMAKE_BUILD_TYPE_LOWER MATCHES "Debug")
message(STATUS "LOG_LEVEL is not set, use DEBUG as default for debug build")
add_compile_definitions(LOGLEVEL=6)
else()
message(STATUS "LOG_LEVEL is not set, use INFO as default for release build")
add_compile_definitions(LOGLEVEL=7)
endif()
elseif(LOG_LEVEL_LOWER STREQUAL "verbose")
add_compile_definitions(LOGLEVEL=5)
elseif(LOG_LEVEL_LOWER STREQUAL "debug")
Expand All @@ -81,15 +78,13 @@ elseif(LOG_LEVEL_LOWER STREQUAL "warn")
add_compile_definitions(LOGLEVEL=8)
elseif(LOG_LEVEL_LOWER STREQUAL "error")
add_compile_definitions(LOGLEVEL=9)

# default none is info
elseif(LOG_LEVEL_LOWER STREQUAL "none")
add_compile_definitions(LOGLEVEL=7)
else()
message(WARNING "unknown log level ${LOG_LEVEL}, use INFO as default")
add_compile_definitions(LOGLEVEL=7)
endif()



# Define shared compiler flags for all targets
set(LIBCACHESIM_C_FLAGS
-Wall -Wextra -Werror
Expand Down
6 changes: 3 additions & 3 deletions libCacheSim/cache/admission/adaptsize/adaptsize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Adaptsize::reconfigure() {
total_obj_size += it->second.obj_size;
++it;
}
VVERBOSE(
VERBOSE(
"Reconfiguring over %zu objects - log2 total size %f log2 statsize %f\n",
longterm_metadata.size(), log2(total_obj_size), log2(stat_size));
// END Prepare for reconf
Expand Down Expand Up @@ -249,10 +249,10 @@ void Adaptsize::reconfigure() {
WARN("BUG: NaN h1:%f h2:%f\n", h1, h2);
} else if (h1 > h2) {
c_param = pow(2, x1);
VVERBOSE("C = %f (log2: %f )\n", c_param, x1);
VERBOSE("C = %f (log2: %f )\n", c_param, x1);
} else {
c_param = pow(2, x2);
VVERBOSE("C = %f (log2: %f )\n", c_param, x2);
VERBOSE("C = %f (log2: %f )\n", c_param, x2);
}
// END Check for result
}
Expand Down
6 changes: 3 additions & 3 deletions libCacheSim/cache/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ bool cache_get_base(cache_t *cache, const request_t *req) {
}

if (hit) {
VVERBOSE("req %ld, obj %ld --- cache hit\n", cache->n_req, req->obj_id);
VERBOSE("req %ld, obj %ld --- cache hit\n", cache->n_req, req->obj_id);
} else if (!cache->can_insert(cache, req)) {
VVERBOSE("req %ld, obj %ld --- cache miss cannot insert\n", cache->n_req,
req->obj_id);
VERBOSE("req %ld, obj %ld --- cache miss cannot insert\n", cache->n_req,
req->obj_id);
} else {
while (cache->get_occupied_byte(cache) + req->obj_size +
cache->obj_md_size >
Expand Down
4 changes: 2 additions & 2 deletions libCacheSim/cache/eviction/GLCache/GLCache.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ static cache_obj_t *GLCache_insert(cache_t *cache, const request_t *req) {

seg = allocate_new_seg(cache, bucket->bucket_id);
append_seg_to_bucket(params, bucket, seg);
VVERBOSE("%lu allocate new seg, %d in use seg\n", cache->n_req,
params->n_in_use_segs);
VERBOSE("%lu allocate new seg, %d in use seg\n", cache->n_req,
params->n_in_use_segs);
}

cache_obj_t *cache_obj = &seg->objs[seg->n_obj];
Expand Down
4 changes: 2 additions & 2 deletions libCacheSim/cache/eviction/GLCache/eviction.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void GLCache_merge_segs(cache_t *cache, bucket_t *bucket, segment_t **segs) {
// called when there is no segment can be merged due to fragmentation
// different from clean_one_seg because this function also updates cache state
int evict_one_seg(cache_t *cache, segment_t *seg) {
VVERBOSE("req %lu, evict one seg id %d occupied size %lu/%lu\n", cache->n_req,
seg->seg_id, cache->occupied_byte, cache->cache_size);
VERBOSE("req %lu, evict one seg id %d occupied size %lu/%lu\n", cache->n_req,
seg->seg_id, cache->occupied_byte, cache->cache_size);
GLCache_params_t *params = cache->eviction_params;
bucket_t *bucket = &params->buckets[seg->bucket_id];

Expand Down
4 changes: 2 additions & 2 deletions libCacheSim/cache/eviction/LFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ static cache_obj_t *LFU_find(cache_t *cache, const request_t *req,
memset(new_node, 0, sizeof(freq_node_t));
new_node->freq = cache_obj->lfu.freq;
g_hash_table_insert(params->freq_map, new_key, new_node);
VVVERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
new_node->first_obj, new_node->last_obj);
VERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
new_node->first_obj, new_node->last_obj);
} else {
// it could be new_node is empty
DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);
Expand Down
4 changes: 2 additions & 2 deletions libCacheSim/cache/eviction/LFUDA.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ static cache_obj_t *LFUDA_find(cache_t *cache, const request_t *req,
memset(new_node, 0, sizeof(freq_node_t));
new_node->freq = cache_obj->lfu.freq;
g_hash_table_insert(params->freq_map, new_key, new_node);
VVVERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
new_node->first_obj, new_node->last_obj);
VERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
new_node->first_obj, new_node->last_obj);
} else {
// it could be new_node is empty
DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);
Expand Down
18 changes: 9 additions & 9 deletions libCacheSim/cache/eviction/LeCaR.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static cache_obj_t *LeCaR_find(cache_t *cache, const request_t *req,
* when remove_obj_from_freq_node */
if (cache_obj->LeCaR.freq < params->min_freq) {
params->min_freq = cache_obj->LeCaR.freq;
VVERBOSE("update min freq to %d\n", (int)params->min_freq);
VERBOSE("update min freq to %d\n", (int)params->min_freq);
}
}

Expand All @@ -312,7 +312,7 @@ static cache_obj_t *LeCaR_find(cache_t *cache, const request_t *req,
cache_obj_t *LeCaR_insert(cache_t *cache, const request_t *req) {
LeCaR_params_t *params = (LeCaR_params_t *)(cache->eviction_params);

VVERBOSE("insert object %lu into cache\n", (unsigned long)req->obj_id);
VERBOSE("insert object %lu into cache\n", (unsigned long)req->obj_id);

// LRU and hash table insert
cache_obj_t *cache_obj = cache_insert_base(cache, req);
Expand Down Expand Up @@ -652,8 +652,8 @@ static inline void update_LFU_min_freq(LeCaR_params_t *params) {
break;
}
}
VVERBOSE("update LFU min freq from %ld to %ld\n", old_min_freq,
params->min_freq);
VERBOSE("update LFU min freq from %ld to %ld\n", old_min_freq,
params->min_freq);
// if the object is the only object in the cache, we may have min_freq == 1
DEBUG_ASSERT(params->min_freq > old_min_freq ||
params->q_head == params->q_tail);
Expand Down Expand Up @@ -682,19 +682,19 @@ static inline void remove_obj_from_freq_node(LeCaR_params_t *params,
DEBUG_ASSERT(freq_node != NULL);
DEBUG_ASSERT(freq_node->freq == cache_obj->LeCaR.freq);
DEBUG_ASSERT(freq_node->n_obj > 0);
VVERBOSE("remove object from freq node %p (freq %ld, %u obj)\n", freq_node,
freq_node->freq, freq_node->n_obj);
VERBOSE("remove object from freq node %p (freq %ld, %u obj)\n", freq_node,
freq_node->freq, freq_node->n_obj);
freq_node->n_obj--;

if (cache_obj == freq_node->first_obj) {
VVVERBOSE("remove object from freq node --- object is the first object\n");
VERBOSE("remove object from freq node --- object is the first object\n");
freq_node->first_obj = cache_obj->LeCaR.lfu_next;
if (cache_obj->LeCaR.lfu_next != NULL)
((cache_obj_t *)(cache_obj->LeCaR.lfu_next))->LeCaR.lfu_prev = NULL;
}

if (cache_obj == freq_node->last_obj) {
VVVERBOSE("remove object from freq node --- object is the last object\n");
VERBOSE("remove object from freq node --- object is the last object\n");
freq_node->last_obj = cache_obj->LeCaR.lfu_prev;
if (cache_obj->LeCaR.lfu_prev != NULL)
((cache_obj_t *)(cache_obj->LeCaR.lfu_prev))->LeCaR.lfu_next = NULL;
Expand Down Expand Up @@ -787,7 +787,7 @@ static void verify_ghost_lru_integrity(cache_t *cache, LeCaR_params_t *params) {
cur = cur->queue.next;
}

VVVERBOSE(
VERBOSE(
"ghost entry head %p tail %p, "
"ghost_entry_size from scan = %ld,"
"lru_g_occupied_byte = %ld\n ",
Expand Down
4 changes: 1 addition & 3 deletions libCacheSim/include/libCacheSim/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ extern "C" {
#define MAGENTA "\x1B[35m"
#define CYAN "\x1B[36m"

#define VVVERBOSE_LEVEL 3
#define VVERBOSE_LEVEL 4
#define VERBOSE_LEVEL 5
#define DEBUG_LEVEL 6
#define INFO_LEVEL 7
#define WARN_LEVEL 8
#define SEVERE_LEVEL 9
#define ERROR_LEVEL 9

// this is correct, to change to this, need to update test
#define KiB 1024LL
Expand Down
34 changes: 6 additions & 28 deletions libCacheSim/include/libCacheSim/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ extern pthread_mutex_t log_mtx;
pthread_mutex_unlock(&log_mtx); \
} while (0)

#if LOGLEVEL <= VVVERBOSE_LEVEL
#define VVVERBOSE(...) LOGGING(VVVERBOSE_LEVEL, __VA_ARGS__)
#else
#define VVVERBOSE(...) \
do { \
} while (0)
#endif

#if LOGLEVEL <= VVERBOSE_LEVEL
#define VVERBOSE(...) LOGGING(VVERBOSE_LEVEL, __VA_ARGS__)
#else
#define VVERBOSE(...) \
do { \
} while (0)
#endif

#if LOGLEVEL <= VERBOSE_LEVEL
#define VERBOSE(...) LOGGING(VERBOSE_LEVEL, __VA_ARGS__)
#else
Expand Down Expand Up @@ -76,11 +60,11 @@ extern pthread_mutex_t log_mtx;
} while (0)
#endif

#if LOGLEVEL <= SEVERE_LEVEL
#define ERROR(...) \
{ \
LOGGING(SEVERE_LEVEL, __VA_ARGS__); \
abort(); \
#if LOGLEVEL <= ERROR_LEVEL
#define ERROR(...) \
{ \
LOGGING(ERROR_LEVEL, __VA_ARGS__); \
abort(); \
}
#else
#define ERROR(...)
Expand Down Expand Up @@ -119,12 +103,6 @@ extern pthread_mutex_t log_mtx;
static inline void log_header(int level, const char *file, int line) {
int n;
switch (level) {
case VVVERBOSE_LEVEL:
n = fprintf(stderr, "%s[VVV] ", CYAN);
break;
case VVERBOSE_LEVEL:
n = fprintf(stderr, "%s[VV] ", CYAN);
break;
case VERBOSE_LEVEL:
n = fprintf(stderr, "%s[VERB] ", MAGENTA);
break;
Expand All @@ -137,7 +115,7 @@ static inline void log_header(int level, const char *file, int line) {
case WARN_LEVEL:
n = fprintf(stderr, "%s[WARN] ", YELLOW);
break;
case SEVERE_LEVEL:
case ERROR_LEVEL:
n = fprintf(stderr, "%s[ERROR] ", RED);
break;
default:
Expand Down
16 changes: 4 additions & 12 deletions libCacheSim/include/libCacheSim/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,16 @@ extern "C" {
#define DEBUG_ASSERT(x)
#endif

// #pragma message "current LOGLEVEL: " XSTR(LOGLEVEL)

#if LOGLEVEL > DEBUG_LEVEL
#define THIS_IS_DEBUG_FUNC return
#else
#define THIS_IS_DEBUG_FUNC
#endif

#if LOGLEVEL > VERBOSE_LEVEL
#define THIS_IS_DEBUG2_FUNC return
#else
#define THIS_IS_DEBUG2_FUNC
#endif

#if LOGLEVEL > VVERBOSE_LEVEL
#define THIS_IS_DEBUG3_FUNC return
#define THIS_IS_VERBOSE_FUNC return
#else
#define THIS_IS_DEBUG3_FUNC
#define THIS_IS_VERBOSE_FUNC
#endif

Comment thread
1a1a11a marked this conversation as resolved.
#define PRINT_ONCE(...) \
Expand Down Expand Up @@ -164,15 +156,15 @@ extern "C" {
// int ffsl(long int i);
// int ffsll(long long int i);

#define find_max(array, n_elem, max_elem_ptr, max_elem_idx_ptr) \
#define FIND_MAX(array, n_elem, max_elem_ptr, max_elem_idx_ptr) \
do { \
*(max_elem_idx_ptr) = 0; \
for (uint64_t i = 0; i < (uint64_t)(n_elem); i++) \
if ((array)[i] > (array)[*(max_elem_idx_ptr)]) *(max_elem_idx_ptr) = i; \
*(max_elem_ptr) = (array)[*(max_elem_idx_ptr)]; \
} while (0)

#define find_min(array, n_elem, min_elem_ptr, min_elem_idx_ptr) \
#define FIND_MIN(array, n_elem, min_elem_ptr, min_elem_idx_ptr) \
do { \
*(min_elem_idx_ptr) = 0; \
for (uint64_t i = 0; i < (uint64_t)(n_elem); i++) \
Expand Down
6 changes: 3 additions & 3 deletions libCacheSim/traceReader/generalReader/txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ int txt_read_one_req(reader_t *const reader, request_t *const req) {
char **buf_ptr = (char **)&reader->line_buf;
size_t *buf_size_ptr = &reader->line_buf_size;
ssize_t read_size = getline(buf_ptr, buf_size_ptr, reader->file);
VVERBOSE("read \"%s\", first char %d, read size %zu, curr pos %zu\n",
reader->line_buf, reader->line_buf[0], read_size,
ftell(reader->file));
VERBOSE("read \"%s\", first char %d, read size %zu, curr pos %zu\n",
reader->line_buf, reader->line_buf[0], read_size,
ftell(reader->file));

while (read_size == 1 && reader->line_buf[0] == '\n') {
// empty line
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/traceReader/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ int read_one_req(reader_t *const reader, request_t *const req) {
sampler_t *sampler = reader->sampler;
reader->sampler = NULL;
while (!sampler->sample(sampler, req)) {
VVERBOSE("skip one req: time %lu, obj_id %lu, size %lu at offset %zu\n",
req->clock_time, req->obj_id, req->obj_size, offset_before_read);
VERBOSE("skip one req: time %lu, obj_id %lu, size %lu at offset %zu\n",
req->clock_time, req->obj_id, req->obj_size, offset_before_read);
if (reader->read_direction == READ_FORWARD) {
status = read_one_req(reader, req);
} else {
Expand All @@ -333,8 +333,8 @@ int read_one_req(reader_t *const reader, request_t *const req) {
req->obj_size = 1;
}

VVERBOSE("read one req: time %lu, obj_id %lu, size %lu at offset %zu\n",
req->clock_time, req->obj_id, req->obj_size, offset_before_read);
VERBOSE("read one req: time %lu, obj_id %lu, size %lu at offset %zu\n",
req->clock_time, req->obj_id, req->obj_size, offset_before_read);

return status;
}
Expand Down
Loading