-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_test.cpp
More file actions
157 lines (122 loc) · 3.78 KB
/
cache_test.cpp
File metadata and controls
157 lines (122 loc) · 3.78 KB
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
147
148
149
150
151
152
153
154
155
156
157
#include "cache_test.hh"
namespace gem5 {
int main(int argc, char **argv)
{
// 检查参数数量
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <options>" << std::endl;
return 1;
}
int i = 1;
int cache_type = stoi(argv[i++]); // cache类型
int wl_type = stoi(argv[i++]); // wl 类型
MaxDrampage = 1ULL * 256 * 1024 * 1024 * 1024; // 256GB对齐最大地址
MaxDrampage /= PageSize; // 最大页数
uint64_t HBMsize = 4096;//单位B
int random_start = 0; // 默认不随机
if (cache_type)
{
HBMsize = stoll(argv[i++]);//设置容量
}
bool set_pre = true; // 默认有预取
int print_other = 0;
if (cache_type == 1 || cache_type == 3) // rt,以及8set, 区分有无预取
{
if (!stoi(argv[i++]))
{
set_pre = false;
}
}
if(cache_type !=2 )//2是 tlb
random_start = stoi(argv[i++]);
if (cache_type == 1 || cache_type == 2)
print_other = stoi(argv[i++]); // 是否输出额外信息 也就是timeprint,目前应该都不用,
string physical_path = argv[i++];
wearlevel_threshold = 2048; // 理想用
std::string extension;
size_t pos = physical_path.rfind('.');
if (pos != std::string::npos)
{
extension = physical_path.substr(pos + 1);
}
else
{
std::cerr << "No file extension found: " << physical_path << std::endl;
return 0;
}
std::cout << physical_path << " " << MaxDrampage << endl;
int fd = open(physical_path.c_str(), O_RDONLY);
if (fd == -1)
{
std::cerr << "Failed to open file: " << physical_path << std::endl;
return 1;
}
struct stat sb;
if (fstat(fd, &sb) == -1)
{
std::cerr << "Failed to get file status: " << physical_path << std::endl;
close(fd);
return 1;
}
size_t fileSize = sb.st_size;
char *data = static_cast<char *>(mmap(nullptr, fileSize, PROT_READ, MAP_PRIVATE, fd, 0));
if (data == MAP_FAILED)
{
std::cerr << "Failed to map file: " << physical_path << std::endl;
close(fd);
return 1;
}
size_t offset = 0;
while (offset < fileSize)
{
char *lineEnd = static_cast<char *>(memchr(data + offset, '\n', fileSize - offset));
if (!lineEnd)
{
break;
}
std::string line(data + offset, lineEnd - (data + offset));
offset += line.size() + 1;
istringstream read(line);
char operator_;
uint64_t addr;
std::string ignore1, ignore2, ignore4;
int rw;
if (extension == "out")
{
read >> operator_ >> addr;
rw = (operator_ == 'R' )? 0 : 1;//写操作为1
}
else if (extension == "trace")
{
read >> rw >> addr;
}
else if (extension == "pout")
{
read >> operator_ >> hex >> addr >> ignore1;
rw = (operator_ == 'R' )? 0 : 1;//写操作为1
}
else
{
std::cerr << "Unsupported file extension: " << extension << std::endl;
break;
}
uint64_t dram_num = addr / PageSize;
if (dram_num >= MaxDrampage)
{
dram_num %= MaxDrampage;
}
total_count++;
if (!rw)
read_count++;
std::pair<bool, uint64_t> it = get(dram_num);
if(wl_type==0)
update_time= cache_model->wearlevelaccess(it.second,rw);//传入映射后的地址,rw == 写操作
else if(wl_type!=3)
update_time= cache_model->wearlevelaccess(dram_num,rw);//内部有映射表表,
}
munmap(data, fileSize);
close(fd);
cache_model->print();
return 0;
}