Skip to content

Commit 2a9885e

Browse files
committed
Add request cost support alongside object size
1 parent 6ec428d commit 2a9885e

9 files changed

Lines changed: 66 additions & 10 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Run the example traces using the LRU eviction algorithm and a 1 GB cache size.
164164
./bin/cachesim ../data/trace.vscsi vscsi lru 1000,16000 --ignore-obj-size 1
165165

166166
# use a csv trace, note the quotation marks when you have multiple options
167-
./bin/cachesim ../data/trace.csv csv lru 1gb -t "time-col=2, obj-id-col=5, obj-size-col=4"
167+
./bin/cachesim ../data/trace.csv csv lru 1gb -t "time-col=2, obj-id-col=5, obj-size-col=4, obj-cost-col=6"
168168

169169
# use a csv trace with more options
170170
./bin/cachesim ../data/trace.csv csv lru 1gb -t "time-col=2, obj-id-col=5, obj-size-col=4, delimiter=,, has-header=true"
@@ -189,7 +189,7 @@ You can plot miss ratios of different algorithms and sizes, and plot the miss ra
189189
```bash
190190
# plot miss ratio over size
191191
cd scripts
192-
python3 plot_mrc_size.py --tracepath ../data/twitter_cluster52.csv --trace-format csv --trace-format-params="time-col=1,obj-id-col=2,obj-size-col=3,delimiter=," --algos=fifo,lru,lecar,s3fifo --sizes=0.001,0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.3,0.4
192+
python3 plot_mrc_size.py --tracepath ../data/twitter_cluster52.csv --trace-format csv --trace-format-params="time-col=1,obj-id-col=2,obj-size-col=3,obj-cost-col=4,delimiter=," --algos=fifo,lru,lecar,s3fifo --sizes=0.001,0.002,0.005,0.01,0.02,0.05,0.1,0.2,0.3,0.4
193193

194194
# plot miss ratio over time
195195
python3 plot_mrc_time.py --tracepath ../data/twitter_cluster52.csv --trace-format csv --trace-format-params="time-col=1, obj-id-col=2, obj-size-col=3, delimiter=,," --algos=fifo,lru,lecar,s3fifo --report-interval=30 --miss-ratio-type="accu"

libCacheSim/bin/cachesim/sim.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
2525
uint64_t req_cnt = 0, miss_cnt = 0;
2626
uint64_t last_req_cnt = 0, last_miss_cnt = 0;
2727
uint64_t req_byte = 0, miss_byte = 0;
28+
double req_cost = 0, miss_cost = 0;
2829

2930
read_one_req(reader, req);
3031
uint64_t start_ts = (uint64_t)req->clock_time;
@@ -52,9 +53,11 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
5253

5354
req_cnt++;
5455
req_byte += req->obj_size;
56+
req_cost += req->obj_cost;
5557
if (cache->get(cache, req) == false) {
5658
miss_cnt++;
5759
miss_byte += req->obj_size;
60+
miss_cost += req->obj_cost;
5861
}
5962
if (req->clock_time - last_report_ts >= (uint64_t)report_interval &&
6063
req->clock_time != 0) {
@@ -78,24 +81,28 @@ void simulate(reader_t *reader, cache_t *cache, int report_interval,
7881

7982
char output_str[1024];
8083
char size_str[64];
84+
double byte_miss_ratio = req_byte > 0 ? (double)miss_byte / (double)req_byte : 0.0;
85+
double cost_miss_ratio = req_cost > 0 ? miss_cost / req_cost : 0.0;
8186

8287
if (!ignore_obj_size) convert_size_to_str(cache->cache_size, size_str, 64);
8388
#pragma GCC diagnostic push
8489
// Removed unknown pragma warning
8590
if (!ignore_obj_size) {
8691
snprintf(output_str, 1024,
87-
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, throughput "
92+
"%s %s cache size %8s, %16lu req, miss ratio %.4lf, byte miss ratio %.4lf, cost miss ratio %.4lf, throughput "
8893
"%.2lf MQPS\n",
8994
reader->trace_path, detailed_cache_name, size_str,
9095
(unsigned long)req_cnt, (double)miss_cnt / (double)req_cnt,
96+
byte_miss_ratio, cost_miss_ratio,
9197
(double)req_cnt / 1000000.0 / runtime);
9298
} else {
9399
snprintf(output_str, 1024,
94-
"%s %s cache size %8lld, %16lu req, miss ratio %.4lf, throughput "
100+
"%s %s cache size %8lld, %16lu req, miss ratio %.4lf, byte miss ratio %.4lf, cost miss ratio %.4lf, throughput "
95101
"%.2lf MQPS\n",
96102
reader->trace_path, detailed_cache_name,
97103
(long long)cache->cache_size, (unsigned long)req_cnt,
98104
(double)miss_cnt / (double)req_cnt,
105+
byte_miss_ratio, cost_miss_ratio,
99106
(double)req_cnt / 1000000.0 / runtime);
100107
}
101108

libCacheSim/bin/cli_reader_utils.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ void parse_reader_params(const char *reader_params_str,
119119
strcasecmp(key, "size-col") == 0) {
120120
params->obj_size_field = (int)strtol(value, &end, 0);
121121
_check_parsed_result(end, params->obj_size_field);
122+
} else if (strcasecmp(key, "obj-cost-col") == 0 ||
123+
strcasecmp(key, "cost-col") == 0) {
124+
params->obj_cost_field = (int)strtol(value, &end, 0);
125+
_check_parsed_result(end, params->obj_cost_field);
122126
} else if (strcasecmp(key, "cnt-col") == 0) {
123127
params->cnt_field = (int)strtol(value, &end, 0);
124128
} else if (strcasecmp(key, "op-col") == 0) {

libCacheSim/include/libCacheSim/reader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct {
4545
int32_t time_field;
4646
int32_t obj_id_field;
4747
int32_t obj_size_field;
48+
int32_t obj_cost_field;
4849
int32_t op_field;
4950
int32_t ttl_field;
5051
int32_t cnt_field;

libCacheSim/include/libCacheSim/request.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ typedef struct request {
3232

3333
int64_t obj_size;
3434

35+
int64_t obj_cost;
36+
3537
int32_t ttl;
3638

3739
req_op_e op;
@@ -79,6 +81,7 @@ static inline request_t *new_request(void) {
7981
request_t *req = my_malloc(request_t);
8082
memset(req, 0, sizeof(request_t));
8183
req->obj_size = 1;
84+
req->obj_cost = 1;
8285
req->op = OP_NOP;
8386
req->valid = true;
8487
req->obj_id = 0;
@@ -118,14 +121,16 @@ static inline void free_request(request_t *req) { my_free(request_t, req); }
118121
static inline void print_request(const request_t *req) {
119122
#ifdef SUPPORT_TTL
120123
LOGGING(DEBUG_LEVEL,
121-
"req clock_time %lu, id %llu, size %ld, ttl %ld, op %s, valid %d\n",
124+
"req clock_time %lu, id %llu, size %ld, cost %ld, ttl %ld, op %s, valid %d\n",
122125
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
123-
(long)req->obj_size, (long)req->ttl, req_op_str[req->op], req->valid);
126+
(long)req->obj_size, (long)req->obj_cost, (long)req->ttl,
127+
req_op_str[req->op], req->valid);
124128
#else
125129
LOGGING(DEBUG_LEVEL,
126-
"req clock_time %lu, id %llu, size %ld, op %s, valid %d\n",
130+
"req clock_time %lu, id %llu, size %ld, cost %ld, op %s, valid %d\n",
127131
(unsigned long)req->clock_time, (unsigned long long)req->obj_id,
128-
(long)req->obj_size, req_op_str[req->op], req->valid);
132+
(long)req->obj_size, (long)req->obj_cost, req_op_str[req->op],
133+
req->valid);
129134
#endif
130135
}
131136

libCacheSim/traceReader/generalReader/binary.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ int binaryReader_setup(reader_t *const reader) {
8080
params->obj_size_offset = -1;
8181
}
8282

83+
params->obj_cost_field_idx = reader->init_params.obj_cost_field;
84+
if (params->obj_cost_field_idx > 0) {
85+
params->obj_cost_format = fmt_str[params->obj_cost_field_idx - 1];
86+
params->obj_cost_offset = cal_offset(fmt_str, params->obj_cost_field_idx);
87+
} else {
88+
params->obj_cost_format = '\0';
89+
params->obj_cost_offset = -1;
90+
}
91+
8392
params->op_field_idx = reader->init_params.op_field;
8493
if (params->op_field_idx > 0) {
8594
params->op_format = fmt_str[params->op_field_idx - 1];
@@ -148,6 +157,12 @@ int binaryReader_setup(reader_t *const reader) {
148157
format_to_size(params->obj_size_format),
149158
params->obj_size_offset);
150159
}
160+
if (params->obj_cost_field_idx > 0) {
161+
n += snprintf(output + n, 1024 - n, ", obj_cost_field %d,%d,%d",
162+
params->obj_cost_field_idx,
163+
format_to_size(params->obj_cost_format),
164+
params->obj_cost_offset);
165+
}
151166
if (params->op_field_idx > 0) {
152167
n += snprintf(output + n, 1024 - n, ", op_field %d,%d,%d",
153168
params->op_field_idx, format_to_size(params->op_format),
@@ -226,6 +241,12 @@ int binary_read_one_req(reader_t *reader, request_t *req) {
226241
read_data(start + params->obj_size_offset, params->obj_size_format);
227242
}
228243

244+
/* read object cost */
245+
if (params->obj_cost_field_idx > 0) {
246+
req->obj_cost =
247+
read_data(start + params->obj_cost_offset, params->obj_cost_format);
248+
}
249+
229250
/* read operation */
230251
if (params->op_field_idx > 0) {
231252
req->op = read_data(start + params->op_offset, params->op_format);

libCacheSim/traceReader/generalReader/csv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ static inline void csv_cb1(void *s, size_t len, void *data) {
237237
if (req->obj_size == 0 && end == s) {
238238
WARN("csvReader obj_size is not a number: \"%s\"\n", (char *)s);
239239
}
240+
} else if (csv_params->curr_field_idx == csv_params->obj_cost_field_idx) {
241+
req->obj_cost = (int64_t)strtoll((char *)s, &end, 0);
242+
if (req->obj_cost == 0 && end == s) {
243+
WARN("csvReader obj_cost is not a number: \"%s\"\n", (char *)s);
244+
}
240245
} else if (csv_params->curr_field_idx == csv_params->op_field_idx) {
241246
if (strncasecmp((char *)s, "read", len) == 0) {
242247
req->op = OP_READ;
@@ -298,6 +303,7 @@ void csv_setup_reader(reader_t *const reader) {
298303
csv_params->time_field_idx = init_params->time_field;
299304
csv_params->obj_id_field_idx = init_params->obj_id_field;
300305
csv_params->obj_size_field_idx = init_params->obj_size_field;
306+
csv_params->obj_cost_field_idx = init_params->obj_cost_field;
301307
csv_params->op_field_idx = init_params->op_field;
302308
csv_params->ttl_field_idx = init_params->ttl_field;
303309
csv_params->cnt_field_idx = init_params->cnt_field;

libCacheSim/traceReader/reader.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ int read_one_req(reader_t *const reader, request_t *const req) {
258258
reader->n_read_req += 1;
259259
req->hv = 0;
260260
req->ttl = 0;
261+
req->obj_size = 1;
262+
req->obj_cost = 1;
261263
req->valid = true;
262264

263265
switch (reader->trace_type) {
@@ -333,8 +335,13 @@ int read_one_req(reader_t *const reader, request_t *const req) {
333335
req->obj_size = 1;
334336
}
335337

336-
VERBOSE("read one req: time %lu, obj_id %lu, size %lu at offset %zu\n",
337-
req->clock_time, req->obj_id, req->obj_size, offset_before_read);
338+
if (reader->init_params.obj_cost_field <= 0) {
339+
req->obj_cost = req->obj_size;
340+
}
341+
342+
VERBOSE("read one req: time %lu, obj_id %lu, size %lu, cost %lu at offset %zu\n",
343+
req->clock_time, req->obj_id, req->obj_size, req->obj_cost,
344+
offset_before_read);
338345

339346
return status;
340347
}

libCacheSim/traceReader/readerInternal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct {
2525
int time_field_idx;
2626
int obj_id_field_idx;
2727
int obj_size_field_idx;
28+
int obj_cost_field_idx;
2829
int op_field_idx;
2930
int cnt_field_idx;
3031
int ttl_field_idx;
@@ -109,6 +110,10 @@ typedef struct {
109110
int8_t obj_size_field_idx;
110111
char obj_size_format;
111112

113+
int32_t obj_cost_offset;
114+
int8_t obj_cost_field_idx;
115+
char obj_cost_format;
116+
112117
int32_t n_fields;
113118
int32_t item_size;
114119
char *fmt_str;

0 commit comments

Comments
 (0)