-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2cache.h
230 lines (177 loc) · 6.16 KB
/
2cache.h
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
struct cachememory
{
unsigned int valid;
unsigned int tag;
};
struct cachememory2
{
unsigned int valid;
unsigned int tag;
};
struct ssd
{
unsigned int valid;
unsigned int tag;
unsigned int pageno;
};
struct dram
{
unsigned int pageno;
unsigned int access;
};
struct streambuffer
{
unsigned int valid;
unsigned int pageno;
};
struct victimbuffer
{
unsigned int valid;
unsigned int pageno;
};
class cache
{
private:
struct cachememory *scachememory;
struct cachememory2 *scachememory2;
struct ssd *sssd;
struct dram *sdram;
struct victimbuffer *svictimbuffer;
struct streambuffer *sstreambuffer;
unsigned int size_ssd;
unsigned int size_page;
unsigned int num_way;
unsigned int num_pages;
unsigned int num_blocks;
unsigned int size_dram;
unsigned int num_paged;
unsigned int size_cache;
unsigned int size_cache2;
unsigned int size_block;//L:block size
unsigned int num_associativity;//K
unsigned int num_set;//N
//unsigned int size_block2;//L:block size
unsigned int num_associativity2;//K
unsigned int num_set2;//N
unsigned int num_block;
unsigned int num_block2;
unsigned int req_offset;
unsigned int req_index;
unsigned int req_tag;//bit
unsigned int req_offset2;
unsigned int req_index2;
unsigned int req_tag2;//bit
unsigned int reqindexmask;
unsigned int reqoffsetmask;
unsigned int reqindexmask2;
unsigned int reqoffsetmask2;
unsigned int req_offsets;
unsigned int req_pages;
unsigned int req_tags;
unsigned int reqpagemasks;
unsigned int reqoffsetmasks;
unsigned int num_vbuffer;
unsigned int num_sbuffer;
unsigned int num_vwrite;
unsigned int num_vread;
unsigned int num_vhit;
unsigned int num_swrite;
unsigned int num_sread;
unsigned int num_shit;
unsigned int num_access;
unsigned int num_miss;
unsigned int num_hit;
unsigned int num_read;
unsigned int num_write;
unsigned int num_access2;
unsigned int num_miss2;
unsigned int num_hit2;
unsigned int num_read2;
unsigned int num_write2;
unsigned int num_accessd;
unsigned int num_missd;
unsigned int num_hitd;
unsigned int num_readd;
unsigned int num_writed;
unsigned int num_accesss;
unsigned int num_misss;
unsigned int num_hits;
unsigned int num_reads;
unsigned int num_writes;
inline unsigned int gettag(unsigned int address);
inline unsigned int gettag2(unsigned int address);
inline unsigned int getindex(unsigned int address);
inline unsigned int getindex2(unsigned int address);
inline unsigned int gettags(unsigned int address);
inline unsigned int getpages(unsigned int address);
inline bool getbaseaddress(unsigned int index, unsigned int &address);
inline bool getbaseaddress2(unsigned int index, unsigned int &address);
inline bool getbaseaddresss(unsigned int page, unsigned int &address);
bool loadandwriteblock(unsigned int address);
bool loadandwriteblock2(unsigned int address);
bool loadandwriteblock3(unsigned int address);
bool loadandwriteblock4(unsigned int address);
bool streambufferread(unsigned int address);
bool streambufferwrite(unsigned int address);
bool victimbuferread(unsigned int address);
bool victimbuferwrite(unsigned int address);
public:
cache(int pagesize ,int vbuffernum,int sbuffernum);
~cache();
void deletecache();
bool initcache();
bool cacheread(unsigned int address);
bool cacheread2(unsigned int address);
bool cachewrite(unsigned int address);
bool instread(unsigned int address);
bool dramread(unsigned int address);
bool ssdread(unsigned int address);
//unsigned int getblocksize(){ return size_block; };
//unsigned int getassociativity(){ return num_associativity; };
//unsigned int getsetnum(){ return num_set; };
//unsigned int getcachesize(){ return size_cache; };
//unsigned int getblocksize2(){ return size_block; };
//unsigned int getassociativity2(){ return num_associativity2; };
//unsigned int getsetnum2(){ return num_set2; };
//unsigned int getcachesize2(){ return size_cache2; };
unsigned int getaccessnum(){ return num_access; };
unsigned int getmissnum(){ return num_miss; };
unsigned int gethitnum() { return num_hit; };
unsigned int getreadnum(){ return num_read; };
unsigned int getwritenum(){ return num_write; };
unsigned int getaccessnum2(){ return num_access2; };
unsigned int getmissnum2(){ return num_miss2; };
unsigned int gethitnum2() { return num_hit2; };
unsigned int getreadnum2(){ return num_read2; };
unsigned int getwritenum2(){ return num_write2; };
unsigned int getaccessnumd(){ return num_accessd; };
unsigned int getmissnumd(){ return num_missd; };
unsigned int gethitnumd() { return num_hitd; };
unsigned int getreadnumd(){ return num_readd; };
unsigned int getwritenumd(){ return num_writed; };
unsigned int getaccessnums(){ return num_accesss; };
unsigned int getmissnums(){ return num_misss; };
unsigned int gethitnums() { return num_hits; };
unsigned int getreadnums(){ return num_reads; };
unsigned int getwritenums(){ return num_writes; };
double getmissrate(){ return (num_miss*1.0) / (double)(num_access*1.0); };
double getmissrate2(){ return (num_miss2*1.0) / (double)(num_access2*1.0); };
double getmissrated(){ return (num_missd*1.0) / (double)(num_accessd*1.0); };
double getmissrates(){ return (num_misss*1.0) / (double)(num_accesss*1.0); };
double totalaccesstime(){
return (double)(num_write + num_read + num_write2 + num_read2 + num_writed * 10 + num_readd * 10) / 1000000.0
+ (double)(num_writes * 200 + num_reads * 25) / 1000.0
+ (double)(num_miss * 1 + num_miss2 * 20 + num_missd * 200) / 1000000.0;
};
double amat(){
return 1 + getmissrate()*(1 + getmissrate2() * (20+getmissrated()*200)) ;
};
unsigned int getvbuffernum(){ return num_vbuffer; };
unsigned int getsbuffernum(){ return num_sbuffer; };
unsigned int getvwritenum(){ return num_vwrite; };
unsigned int getvreadnum(){ return num_vread; };
unsigned int getvhitmnum(){ return num_vhit; };
unsigned int getswritenum(){ return num_swrite; };
unsigned int getsreadnum(){ return num_sread; };
unsigned int getshitmnum(){ return num_shit; };
};