-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
146 lines (123 loc) · 4.17 KB
/
main.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include "LRU.h"
// using namespace std;
BMgr *bmgr;
int main() {
/*flash 平台初始化信息*/
VFD_INFO vfdInfo;
FTL_INFO ftlInfo;
vfdInfo.id = ID_NAND_DEVICE_03;
vfdInfo.blockCount = 1024;
vfdInfo.pageCountPerBlock = 64;
vfdInfo.pageSize.size1 = 2048;
vfdInfo.pageSize.size2 = 0;
vfdInfo.eraseLimitation = 100000;
vfdInfo.readTime.randomTime = 25;
vfdInfo.readTime.serialTime = 0;
vfdInfo.programTime = 200;
vfdInfo.eraseTime = 1500;
ftlInfo.id = ID_FTL_01;
ftlInfo.mapListSize = 65536;
ftlInfo.wearLevelingThreshold = 4;
LRU *lru = NULL;
lru = new LRU();
bmgr = lru;
printf("FlashDBSim正在初始化......\n");
f_initialize(vfdInfo, ftlInfo);
printf("FlashDBSim初始化完成\n");
FILE *fp = NULL;
int RW = -1; /*标识读写操作*/
int lba = -1; /*Trace文件中的LBA*/
int fcount = 0; /*Trace的记录数*/
int readcount = 0; // trace中的读操作
int writecount = 0; // trace中的写操作
int i = 1;
int frid = -1;
NewPage np;
np.frame_id = -1;
np.page_id = -1;
char *data = new char[FRAMESIZE];
memset(data, '0', FRAMESIZE);
/*向闪存连续写入10000个数据页*/
for (int i = 0; i < 10001; i++) {
np = bmgr->FixNewPage(i);
bmgr->WriteFrame(np.frame_id, data);
}
/*将缓存中的脏页写回闪存*/
bmgr->WriteDirty();
/*重新初始化缓冲区*/
bmgr->Init();
if ((fp = fopen("trace1000000", "r")) == NULL) {
printf(" cannot open trace file\n");
return 0;
}
while (fcount < 1000000) {
fscanf(fp, "%d %d", &lba, &RW);
if (RW == 0) {
frid = bmgr->FixPage(bmgr->LBAToPID(lba));
bmgr->ReadFrame(frid, data);
readcount++;
} else {
/*若该页不存在,则直接写回闪存*/
if (bmgr->IsLBAValid(lba)) {
frid = bmgr->FixPage(bmgr->LBAToPID(lba));
bmgr->WriteFrame(frid, data);
} else {
/*若该页不存在,则需要分配一个新页*/
np = bmgr->FixNewPage(lba);
bmgr->WriteFrame(np.frame_id, data);
}
writecount++;
}
fcount++;
if (fcount == 20000 * i) {
printf("%d\n", fcount);
i++;
}
}
fclose(fp);
bmgr->WriteDirty();
printf("trace's read count is:%d\n", readcount);
printf("trace's write count is:%d\n", writecount);
bmgr->RWInfo();
printf("hit ratio is:%f\n", bmgr->HitRatio());
IVFD *vfd = const_cast<IVFD *>(f_get_vfd_module());
IVFD_COUNTER *icounter = NULL;
vfd->QueryInterface(IID_IVFD_COUNTER, (void **)&icounter);
IVFD_LATENCY *ilatency = NULL;
vfd->QueryInterface(IID_IVFD_LATENCY, (void **)&ilatency);
printf("ReadCountTotal is %d\n", icounter->GetReadCountTotal());
printf("WriteCountTotal is %d\n", icounter->GetWriteCountTotal());
printf("EraseCountTotal is %d\n", icounter->GetEraseCountTotal());
printf("totalLatency is %d \n",
ilatency->GetReadLatencyTotal() + ilatency->GetWriteLatencyTotal() +
ilatency->GetEraseLatencyTotal() - 10001 * 220);
printf("Write Latency: %d\n", ilatency->GetWriteLatencyTotal());
FILE *fr = NULL;
if ((fr = fopen("result_200000.txt", "a")) == NULL) {
printf(" cannot open result file\n");
return 0;
}
// fprintf(fr,"Running time is:%d",end-start);
fprintf(fr, "hit ratio is: %f\n", bmgr->HitRatio());
fprintf(fr, "ReadCountTotal is: %d\n",
ilatency->GetReadLatencyTotal() / 25);
fprintf(fr, "WriteCountTotal is: %d\n",
(ilatency->GetWriteLatencyTotal() - 10001 * 200) / 200);
fprintf(fr, "EraseCountTotal is: %d\n",
ilatency->GetEraseLatencyTotal() / 1500);
fprintf(fr, "totalLatency is: %d\n",
ilatency->GetReadLatencyTotal() + ilatency->GetWriteLatencyTotal() +
ilatency->GetEraseLatencyTotal() - 10001 * 220);
fprintf(fr, "\n");
fclose(fr);
printf("FlashDBSim正在释放......\n");
delete lru;
lru = NULL;
delete[] data;
f_release();
printf("FlashDBSim释放完成\n");
printf("\n");
printf("...........................................................\n");
printf("\n");
}