Skip to content
Open
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: 6 additions & 0 deletions libCacheSim/bin/cli_reader_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ trace_type_e trace_type_str_to_enum(const char *trace_type_str,
}

bool is_true(const char *arg) {
/* options declared OPTION_ARG_OPTIONAL are passed a NULL arg when the bare
* flag is used, e.g. `--verbose`; treat the flag's presence as true */
if (arg == NULL) {
return true;
}

if (strcasecmp(arg, "true") == 0 || strcasecmp(arg, "1") == 0 ||
strcasecmp(arg, "yes") == 0 || strcasecmp(arg, "y") == 0) {
return true;
Expand Down
10 changes: 5 additions & 5 deletions libCacheSim/bin/mrcProfiler/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ static struct argp_option options[] = {
1},

{NULL, 0, NULL, 0, "mrc profiler options:", 0},
{"algo", OPTION_CACHE_ALGORITHM, "LRU", OPTION_ARG_OPTIONAL,
{"algo", OPTION_CACHE_ALGORITHM, "ALGO", 0,
"Which algorithm to profile. Only Support LRU for SHARDS.", 2},
{"size", OPTION_MRC_SIZE, "0.01,1,100", OPTION_ARG_OPTIONAL,
{"size", OPTION_MRC_SIZE, "SIZES", 0,
"MRC profile size. Support two formats "
"[start_size,end_size,#test_points|size1,size2,size3,...,size_n]. For "
"size settings, both explicit sizes (e.g., 1GiB) and WSS-based sizes (a "
"floating-point number between 0 and 1) are supported.",
2},
{"profiler", OPTION_PROFILER, "SHARDS", OPTION_ARG_OPTIONAL,
{"profiler", OPTION_PROFILER, "PROFILER", 0,
"Which profiler to use. Support SHARDS|MINISIM", 2},
{"profiler-params", OPTION_PROFILER_PARAMS, "", OPTION_ARG_OPTIONAL,
{"profiler-params", OPTION_PROFILER_PARAMS, "PARAMS", 0,
"Profiler parameters. ", 2},
{"ignore-obj-size", OPTION_IGNORE_OBJ_SIZE, NULL, OPTION_ARG_OPTIONAL,
"Ignore object size", 2},

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

{"output", OPTION_OUTPUT_PATH, "", OPTION_ARG_OPTIONAL, "Output path", 3},
{"output", OPTION_OUTPUT_PATH, "PATH", 0, "Output path", 3},
{"verbose", OPTION_VERBOSE, NULL, OPTION_ARG_OPTIONAL,
"Produce verbose output", 3},
{NULL, 0, NULL, 0, NULL, 0}};
Expand Down
5 changes: 3 additions & 2 deletions libCacheSim/bin/traceAnalyzer/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static struct argp_option options[] = {

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

{"output", OPTION_OUTPUT_PATH, "", OPTION_ARG_OPTIONAL, "Output path", 8},
{"output", OPTION_OUTPUT_PATH, "PATH", 0, "Output path", 8},
{"verbose", OPTION_VERBOSE, NULL, OPTION_ARG_OPTIONAL,
"Produce verbose output", 8},
{NULL, 0, NULL, 0, NULL, 0}};
Expand Down Expand Up @@ -219,7 +219,8 @@ static char args_doc[] = "trace_path trace_type [--task1] [--task2] ...";

/* Program documentation. */
static char doc[] =
"example: ./bin/traceAnalyzer ../data/trace.vscsi vscsi --common\n\n"
"example: ./bin/traceAnalyzer ../data/cloudPhysicsIO.vscsi vscsi "
"--common\n\n"
"trace_type: txt/csv/twr/vscsi/oracleGeneralBin and more\n"
"if using csv trace, considering specifying -t obj-id-is-num=true\n\n"
"task: "
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/ARC.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ static void ARC_parse_params(cache_t *cache,

if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", ARC_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/ARCv0.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ static void ARCv0_parse_params(cache_t *cache,

if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", ARCv0_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/BeladySize.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ static void BeladySize_parse_params(cache_t *cache,
}
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", BeladySize_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s, support %s\n", cache->cache_name,
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/CAR.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ static void CAR_parse_params(cache_t *cache,
}
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", CAR_current_params(cache, params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s, example parameters %s\n",
Expand Down
7 changes: 6 additions & 1 deletion libCacheSim/cache/eviction/Cacheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ cache_t *Cacheus_init(const common_cache_params_t ccache_params,
const char *cache_specific_params) {
common_cache_params_t updated_cc_params = ccache_params;
/* reduce the hash table size */
updated_cc_params.hashpower -= 2;
/* only shrink an explicitly requested hash power: cache_struct_init reads
* a non-positive value as "use the default", and clamping would turn that
* sentinel into a 16-bucket table. */
if (updated_cc_params.hashpower > 0) {
updated_cc_params.hashpower = MAX(4, updated_cc_params.hashpower - 2);
}

cache_t *cache =
cache_struct_init("Cacheus", updated_cc_params, cache_specific_params);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ static void Clock_parse_params(cache_t *cache,
}
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", Clock_current_params(cache, params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s, example parameters %s\n",
Expand Down
4 changes: 3 additions & 1 deletion libCacheSim/cache/eviction/Clock2QPlus.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ static void Clock2QPlus_parse_params(cache_t *cache,
params_str++;
}

if (key == NULL || value == NULL) {
/* "print" is a bare flag, not a key=value pair */
if (key == NULL || (value == NULL && strcasecmp(key, "print") != 0)) {
ERROR("invalid parameter string: missing key or value\n");
exit(1);
}
Expand All @@ -506,6 +507,7 @@ static void Clock2QPlus_parse_params(cache_t *cache,
params->move_to_main_threshold = atoi(value);
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", Clock2QPlus_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/ClockPro.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static void ClockPro_parse_params(cache_t *cache,
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n",
ClockPro_current_params(cache, params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/FIFO_Merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ static void FIFO_Merge_parse_params(cache_t *cache,
} else if (strcasecmp(key, "print") == 0) {
printf("%s parameters: %s\n", cache->cache_name,
FIFO_Merge_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/FIFO_Reinsertion.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ static void FIFO_Reinsertion_parse_params(cache_t *cache,
} else if (strcasecmp(key, "print") == 0) {
printf("%s parameters: %s\n", cache->cache_name,
FIFO_Reinsertion_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
4 changes: 4 additions & 0 deletions libCacheSim/cache/eviction/GLCache/GLCache.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const char *GLCache_default_params(void) {
static void GLCache_parse_init_params(const char *cache_specific_params,
GLCache_params_t *params) {
char *params_str = strdup(cache_specific_params);
char *old_params_str = params_str;

while (params_str != NULL && params_str[0] != '\0') {
char *key = strsep((char **)&params_str, "=");
Expand Down Expand Up @@ -104,13 +105,16 @@ static void GLCache_parse_init_params(const char *cache_specific_params,
} else if (strcasecmp(key, "print") == 0 ||
strcasecmp(key, "default") == 0) {
printf("default params: %s\n", GLCache_default_params());
free(old_params_str);
exit(0);
} else {
ERROR("GLCache does not have parameter %s\n", key);
printf("default params: %s\n", GLCache_default_params());
free(old_params_str);
exit(1);
}
}
free(old_params_str);
}

// ***********************************************************************
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/Hyperbolic.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ static void Hyperbolic_parse_params(cache_t *cache,
}
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", Hyperbolic_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s, support %s\n", cache->cache_name,
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/LRUProb.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ static void LRU_Prob_parse_params(cache_t *cache,

} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", LRU_Prob_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/LeCaR.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ static void LeCaR_parse_params(cache_t *cache,
params->w_lru = (double)strtod(value, &end);
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", LeCaR_current_params(cache, params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/MQ.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ static void MQ_parse_params(cache_t *cache, const char *cache_specific_params) {
}
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", MQ_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
7 changes: 6 additions & 1 deletion libCacheSim/cache/eviction/QDLP.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,12 @@ static inline bool QDLP_can_insert(cache_t *cache, const request_t *req) {
// ***********************************************************************
static const char *QDLP_current_params(QDLP_params_t *params) {
static __thread char params_str[128];
/* main_cache is only built after the parameters are parsed, so report the
* configured type, which is what `-e print` runs against */
snprintf(params_str, 128, "fifo-size-ratio=%.4lf,main-cache=%s\n",
params->small_size_ratio, params->main_cache->cache_name);
params->small_size_ratio,
params->main_cache == NULL ? params->main_cache_type
: params->main_cache->cache_name);
return params_str;
}

Expand Down Expand Up @@ -470,6 +474,7 @@ static void QDLP_parse_params(cache_t *cache,
strncpy(params->main_cache_type, value, 30);
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", QDLP_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
2 changes: 2 additions & 0 deletions libCacheSim/cache/eviction/RandomLRU.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ cache_t *RandomLRU_init(const common_cache_params_t ccache_params,
static void RandomLRU_free(cache_t *cache) {
RandomLRU_params_t *params = (RandomLRU_params_t *)(cache->eviction_params);
free(params->eviction_candidates);
free(params);
cache_struct_free(cache);
}

Expand Down Expand Up @@ -273,6 +274,7 @@ static void RandomLRU_parse_params(cache_t *cache,
params->n_samples = (int)strtol(value, &end, 0);
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: n-samples=%d\n", params->n_samples);
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
1 change: 1 addition & 0 deletions libCacheSim/cache/eviction/S3FIFO.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ static void S3FIFO_parse_params(cache_t *cache,
params->move_to_main_threshold = atoi(value);
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", S3FIFO_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
16 changes: 14 additions & 2 deletions libCacheSim/cache/eviction/S3FIFOd.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ cache_t *S3FIFOd_init(const common_cache_params_t ccache_params,
}

ccache_params_local.cache_size = ccache_params.cache_size / 10;
ccache_params_local.hashpower -= 4;
/* see Cacheus_init: a non-positive hash power is the "use the default"
* sentinel and must survive untouched. */
if (ccache_params_local.hashpower > 0) {
ccache_params_local.hashpower = MAX(4, ccache_params_local.hashpower - 4);
}
params->small_eviction = FIFO_init(ccache_params_local, NULL);
params->main_eviction = FIFO_init(ccache_params_local, NULL);
snprintf(params->small_eviction->cache_name, CACHE_NAME_ARRAY_LEN,
Expand Down Expand Up @@ -185,6 +189,9 @@ static void S3FIFOd_free(cache_t *cache) {
params->small_fifo->cache_free(params->small_fifo);
params->ghost_fifo->cache_free(params->ghost_fifo);
params->main_fifo->cache_free(params->main_fifo);
/* init also builds these two to track evicted objects */
params->small_eviction->cache_free(params->small_eviction);
params->main_eviction->cache_free(params->main_eviction);
free(cache->eviction_params);
cache_struct_free(cache);
}
Expand Down Expand Up @@ -530,8 +537,12 @@ static inline bool S3FIFOd_can_insert(cache_t *cache, const request_t *req) {
// ***********************************************************************
static const char *S3FIFOd_current_params(S3FIFOd_params_t *params) {
static __thread char params_str[128];
/* main_fifo is only built after the parameters are parsed, so report the
* configured type, which is what `-e print` runs against */
snprintf(params_str, 128, "fifo-size-ratio=%.4lf,main-cache=%s\n",
params->small_fifo_size_ratio, params->main_fifo->cache_name);
params->small_fifo_size_ratio,
params->main_fifo == NULL ? params->main_fifo_type
: params->main_fifo->cache_name);
return params_str;
}

Expand Down Expand Up @@ -563,6 +574,7 @@ static void S3FIFOd_parse_params(cache_t *cache,
params->move_to_main_threshold = atoi(value);
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", S3FIFOd_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
7 changes: 6 additions & 1 deletion libCacheSim/cache/eviction/S3FIFOv0.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,12 @@ static inline bool S3FIFOv0_can_insert(cache_t *cache, const request_t *req) {
// ***********************************************************************
static const char *S3FIFOv0_current_params(S3FIFOv0_params_t *params) {
static __thread char params_str[128];
/* main_fifo is only built after the parameters are parsed, so it is still
* NULL when the user asks for the parameters with `-e print`; it is always a
* plain FIFO in this variant */
snprintf(params_str, 128, "small-size-ratio=%.4lf,main-cache=%s\n",
params->small_size_ratio, params->main_fifo->cache_name);
params->small_size_ratio,
params->main_fifo == NULL ? "FIFO" : params->main_fifo->cache_name);
return params_str;
}

Expand Down Expand Up @@ -510,6 +514,7 @@ static void S3FIFOv0_parse_params(cache_t *cache,
params->move_to_main_threshold = atoi(value);
} else if (strcasecmp(key, "print") == 0) {
printf("parameters: %s\n", S3FIFOv0_current_params(params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
36 changes: 31 additions & 5 deletions libCacheSim/cache/eviction/SLRU.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,28 @@ static bool SLRU_remove(cache_t *cache, obj_id_t obj_id) {
// **** parameter set up functions ****
// **** ****
// ***********************************************************************
/* share of the cache given to one segment, in percent. lru_max_n_bytes is only
* allocated after the parameters are parsed, so it is still NULL when the user
* asks for the parameters with `-e print`; until seg-size says otherwise the
* segments are evenly sized */
static int SLRU_seg_pct(const cache_t *cache, const SLRU_params_t *params,
const int seg) {
if (params->lru_max_n_bytes == NULL) {
return 100 / params->n_seg;
}
return (int)(params->lru_max_n_bytes[seg] * 100 / cache->cache_size);
}

static const char *SLRU_current_params(cache_t *cache, SLRU_params_t *params) {
static __thread char params_str[128];
int n = snprintf(params_str, 128, "n-seg=%d,seg-size=%d", params->n_seg,
(int)(params->lru_max_n_bytes[0] * 100 / cache->cache_size));

for (int i = 1; i < params->n_seg; i++) {
n += snprintf(params_str + n, 128 - n, ":%d",
(int)(params->lru_max_n_bytes[i] * 100 / cache->cache_size));
int n = snprintf(params_str, sizeof(params_str), "n-seg=%d,seg-size=%d",
params->n_seg, SLRU_seg_pct(cache, params, 0));

for (int i = 1; i < params->n_seg && n > 0 && n < (int)sizeof(params_str);
i++) {
n += snprintf(params_str + n, sizeof(params_str) - n, ":%d",
SLRU_seg_pct(cache, params, i));
}

return params_str;
Expand Down Expand Up @@ -439,16 +453,27 @@ static void SLRU_parse_params(cache_t *cache,
if (strlen(end) > 2) {
ERROR("param parsing error, find string \"%s\" after number\n", end);
}
/* n_seg divides the cache size and the reported percentages */
if (params->n_seg < 1 || params->n_seg > SLRU_MAX_N_SEG) {
ERROR("n-seg must be between 1 and %d, got %d\n", SLRU_MAX_N_SEG,
params->n_seg);
}
} else if (strcasecmp(key, "seg-size") == 0) {
int n_seg = 0;
int64_t seg_size_sum = 0;
int64_t seg_size_array[SLRU_MAX_N_SEG];
char *v = strsep((char **)&value, ":");
while (v != NULL) {
if (n_seg >= SLRU_MAX_N_SEG) {
ERROR("seg-size accepts at most %d segments\n", SLRU_MAX_N_SEG);
}
seg_size_array[n_seg++] = (int64_t)strtol(v, &end, 0);
seg_size_sum += seg_size_array[n_seg - 1];
v = strsep((char **)&value, ":");
}
if (n_seg < 1 || seg_size_sum <= 0) {
ERROR("seg-size needs at least one segment with a positive size\n");
}
params->n_seg = n_seg;
params->lru_max_n_bytes = calloc(params->n_seg, sizeof(int64_t));
for (int i = 0; i < n_seg; i++) {
Expand All @@ -462,6 +487,7 @@ static void SLRU_parse_params(cache_t *cache,
}
} else if (strcasecmp(key, "print") == 0) {
printf("current parameters: %s\n", SLRU_current_params(cache, params));
free(old_params_str);
exit(0);
} else {
ERROR("%s does not have parameter %s\n", cache->cache_name, key);
Expand Down
Loading
Loading