-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlru.llc_repl
177 lines (135 loc) · 5.31 KB
/
lru.llc_repl
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
#include "cache.h"
#include "ooo_cpu.h"
// initialize replacement state
void CACHE::llc_initialize_replacement()
{
}
// find replacement victim
uint32_t CACHE::llc_find_victim(uint32_t cpu, uint64_t instr_id, uint32_t set, const BLOCK *current_set, uint64_t ip, uint64_t full_addr, uint32_t type)
{
// baseline LRU
//if(NUM_CPUS == 1)
//return lru_victim(cpu, instr_id, set, current_set, ip, full_addr, type);
uint32_t way = 0;
// fill invalid line first
for (way = 0; way < NUM_WAY; way++)
{
if (block[set][way].valid == false)
{
DP(if (warmup_complete[cpu]) {
cout << "[" << NAME << "] " << __func__ << " instr_id: " << instr_id << " invalid set: " << set << " way: " << way;
cout << hex << " address: " << (full_addr>>LOG2_BLOCK_SIZE) << " victim address: " << block[set][way].address << " data: " << block[set][way].data;
cout << dec << " lru: " << block[set][way].lru << endl; });
return way;
}
}
// LRU victim
int cpu_max, noncpu_max, cpu_max_way, noncpu_max_way,c,flag,count,cp,flagUpper=0;
cpu_max = -1, noncpu_max = -1, cpu_max_way = -1;
/* if(way==NUM_WAY)
{
for (way = 0; way < NUM_WAY; way++)
{ flag=0;
for(c=0;c<NUM_CPUS;c++)
{
if(ooo_cpu[c].L2C.search_entry(block[set][way].address)) {flag=1;}
}
if(flag==0)
{
flagUpper = 1;
if (cpu_max < (int) block[set][way].lru)
{
cpu_max = block[set][way].lru;
cpu_max_way = way;
}
}
}
if(flagUpper)
return cpu_max_way;
cout<<"entering private core section"<<endl;
for (way = 0; way < NUM_WAY; way++)
{ count=0;cp=0;
for(c=0;c<NUM_CPUS;c++)
{
int t=(ooo_cpu[c].L2C.search_entry(block[set][way].address));
cout<<"return value of search "<<t<<endl;
if(t) {
count++;
if(c==(int)cpu) cp=1;
}
}
cout<<"COUNT "<<count<<"cp "<<cp<<endl;
if(count==1 && cp==1) {
flagUpper = 1;
cout<<"inside if"<<endl;
if (cpu_max < (int) block[set][way].lru)
{
cpu_max = block[set][way].lru;
cpu_max_way = way;
}
}
}
cout<<"exiting of private"<<endl;
cout<<"CPU MAX"<<cpu_max_way<<endl;
if(flagUpper && cpu_max_way!=-1)
return cpu_max_way;
/* for (way = 0; way < NUM_WAY; way++)
{
if (cpu_max < (int )block[set][way].lru)
{
cpu_max = block[set][way].lru;
cpu_max_way = way;
}
}
*/
for (way=0; way<NUM_WAY; way++) {
if (block[set][way].lru == NUM_WAY-1) {
cpu_max_way = way;
DP ( if (warmup_complete[cpu]) {
cout << "[" << NAME << "] " << __func__ << " instr_id: " << instr_id << " replace set: " << set << " way: " << way;
cout << hex << " address: " << (full_addr>>LOG2_BLOCK_SIZE) << " victim address: " << block[set][way].address << " data: " << block[set][way].data;
cout << dec << " lru: " << block[set][way].lru << endl; });
break;
}
}
//}
/*
if (way == NUM_WAY)
{
cerr << "[" << NAME << "] " << __func__ << " no victim! set: " << set << endl;
assert(0);
} */
// cout<<"CPU MAX WAY"<<cpu_max_way<<endl;
return cpu_max_way;
}
// called on every cache hit and cache fill
void CACHE::llc_update_replacement_state(uint32_t cpu, uint32_t set, uint32_t way, uint64_t full_addr, uint64_t ip, uint64_t victim_addr, uint32_t type, uint8_t hit)
{
string TYPE_NAME;
if (type == LOAD)
TYPE_NAME = "LOAD";
else if (type == RFO)
TYPE_NAME = "RFO";
else if (type == PREFETCH)
TYPE_NAME = "PF";
else if (type == WRITEBACK)
TYPE_NAME = "WB";
else
assert(0);
if (hit)
TYPE_NAME += "_HIT";
else
TYPE_NAME += "_MISS";
if ((type == WRITEBACK) && ip)
assert(0);
// uncomment this line to see the LLC accesses
// cout << "CPU: " << cpu << " LLC " << setw(9) << TYPE_NAME << " set: " << setw(5) << set << " way: " << setw(2) << way;
// cout << hex << " paddr: " << setw(12) << paddr << " ip: " << setw(8) << ip << " victim_addr: " << victim_addr << dec << endl;
// baseline LRU
if (hit && (type == WRITEBACK)) // writeback hit does not update LRU state
return;
return lru_update(set, way);
}
void CACHE::llc_replacement_final_stats()
{
}