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.cc
More file actions
176 lines (151 loc) · 5.58 KB
/
base_replacement.cc
File metadata and controls
176 lines (151 loc) · 5.58 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
167
168
169
170
171
172
173
174
175
176
#include "cache.h"
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)
{
// fill invalid line first
uint32_t i, way;
for (i = 0; i < ways_partition[cpu].size(); i++)
{
way = ways_partition[cpu][i];
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 (i == ways_partition[cpu].size())
{
for (i = 0; i < ways_partition[cpu].size(); i++)
{
way = ways_partition[cpu][i];
if (block[set][way].lru == ways_partition[cpu].size() - 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 (i == ways_partition[cpu].size())
{
cerr << "[" << NAME << "] " << __func__ << " no victim! set: " << set << endl;
assert(0);
}
return way;
}
else
{
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)
{
uint32_t i, j;
for (j = 0; j < ways_partition[cpu].size(); j++)
{
i = ways_partition[cpu][j];
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