-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPA2_C.patch
278 lines (269 loc) · 11.1 KB
/
PA2_C.patch
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
diff -Naru ChampSim-master_orig/inc/cache.h ChampSim-master/inc/cache.h
--- ChampSim-master_orig/inc/cache.h 2018-01-23 23:23:54.000000000 +0530
+++ ChampSim-master/inc/cache.h 2018-10-21 01:36:13.775937478 +0530
@@ -174,6 +174,7 @@
int check_hit(PACKET *packet),
invalidate_entry(uint64_t inval_addr),
+ search_entry(uint64_t inval_addr),
check_mshr(PACKET *packet),
prefetch_line(uint64_t ip, uint64_t base_addr, uint64_t pf_addr, int fill_level),
kpc_prefetch_line(uint64_t base_addr, uint64_t pf_addr, int fill_level, int delta, int depth, int signature, int confidence);
diff -Naru ChampSim-master_orig/inc/ooo_cpu.h ChampSim-master/inc/ooo_cpu.h
--- ChampSim-master_orig/inc/ooo_cpu.h 2018-01-23 23:23:54.000000000 +0530
+++ ChampSim-master/inc/ooo_cpu.h 2018-10-21 01:38:06.283937049 +0530
@@ -82,6 +82,8 @@
L1D{"L1D", L1D_SET, L1D_WAY, L1D_SET*L1D_WAY, L1D_WQ_SIZE, L1D_RQ_SIZE, L1D_PQ_SIZE, L1D_MSHR_SIZE},
L2C{"L2C", L2C_SET, L2C_WAY, L2C_SET*L2C_WAY, L2C_WQ_SIZE, L2C_RQ_SIZE, L2C_PQ_SIZE, L2C_MSHR_SIZE};
+ int L1_BackHitCount, L2_BackHitCount, LLCEvictionCount, crossCoreEvictionCount;
+
// constructor
O3_CPU() {
cpu = 0;
@@ -150,6 +152,13 @@
RTS1_head = 0;
RTS0_tail = 0;
RTS1_tail = 0;
+
+ //L1, L2 Backhit and LLC eviction count
+ L1_BackHitCount = 0;
+ L2_BackHitCount = 0;
+ LLCEvictionCount = 0;
+ crossCoreEvictionCount = 0;
+
}
// functions
diff -Naru ChampSim-master_orig/run_2core.sh ChampSim-master/run_2core.sh
--- ChampSim-master_orig/run_2core.sh 1970-01-01 05:30:00.000000000 +0530
+++ ChampSim-master/run_2core.sh 2018-10-19 16:41:40.639979000 +0530
@@ -0,0 +1,13 @@
+TRACE_DIR=../Traces
+binary=${1}
+n_warm=${2}
+n_sim=${3}
+trace1=${4}
+trace2=${5}
+option=${6}
+
+
+
+mkdir -p results_2core
+
+(./bin/${binary} -warmup_instructions ${n_warm}000000 -simulation_instructions ${n_sim}000000 ${option} -traces ${TRACE_DIR}/${trace1}.trace.gz ${TRACE_DIR}/${trace2}.trace.gz) &> results_2core/${trace1}-${trace2}-${binary}${option}.txt
diff -Naru ChampSim-master_orig/run_4core.sh ChampSim-master/run_4core.sh
--- ChampSim-master_orig/run_4core.sh 1970-01-01 05:30:00.000000000 +0530
+++ ChampSim-master/run_4core.sh 2018-10-21 12:03:44.975994000 +0530
@@ -0,0 +1,13 @@
+TRACE_DIR=../Traces
+binary=${1}
+n_warm=${2}
+n_sim=${3}
+trace1=${4}
+trace2=${5}
+trace3=${6}
+trace4=${7}
+option=${8}
+
+
+mkdir -p results_4core
+(./bin/${binary} -warmup_instructions ${n_warm}000000 -simulation_instructions ${n_sim}000000 ${option} -traces ${TRACE_DIR}/${trace1}.trace.gz ${TRACE_DIR}/${trace2}.trace.gz ${TRACE_DIR}/${trace3}.trace.gz ${TRACE_DIR}/${trace4}.trace.gz) &> results_4core/mix${num}-${binary}${option}.txt
diff -Naru ChampSim-master_orig/run_champsim.sh ChampSim-master/run_champsim.sh
--- ChampSim-master_orig/run_champsim.sh 1970-01-01 05:30:00.000000000 +0530
+++ ChampSim-master/run_champsim.sh 2018-10-19 15:37:42.499994000 +0530
@@ -0,0 +1,9 @@
+TRACE_DIR=../Traces
+binary=${1}
+n_warm=${2}
+n_sim=${3}
+trace=${4}
+option=${5}
+
+mkdir -p results_${n_sim}M
+(./bin/${binary} -warmup_instructions ${n_warm}000000 -simulation_instructions ${n_sim}000000 ${option} -traces ${TRACE_DIR}/${trace}.trace.gz) &> results_${n_sim}M/${trace}-${binary}${option}.txt
diff -Naru ChampSim-master_orig/src/cache.cc ChampSim-master/src/cache.cc
--- ChampSim-master_orig/src/cache.cc 2018-01-23 23:23:54.000000000 +0530
+++ ChampSim-master/src/cache.cc 2018-10-22 16:02:28.911992974 +0530
@@ -1,5 +1,6 @@
#include "cache.h"
#include "set.h"
+#include "ooo_cpu.h"
uint64_t l2pf_access = 0;
@@ -19,10 +20,107 @@
uint32_t mshr_index = MSHR.next_fill_index;
+ uint64_t inval_addr;
+ int isInvalidated = -1, foundInL2 = 0, foundInL1 = 0;
+
// find victim
uint32_t set = get_set(MSHR.entry[mshr_index].address), way;
if (cache_type == IS_LLC) {
- way = llc_find_victim(fill_cpu, MSHR.entry[mshr_index].instr_id, set, block[set], MSHR.entry[mshr_index].ip, MSHR.entry[mshr_index].full_addr, MSHR.entry[mshr_index].type);
+
+ //Part-C: Minimizing the cross core Eviction
+ int found_in_other_L2 = 1, tryCount=0;
+ //Retry with other way till we try all the ways and till there is cross core eviction
+ while((tryCount < NUM_WAY) && (found_in_other_L2 == 1)){
+ //reset cross-core evic counter to 0
+ found_in_other_L2 = 0;
+ //get the victim way
+ way = llc_find_victim(fill_cpu, MSHR.entry[mshr_index].instr_id, set, block[set], MSHR.entry[mshr_index].ip, MSHR.entry[mshr_index].full_addr, MSHR.entry[mshr_index].type);
+
+ //check if the block is valid
+ if (block[set][way].valid != false) {
+
+ int search_in_L2 = 0;
+ //Check for all the CPUS L2 caches
+ for(int current_cpu=0; current_cpu<NUM_CPUS; current_cpu++ )
+ {
+ //Search a given LLC Block in L2 cache
+ search_in_L2=(ooo_cpu[current_cpu].L2C.search_entry(block[set][way].address));
+ //block is found in L2
+ if(search_in_L2 == 1)
+ {
+ //check if the block is in other cpu L2 cache
+ if(current_cpu != (int)fill_cpu ){
+ //Set the cross core eviction to 1
+ found_in_other_L2 =1;
+ //update the replacement state so that the same way will not be returned again
+ llc_update_replacement_state(fill_cpu, set, way, MSHR.entry[mshr_index].full_addr, MSHR.entry[mshr_index].ip, 0, MSHR.entry[mshr_index].type, 1);
+ }
+
+ }
+
+ }
+ //Increment the retry count
+ tryCount++;
+ }
+ }
+
+ //check if the block is valid, if yes then check at upper levels
+ if (block[set][way].valid != false) {
+ //Increment the total blocks evicted by cpu_fill
+ ooo_cpu[fill_cpu].LLCEvictionCount++;
+ //get block addr to be invalidated
+ inval_addr = block[set][way].address;
+ //Make the cache Inclusive by invalidating the inval_addr from upper levels
+ for (int cpu_id = 0; cpu_id < NUM_CPUS; cpu_id++)
+ {
+ //Is invalidated in L2, invalidate_entry returns -1 if block not present in L2
+ isInvalidated = ooo_cpu[cpu_id].L2C.invalidate_entry(inval_addr);
+ //if the block was present in L2 invalidate check and invalidate L1
+ if(isInvalidated != -1){
+
+ //check cross-core evictions
+ if(cpu_id != fill_cpu){
+ ooo_cpu[fill_cpu].crossCoreEvictionCount++;
+ }
+
+ //increment L2 backhits only once for all L2 cache
+ if(foundInL2 == 0){
+ ooo_cpu[cpu_id].L2_BackHitCount++;
+ foundInL2 = 1;
+ }
+ //Invalidate L1D
+ isInvalidated = ooo_cpu[cpu_id].L1D.invalidate_entry(inval_addr);
+ if((isInvalidated != -1) && (foundInL1 == 0)){
+ ooo_cpu[cpu_id].L1_BackHitCount++;
+ foundInL1 = 1;
+ }
+
+ //Invalidate L1I
+ isInvalidated = ooo_cpu[cpu_id].L1I.invalidate_entry(inval_addr);
+ if((isInvalidated != -1) && (foundInL1 == 0)){
+ ooo_cpu[cpu_id].L1_BackHitCount++;
+ foundInL1 =1;
+ }
+
+ }
+
+ }
+ }
+ }
+ //For L2 cache
+ else if(cache_type == IS_L2C) {
+ //find_victim
+ way = find_victim(fill_cpu, MSHR.entry[mshr_index].instr_id, set, block[set], MSHR.entry[mshr_index].ip, MSHR.entry[mshr_index].full_addr, MSHR.entry[mshr_index].type);
+
+ if (block[set][way].valid != false) {
+ //get block addr to be invalidated
+ inval_addr = block[set][way].address;
+
+ //Make the cache Inclusive by invalidating the inval_addr from upper levels L1D & L1I
+ ooo_cpu[fill_cpu].L1D.invalidate_entry(inval_addr);
+ ooo_cpu[fill_cpu].L1I.invalidate_entry(inval_addr);
+
+ }
}
else
way = find_victim(fill_cpu, MSHR.entry[mshr_index].instr_id, set, block[set], MSHR.entry[mshr_index].ip, MSHR.entry[mshr_index].full_addr, MSHR.entry[mshr_index].type);
@@ -1384,3 +1482,28 @@
{
WQ.FULL++;
}
+
+//check if the inval_addr is present in the cache, If yes return 1 else return 0
+int CACHE::search_entry(uint64_t inval_addr)
+{
+ uint32_t set = get_set(inval_addr);
+
+ if (NUM_SET < set)
+ {
+ cerr << "[" << NAME << "_ERROR] " << __func__ << " invalid set index: " << set << " NUM_SET: " << NUM_SET;
+ cerr << " inval_addr: " << hex << inval_addr << dec << endl;
+ assert(0);
+ }
+
+ // search
+ for (uint32_t way = 0; way < NUM_WAY; way++)
+ {
+ if (block[set][way].valid && (block[set][way].tag == inval_addr))
+ {
+ //Found: return 1
+ return 1;
+ }
+ }
+ //Not found: return 0
+ return 0;
+}
diff -Naru ChampSim-master_orig/src/main.cc ChampSim-master/src/main.cc
--- ChampSim-master_orig/src/main.cc 2018-01-23 23:23:54.000000000 +0530
+++ ChampSim-master/src/main.cc 2018-10-21 01:40:09.079936580 +0530
@@ -446,6 +446,29 @@
return pa;
}
+//Solution: PA-2_A
+void print_backhit_stats(){
+
+ for (int i=0; i<NUM_CPUS; i++) {
+ cout<<"\nPrinting BackHits Stats of CPU "<<i;
+ cout<<"\nTotal Eviction count in LLC : "<<ooo_cpu[i].LLCEvictionCount;
+ cout<<"\nL1 BackHit: "<<ooo_cpu[i].L1_BackHitCount;
+ cout<<"\tL2 BackHit: "<<ooo_cpu[i].L2_BackHitCount;
+ }
+ cout<<endl;
+}
+
+//Solution: PA-2_B
+void print_crosscore_eviction_stats(){
+
+ for (int i=0; i<NUM_CPUS; i++) {
+ cout<<"\nPrinting Cross-Core Eviction count of CPU "<<i;
+ cout<<"\nCross-Core Eviction Count: "<<ooo_cpu[i].crossCoreEvictionCount;
+
+ }
+ cout<<endl;
+}
+
int main(int argc, char** argv)
{
// interrupt signal hanlder
@@ -845,6 +868,12 @@
}
}
+ //Printing Backhits count
+ print_backhit_stats();
+
+ //Printing Cross-Core Eviction count
+ print_crosscore_eviction_stats();
+
cout << endl << "Region of Interest Statistics" << endl;
for (uint32_t i=0; i<NUM_CPUS; i++) {
cout << endl << "CPU " << i << " cumulative IPC: " << ((float) ooo_cpu[i].finish_sim_instr / ooo_cpu[i].finish_sim_cycle);