diff --git a/doc/quickstart_cachesim.md b/doc/quickstart_cachesim.md index a87f4a1c0..91747fdde 100644 --- a/doc/quickstart_cachesim.md +++ b/doc/quickstart_cachesim.md @@ -192,8 +192,10 @@ You can use `-p` or `--prefetch` to set the prefetching algorithm. # use part of the trace to warm up the cache ./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru 1gb --warmup-sec=86400 -# Use TTL -./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru 1gb --use-ttl=true +# TTL: a build with -DSUPPORT_TTL=ON uses the TTL in the trace by default; +# --use-ttl=false replays the trace as if it carried no TTL. A build without +# SUPPORT_TTL ignores TTLs and rejects --use-ttl=true +./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru 1gb --use-ttl=false # Disable the print of the first few requests ./bin/cachesim ../data/cloudPhysicsIO.vscsi vscsi lru 1gb --print-head-req=false diff --git a/libCacheSim/bin/MRC/parser_mini.c b/libCacheSim/bin/MRC/parser_mini.c index 156498382..a3a7e6556 100644 --- a/libCacheSim/bin/MRC/parser_mini.c +++ b/libCacheSim/bin/MRC/parser_mini.c @@ -85,7 +85,9 @@ static struct argp_option options[] = { {"report-interval", OPTION_REPORT_INTERVAL, "3600", 0, "how often to report stat when running one cache", 10}, {"warmup-sec", OPTION_WARMUP_SEC, "0", 0, "warm up time in seconds", 10}, - {"use-ttl", OPTION_USE_TTL, "false", 0, "specify to use ttl from the trace", + {"use-ttl", OPTION_USE_TTL, "true|false", 0, + "use the TTL in the trace (default: true in builds with SUPPORT_TTL, " + "which true requires)", 10}, {"consider-obj-metadata", OPTION_CONSIDER_OBJ_METADATA, "false", 0, "Whether consider per object metadata size in the simulated cache", 10}, @@ -145,6 +147,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { break; case OPTION_USE_TTL: arguments->use_ttl = is_true(arg) ? true : false; +#ifndef SUPPORT_TTL + if (arguments->use_ttl) + argp_error(state, + "error: --use-ttl true needs a build with -DSUPPORT_TTL=ON"); +#endif break; case OPTION_REPORT_INTERVAL: arguments->report_interval = atol(arg); @@ -218,7 +225,11 @@ static void init_mini_arg(struct MINI_arguments *args) { args->trace_type_str = NULL; args->trace_type_params = NULL; args->verbose = true; +#ifdef SUPPORT_TTL + args->use_ttl = true; +#else args->use_ttl = false; +#endif args->ignore_obj_size = false; args->consider_obj_metadata = false; args->report_interval = 3600 * 24; @@ -303,6 +314,7 @@ void parse_mini_cmd(int argc, char *argv[], struct MINI_arguments *args) { reader_init_params.obj_id_is_num = true; reader_init_params.cap_at_n_req = args->n_req; reader_init_params.sampler = NULL; + reader_init_params.ignore_ttl = !args->use_ttl; parse_reader_params(args->trace_type_params, &reader_init_params); @@ -542,8 +554,10 @@ void print_parsed_args(struct MINI_arguments *args) { n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", eviction-params: %s", args->eviction_params); - if (args->use_ttl) - n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", use ttl"); +#ifdef SUPPORT_TTL + if (!args->use_ttl) + n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", ignore ttl"); +#endif if (args->ignore_obj_size) n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, diff --git a/libCacheSim/bin/cachesim/cli_parser.c b/libCacheSim/bin/cachesim/cli_parser.c index 0bfdb9032..14d3b83ba 100644 --- a/libCacheSim/bin/cachesim/cli_parser.c +++ b/libCacheSim/bin/cachesim/cli_parser.c @@ -93,7 +93,9 @@ static struct argp_option options[] = { {"report-interval", OPTION_REPORT_INTERVAL, "3600", 0, "how often to report stat when running one cache", 10}, {"warmup-sec", OPTION_WARMUP_SEC, "0", 0, "warm up time in seconds", 10}, - {"use-ttl", OPTION_USE_TTL, "false", 0, "specify to use ttl from the trace", + {"use-ttl", OPTION_USE_TTL, "true|false", 0, + "use the TTL in the trace (default: true in builds with SUPPORT_TTL, " + "which true requires)", 10}, {"consider-obj-metadata", OPTION_CONSIDER_OBJ_METADATA, "false", 0, "Whether consider per object metadata size in the simulated cache", 10}, @@ -176,6 +178,11 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { break; case OPTION_USE_TTL: arguments->use_ttl = is_true(arg) ? true : false; +#ifndef SUPPORT_TTL + if (arguments->use_ttl) + argp_error(state, + "error: --use-ttl true needs a build with -DSUPPORT_TTL=ON"); +#endif break; case OPTION_REPORT_INTERVAL: arguments->report_interval = @@ -274,7 +281,11 @@ static void init_arg(struct arguments *args) { args->trace_type_str = NULL; args->trace_type_params = NULL; args->verbose = true; +#ifdef SUPPORT_TTL + args->use_ttl = true; +#else args->use_ttl = false; +#endif args->ignore_obj_size = false; args->consider_obj_metadata = false; args->hashpower = DEFAULT_HASHPOWER; @@ -367,6 +378,7 @@ void parse_cmd(int argc, char *argv[], struct arguments *args) { reader_init_params.obj_id_is_num = true; reader_init_params.cap_at_n_req = args->n_req; reader_init_params.sampler = NULL; + reader_init_params.ignore_ttl = !args->use_ttl; parse_reader_params(args->trace_type_params, &reader_init_params); @@ -632,8 +644,10 @@ void print_parsed_args(struct arguments *args) { n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", hashpower %d", args->hashpower); - if (args->use_ttl) - n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", use ttl"); +#ifdef SUPPORT_TTL + if (!args->use_ttl) + n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, ", ignore ttl"); +#endif if (args->ignore_obj_size) n += snprintf(output_str + n, OUTPUT_STR_LEN - n - 1, diff --git a/libCacheSim/include/libCacheSim/reader.h b/libCacheSim/include/libCacheSim/reader.h index a95577bca..9b08f7c4d 100644 --- a/libCacheSim/include/libCacheSim/reader.h +++ b/libCacheSim/include/libCacheSim/reader.h @@ -83,6 +83,10 @@ typedef struct { /* Reject oracle filtering that invalidates future-access metadata. * Offline-policy callers should enable this before reading or cloning. */ bool require_valid_next_access; + + // if true, drop the TTL of every request (req->ttl = 0), so a build with + // SUPPORT_TTL replays the trace as if it carried no TTL + bool ignore_ttl; } reader_init_param_t; enum read_direction { diff --git a/libCacheSim/traceReader/readerRequest.c b/libCacheSim/traceReader/readerRequest.c index 3e28a055e..16b2275ff 100644 --- a/libCacheSim/traceReader/readerRequest.c +++ b/libCacheSim/traceReader/readerRequest.c @@ -136,6 +136,10 @@ int read_one_req(reader_t *const reader, request_t *const req) { req->obj_size = 1; } + if (reader->init_params.ignore_ttl) { + req->ttl = 0; + } + /* lcp derives cost from block position rather than from a column */ if (reader->init_params.obj_cost_field <= 0 && reader->trace_type != LCP_TRACE) { diff --git a/test/test_cli.sh b/test/test_cli.sh index 3b7e88b18..e938c0ef6 100755 --- a/test/test_cli.sh +++ b/test/test_cli.sh @@ -223,6 +223,29 @@ expect_output "cachesim hashes string object ids" "miss ratio 0\.6667" \ "${BIN_DIR}/cachesim" str-ids.csv csv lru 1mb \ -t "time-col=1,obj-id-col=2,obj-size-col=3,has-header=true" +# --use-ttl. Object 1 has a TTL of 5 and is read again at t=10. Without TTLs +# that read hits (two misses in three requests); with TTLs it misses. +cat >ttl.csv <<'CSV' +time,id,size,ttl +1,1,100,5 +2,2,100,0 +10,1,100,0 +CSV +TTL_FMT="time-col=1,obj-id-col=2,obj-size-col=3,ttl-col=4,has-header=true" +# A build without SUPPORT_TTL rejects --use-ttl=true; probe it on a trace +# without TTLs, since an expired read crashes TTL builds until #349 is fixed. +if "${BIN_DIR}/cachesim" str-ids.csv csv lru 1mb --use-ttl=true \ + -t "time-col=1,obj-id-col=2,obj-size-col=3,has-header=true" 2>&1 | + grep -q "SUPPORT_TTL"; then + expect_clean_error "cachesim --use-ttl=true without SUPPORT_TTL" \ + "${BIN_DIR}/cachesim" ttl.csv csv lru 1mb -t "${TTL_FMT}" --use-ttl=true + expect_output "cachesim ignores TTLs without SUPPORT_TTL" "miss ratio 0\.6667" \ + "${BIN_DIR}/cachesim" ttl.csv csv lru 1mb -t "${TTL_FMT}" +else + expect_output "cachesim --use-ttl=false drops the trace TTL" "miss ratio 0\.6667" \ + "${BIN_DIR}/cachesim" ttl.csv csv lru 1mb -t "${TTL_FMT}" --use-ttl=false +fi + echo "running synthetic reader tests" for spec in Uniform_1000_10 Zipf_1000_10_0 Zipf_1000_10_1 \ Zipf_1000_10_1.2_42 Zipf_1000_10_.5 Zipf_1000_10_1e-310; do