forked from Arshdeep-Singh-01/UCP-CHAMPSIM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_replacement_static_part.cc
More file actions
166 lines (134 loc) · 5.01 KB
/
base_replacement_static_part.cc
File metadata and controls
166 lines (134 loc) · 5.01 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
158
159
160
161
162
163
164
165
166
#include "cache.h"
//#include<vector>
int cpuways[4]={7,1,1,7}; //Change only the values in this array to statically change the values for number of ways alloted
//Don't Change anything below this line
uint32_t CACHE::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 replacement policy for other caches
return lru_victim(cpu, instr_id, set, current_set, ip, full_addr, type);
}
void CACHE::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)
{
if (type == WRITEBACK) {
if (hit) // wrietback hit does not update LRU state
return;
}
return lru_update(set, way,cpu);
}
uint32_t CACHE::lru_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)
{
if(cache_type == IS_LLC){
uint32_t way =0;
int waysTaken[4]={0,0,0,0};
for(int j=0;j<NUM_WAY;j++){
if(block[set][j].valid==true)
if(block[set][j].cpu==cpu)
waysTaken[block[set][j].cpu]+=1;
}
//cout<<"Debug"<<waysTaken[0]<<" "<<waysTaken[1]<<endl;
// fill invalid line first
if(waysTaken[cpu]<cpuways[cpu]){
for (way=0; way<NUM_WAY; way++) {
if (block[set][way].valid!=true){
waysTaken[cpu]++;
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; });
break;
}
}
}
else{
// LRU victim
for (way=0; way<NUM_WAY; way++) {
if (block[set][way].cpu ==cpu) {
if (block[set][way].lru ==cpuways[cpu]-1)
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+1) {
cerr << "[" << NAME << "] " << __func__ << " no victim! set: " << set << endl;
assert(0);
}
return way;
}
else{
//Code Begin for Non LLC Cache
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; });
break;
}
}
// LRU victim
if (way == NUM_WAY) {
for (way= 0; way<NUM_WAY; way++) {
if (block[set][way].lru == NUM_WAY-1) {
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);
}
return way;
}
}
void CACHE::lru_update(uint32_t set, uint32_t way, uint32_t cpu)
{
// update lru replacement state
if(cache_type==IS_LLC){
for (uint32_t i=0; i<NUM_WAY; i++) {
if(block[set][i].cpu==cpu)
if (block[set][i].lru < block[set][way].lru) {
block[set][i].lru++;
}
}
block[set][way].lru = 0; // promote to the MRU position
}
else{
for (uint32_t i=0; i<NUM_WAY; i++) {
if (block[set][i].lru < block[set][way].lru) {
block[set][i].lru++;
}
}
block[set][way].lru = 0; // promote to the MRU position
}
}
void CACHE::replacement_final_stats()
{
}
#ifdef NO_CRC2_COMPILE
void InitReplacementState()
{
}
uint32_t GetVictimInSet (uint32_t cpu, uint32_t set, const BLOCK *current_set, uint64_t PC, uint64_t paddr, uint32_t type)
{
return 0;
}
void UpdateReplacementState (uint32_t cpu, uint32_t set, uint32_t way, uint64_t paddr, uint64_t PC, uint64_t victim_addr, uint32_t type, uint8_t hit)
{
}
void PrintStats_Heartbeat()
{
}
void PrintStats()
{
}
#endif