-
Notifications
You must be signed in to change notification settings - Fork 2
/
gc_sim.c
109 lines (88 loc) · 2.46 KB
/
gc_sim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "gc_sim.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int gc_sim_bench_config(int bench_type, int cycles, struct gc_sim_env *env) {
env->bench_type = bench_type;
env->cycles = cycles;
env->range = RANGE;
return 0;
}
void gc_sim_device_info(struct gc_sim_env *env) {
puts("[Device Configuration]");
printf("Page size: %d KB\n", PAGESIZE/K);
printf("Page per Block: %d\n", PAGE_PER_BLOCK);
printf("Block per Superblock: %d\n", BLOCK_PER_SUPERBLOCK);
puts("");
printf("Device Capacity: %ld GB\n", DEVICE_CAPACITY/G);
printf("nr_pages: %ld\n", NR_PAGES);
printf("nr_blocks: %ld\n", NR_BLOCKS);
printf("nr_superblocks: %ld\n", NR_SUPERBLOCKS);
puts("");
printf("Over-Provisioning Factor: %.2f\n", OP_FACTOR);
printf("Range: %d\n", (int)RANGE);
puts("");
puts("[Bench Configuration]");
if (env->bench_type == SEQ_WRITE) printf("SEQ_WRITE");
else if (env->bench_type == RAND_WRITE) printf("RAND_WRITE");
else printf("BENCH_TYPE_ERR");
printf(" Bench %d cycles\n", env->cycles);
puts("");
}
void gc_sim_print_stat(struct gc_sim_stat *stat) {
puts("=================");
puts("GC Simulator Stat");
puts("=================");
puts("");
printf("Write: %ld\n", stat->writes);
printf("Valid Copy: %ld\n", stat->valid_copies);
printf("GC: %ld\n", stat->gc_cnt);
puts("");
printf("WAF: %.2f\n", (float)(stat->writes + stat->valid_copies) / stat->writes);
puts("");
}
static void progress_bar(int current, int total) {
const int bar_width = 20;
if (current % (total/bar_width) == 0) {
printf("\r[");
for (int i = 0; i < current / (total/bar_width)-1; i++) printf("=");
if (current/bar_width != total/bar_width) printf(">");
for (int i = current / (total/bar_width); i < bar_width-1; i++) printf(" ");
printf("]");
fflush(stdout);
}
}
int gc_sim_simulate(struct gc_sim_ops *ops, struct gc_sim_env *env){
int rc = 0;
int bench_type = env->bench_type;
int cycles = env->cycles;
int range = env->range;
int lpa;
srand(time(NULL));
ops->create();
puts("==================");
puts("GC Simulator Start");
puts("==================");
puts("");
for (int i = 0; i < range * cycles; i++) {
switch (bench_type) {
case SEQ_WRITE:
break;
case RAND_WRITE:
lpa = rand() % range;
ops->write(lpa);
//usleep(1);
break;
default:
printf("bench_type_error, bench_type: %d\n", bench_type);
rc = 1;
goto free;
}
progress_bar(i+1, range * cycles);
}
puts("");
free:
ops->destroy();
return rc;
}