Skip to content

Commit

Permalink
many fixes
Browse files Browse the repository at this point in the history
* fix compile warnning and errors
* fix bugs in CMakeLists
* remove xxhash from source and use system-level xxhash so that macos can compile
* change global variable names
* add n_core function for macos
  • Loading branch information
1a1a11a committed Jan 6, 2024
1 parent 938165f commit 3b0c681
Show file tree
Hide file tree
Showing 26 changed files with 239 additions and 141 deletions.
35 changes: 15 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ set_property(CACHE LOG_LEVEL PROPERTY STRINGS INFO WARN ERROR DEBUG VERBOSE VVER
# detect platform #
########################################
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message(STATUS "Mac OS X detected, version ${CMAKE_SYSTEM_VERSION}")
add_definitions(-DOS_DARWIN)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "/opt/homebrew/include/")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/homebrew/")

elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# set(CFLAGS "$ENV{CFLAGS} " "-Wl,--export-dynamic ")
Expand Down Expand Up @@ -121,7 +121,6 @@ set(CFLAGS "$ENV{CFLAGS} "
# "-Wmissing-prototypes "
"-Wmissing-declarations "
"-Wredundant-decls "
"-Wunused-value -Wunused-variable "
"-fno-strict-aliasing "
)

Expand All @@ -142,21 +141,22 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(GLib REQUIRED)
include_directories(${GLib_INCLUDE_DIRS})
set(LIBS ${LIBS} ${GLib_LIBRARY})
#if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# pkg_check_modules(GLib2 REQUIRED Glib-2.0)
# include_directories(${GLib2_INCLUDE_DIRS})
# # add_compile_options("${LDFLAGS}")
# link_libraries(${GLib2_LDFLAGS})
#endif()


find_package(argp REQUIRED)
include_directories(${ARGP_INCLUDE_DIRS})
set(LIBS ${LIBS} ${ARGP_LIBRARY})

if (OPT_SUPPORT_ZSTD_TRACE)
add_compile_definitions(SUPPORT_ZSTD_TRACE=1)
find_package(ZSTD)
# https://stackoverflow.com/questions/61377055/cannot-find-gflags-gflags-h-while-building-library-osx/61379123#61379123
include_directories(${ZSTD_INCLUDE_DIR})
if ("${ZSTD_LIBRARIES}" STREQUAL "")
message(FATAL_ERROR "zstd not found")
endif()
link_libraries(${ZSTD_LIBRARIES})
message(STATUS "ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIRS}, ZSTD_LIBRARIES ${ZSTD_LIBRARIES}")
message(STATUS "ZSTD_INCLUDE_DIR ${ZSTD_INCLUDE_DIR}, ZSTD_LIBRARIES ${ZSTD_LIBRARIES}")
else()
remove_definitions(SUPPORT_ZSTD_TRACE)
endif(OPT_SUPPORT_ZSTD_TRACE)
Expand Down Expand Up @@ -224,7 +224,7 @@ message(STATUS "<<++=====------------------/\\------------------=====++>>")
message(STATUS "================== dependency related ==================")
message(STATUS "glib found? ${GLib_FOUND} - LIBS=${GLib_LIBRARY}, header =${GLib_INCLUDE_DIRS}")
message(STATUS "tcmalloc found? ${Tcmalloc_FOUND} - LIBS=${Tcmalloc_LIBRARIES}, header=${Tcmalloc_INCLUDE_DIRS}")
message(STATUS "ZSTD found? ${ZSTD_FOUND} - LIBS=${ZSTD_LIBRARIES}, header=${ZSTD_INCLUDE_DIRS}")
message(STATUS "ZSTD found? ${ZSTD_FOUND} - LIBS=${ZSTD_LIBRARIES}, header=${ZSTD_INCLUDE_DIR}")

message(STATUS "==================== CMake related =====================")
message(STATUS "platform = ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
Expand Down Expand Up @@ -330,7 +330,7 @@ endif(OPT_SUPPORT_ZSTD_TRACE)
file(GLOB dataStructure_source
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/*.c
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/hashtable/*.c
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/hash/*.c
${PROJECT_SOURCE_DIR}/libCacheSim/dataStructure/hash/murmur3.c
)

file(GLOB profiler_source
Expand All @@ -347,7 +347,8 @@ set(LIB_SOURCE ${LIB_SOURCE} ${cache_source} ${reader_source} ${dataStructure_so
# # https://stackoverflow.com/questions/32469953/why-is-cmake-designed-so-that-it-removes-runtime-path-when-installing
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

add_library(${PROJECT_NAME} SHARED ${LIB_SOURCE})
add_library(${PROJECT_NAME} ${LIB_SOURCE})
# add_library(${PROJECT_NAME} SHARED ${LIB_SOURCE})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION})
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/libCacheSim/include/libCacheSim.h)
Expand All @@ -366,12 +367,6 @@ install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})



# #target_compile_definitions(binBenchmark PRIVATE HASH=0xb2)
# #add_executable(binBenchmark libCacheSim/benchmark/main.c)
# #target_link_libraries(binBenchmark benchmark cachelib evictionAlgos traceReader profiler dataStructure utils
# # ${LIBS})
#############################


Expand Down
84 changes: 84 additions & 0 deletions cmake/Modules/Findargp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# - try to find the argp library/component of glibc
#
# Users may optionally supply:
# ARGP_ROOT_DIR - a prefix to start searching.
#
# Cache Variables: (probably not for direct use in your scripts)
# ARGP_INCLUDE_DIR
# ARGP_LIBRARY, only defined if linking to an extra library is required
#
# Non-cache variables you might use in your CMakeLists.txt:
# ARGP_FOUND
# ARGP_INCLUDE_DIRS
# ARGP_LIBRARIES
#
# Requires these CMake modules:
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
#
# Original Author:
# 2009-2010 Rylie Pavlik <rylie@ryliepavlik.com>
# https://ryliepavlik.com/
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright 2009-2010, Iowa State University
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# SPDX-License-Identifier: BSL-1.0

set(ARGP_ROOT_DIR
"${ARGP_ROOT_DIR}"
CACHE
PATH
"Path to search for ARGP library")

###
# Configure ARGP
###
set(_check ARGP_INCLUDE_DIR)

find_path(ARGP_INCLUDE_DIR
NAMES
argp.h
HINTS
"${ARGP_ROOT_DIR}"
PATHS
/usr/local
/opt/local
/sw)
mark_as_advanced(ARGP_INCLUDE_DIR)

include(CheckFunctionExists)
check_function_exists(argp_parse ARGP_BUILTIN)

if(NOT ARGP_BUILTIN)
find_library(ARGP_LIBRARY
NAMES
argp
HINTS
"${ARGP_ROOT_DIR}"
PATH_SUFFIXES
lib
lib64
PATHS
/usr/local
/opt/local
/sw)
list(APPEND _check ARGP_LIBRARY)
mark_as_advanced(ARGP_LIBRARY)
endif()

# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(argp
DEFAULT_MSG
${_check})

if(ARGP_FOUND)
set(ARGP_INCLUDE_DIRS "${ARGP_INCLUDE_DIR}")
set(ARGP_LIBRARIES "${ARGP_LIBRARY}")
mark_as_advanced(ARGP_ROOT_DIR)
endif()
4 changes: 2 additions & 2 deletions libCacheSim/bin/cachesim/cli_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static void set_cache_size(struct arguments *args, reader_t *reader) {
args->n_cache_size = n_cache_sizes;

if (args->n_cache_size == 0) {
printf("working set %ld too small\n", wss);
printf("working set %ld too small\n", (long) wss);
exit(0);
}
}
Expand All @@ -494,7 +494,7 @@ void print_parsed_args(struct arguments *args) {
output_str, OUTPUT_STR_LEN - 1,
"trace path: %s, trace_type %s, ofilepath "
"%s, %d threads, warmup %d sec, total %d algo x %d size = %d caches",
args->trace_path, trace_type_str[args->trace_type], args->ofilepath,
args->trace_path, g_trace_type_name[args->trace_type], args->ofilepath,
args->n_thread, args->warmup_sec, args->n_eviction_algo,
args->n_cache_size, args->n_eviction_algo * args->n_cache_size);

Expand Down
11 changes: 6 additions & 5 deletions libCacheSim/bin/cli_reader_utils.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@


#define _GNU_SOURCE
#include "cli_reader_utils.h"

#include <assert.h>
#include <string.h>

#include "../include/libCacheSim/reader.h"
#include "../utils/include/mystr.h"
#include "cli_reader_utils.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -60,11 +59,12 @@ trace_type_e trace_type_str_to_enum(const char *trace_type_str,
return ORACLE_CF1_TRACE;
} else if (strcasecmp(trace_type_str, "oracleSysTwrNS") == 0) {
return ORACLE_SYS_TWRNS_TRACE;
} else if (strcasecmp(trace_type_str, "valpinTrace") == 0){
} else if (strcasecmp(trace_type_str, "valpinTrace") == 0) {
return VALPIN_TRACE;
} else {
ERROR("unsupported trace type: %s\n", trace_type_str);
}
return UNKNOWN_TRACE;
}

bool is_true(const char *arg) {
Expand Down Expand Up @@ -215,7 +215,7 @@ trace_type_e detect_trace_type(const char *trace_path) {
trace_type = UNKNOWN_TRACE;
}

INFO("detecting trace type: %s\n", trace_type_str[trace_type]);
INFO("detecting trace type: %s\n", g_trace_type_name[trace_type]);
return trace_type;
}

Expand Down Expand Up @@ -276,7 +276,8 @@ void cal_working_set_size(reader_t *reader, int64_t *wss_obj,
}
*wss_obj *= scaling_factor;
*wss_byte *= scaling_factor;
INFO("working set size: %ld object %ld byte\n", *wss_obj, *wss_byte);
INFO("working set size: %ld object %ld byte\n", (long)*wss_obj,
(long)*wss_byte);

free_request(req);
reset_reader(reader);
Expand Down
6 changes: 3 additions & 3 deletions libCacheSim/bin/traceAnalyzer/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ enum argp_option_short {
static struct argp_option options[] = {
{NULL, 0, NULL, 0, "trace reader related parameters:", 0},
{"trace-type-params", OPTION_TRACE_TYPE_PARAMS,
"time-col=1,obj-id-col=2,obj-size-col=3,delimiter=,", NULL,
"time-col=1,obj-id-col=2,obj-size-col=3,delimiter=,", 0,
"Parameters used for csv trace", 1},
{"num-req", OPTION_NUM_REQ, 0, NULL,
{"num-req", OPTION_NUM_REQ, 0, 0,
"Num of requests to process, default -1 means all requests in the trace",
1},

Expand Down Expand Up @@ -112,7 +112,7 @@ static struct argp_option options[] = {

{NULL, 0, NULL, 0, "common parameters:", 0},

{"output", OPTION_OUTPUT_PATH, "", NULL, "Output path", 8},
{"output", OPTION_OUTPUT_PATH, "", OPTION_ARG_OPTIONAL, "Output path", 8},
{"verbose", OPTION_VERBOSE, NULL, OPTION_ARG_OPTIONAL,
"Produce verbose output", 8},
{0}};
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/bin/traceUtils/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void print_parsed_arg(struct arguments *args) {
int n = 0;
char output_str[OUTPUT_STR_LEN];
n = snprintf(output_str, OUTPUT_STR_LEN - 1, "trace path: %s, trace_type %s",
args->trace_path, trace_type_str[args->trace_type]);
args->trace_path, g_trace_type_name[args->trace_type]);

if (args->trace_type_params != NULL)
n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1,
Expand Down
8 changes: 4 additions & 4 deletions libCacheSim/bin/traceUtils/traceConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void convert_to_oracleGeneral(reader_t *reader, std::string ofilepath,
"%s: %ld M requests (%.2lf GB), trace time %ld, working set %lld "
"object, %lld B (%.2lf GB)\n",
reader->trace_path, (long)(n_req_curr / 1e6),
(double)total_bytes / GiB, start_ts - req->clock_time,
(double)total_bytes / GiB, (long)(start_ts - req->clock_time),
(long long)n_obj, (long long)unique_bytes,
(double)unique_bytes / GiB);
}
Expand All @@ -118,8 +118,8 @@ void convert_to_oracleGeneral(reader_t *reader, std::string ofilepath,
"%s: %ld M requests (%.2lf GB), trace time %ld, working set %lld "
"object, %lld B (%.2lf GB), reversing output...\n",
reader->trace_path, (long)(n_req_curr / 1e6), (double)total_bytes / GiB,
start_ts - req->clock_time, (long long)n_obj, (long long)unique_bytes,
(double)unique_bytes / GiB);
(long)(start_ts - req->clock_time), (long long)n_obj,
(long long)unique_bytes, (double)unique_bytes / GiB);

struct trace_stat stat;
stat.n_req = n_req_curr;
Expand Down Expand Up @@ -251,6 +251,6 @@ static void _reverse_file(std::string ofilepath, struct trace_stat stat,
remove((ofilepath + ".reverse").c_str());

INFO("trace conversion finished, %ld requests %ld objects, output %s\n",
n_req, stat.n_obj, ofilepath.c_str());
(long) n_req, (long) stat.n_obj, ofilepath.c_str());
}
} // namespace traceConv
2 changes: 1 addition & 1 deletion libCacheSim/bin/traceUtils/traceConvMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) {
struct arguments args;

cli::parse_cmd(argc, argv, &args);
if (args.ofilepath == NULL) {
if (strlen(args.ofilepath) == 0) {
snprintf(args.ofilepath, OFILEPATH_LEN, "%s.oracleGeneral", args.trace_path);
}

Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/bin/traceUtils/traceFilterMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void filter(reader_t *reader, cache_t *cache, std::string ofilepath) {
read_one_req(reader, req);
}

INFO("write %ld/%ld %.4lf requests to file %s\n", n_written_req, n_req,
INFO("write %ld/%ld %.4lf requests to file %s\n", (long) n_written_req, (long) n_req,
(double)n_written_req / n_req, ofilepath.c_str());
free_request(req);
output_file.close();
Expand Down
3 changes: 2 additions & 1 deletion libCacheSim/cache/eviction/CR_LFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ static void free_list_node(void *list_node) {
*/
cache_t *CR_LFU_init(const common_cache_params_t ccache_params,
const char *cache_specific_params) {
cache_t *cache = cache_struct_init("CR_LFU", ccache_params, cache_specific_params);
cache_t *cache =
cache_struct_init("CR_LFU", ccache_params, cache_specific_params);
cache->cache_init = CR_LFU_init;
cache->cache_free = CR_LFU_free;
cache->get = CR_LFU_get;
Expand Down
2 changes: 1 addition & 1 deletion libCacheSim/cache/eviction/LIRS.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ bool LIRS_can_insert(cache_t *cache, const request_t *req) {

INFO("LIRS_can_insert: should not reach here. n_req = %ld\n",
(long)cache->n_req);
assert(false);
abort();
}

static void LIRS_prune(cache_t *cache) {
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/WTinyLFU.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ cache_obj_t *WTinyLFU_insert(cache_t *cache, const request_t *req) {
static cache_obj_t *WTinyLFU_to_evict(cache_t *cache, const request_t *req) {
// Warning: don't use this function
DEBUG_ASSERT(false);
return NULL;
}

static void WTinyLFU_evict(cache_t *cache, const request_t *req) {
Expand Down
13 changes: 7 additions & 6 deletions libCacheSim/cache/eviction/nop.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ static bool nop_get(cache_t *cache, const request_t *req) {
*/
static cache_obj_t *nop_find(cache_t *cache, const request_t *req,
const bool update_cache) {
// cache_obj_t *cache_obj = cache_find_base(cache, req, update_cache);
// cache_obj_t *cache_obj = cache_find_base(cache, req, update_cache);

// return cache_obj;
// return cache_obj;
return NULL;
}

Expand All @@ -130,9 +130,9 @@ static cache_obj_t *nop_find(cache_t *cache, const request_t *req,
* @return the inserted object
*/
static cache_obj_t *nop_insert(cache_t *cache, const request_t *req) {
// cache_obj_t *obj = cache_insert_base(cache, req);
// cache_obj_t *obj = cache_insert_base(cache, req);

// return obj;
// return obj;
return NULL;
}

Expand All @@ -147,7 +147,8 @@ static cache_obj_t *nop_insert(cache_t *cache, const request_t *req) {
* @return the object to be evicted
*/
static cache_obj_t *nop_to_evict(cache_t *cache, const request_t *req) {
assert(false);
assert(false);
return NULL;
}

/**
Expand All @@ -159,7 +160,7 @@ static cache_obj_t *nop_to_evict(cache_t *cache, const request_t *req) {
* @param req not used
*/
static void nop_evict(cache_t *cache, const request_t *req) {
// cache_evict_base(cache, obj_to_evict, true);
// cache_evict_base(cache, obj_to_evict, true);
}

/**
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/priv/QDLPv0.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ static cache_obj_t *QDLPv0_to_evict(cache_t *cache, const request_t *req) {
// not implemented, we need to evict from the clock cache
assert(0);
}
return NULL;
}

/**
Expand Down

0 comments on commit 3b0c681

Please sign in to comment.