-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPA2_A.patch
145 lines (137 loc) · 5.92 KB
/
PA2_A.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
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 00:50:08.155948028 +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;
+
// constructor
O3_CPU() {
cpu = 0;
@@ -150,6 +152,11 @@
RTS1_head = 0;
RTS0_tail = 0;
RTS1_tail = 0;
+
+ //L1, L2 Backhit and LLC eviction count
+ L1_BackHitCount = 0;
+ L2_BackHitCount = 0;
+ LLCEvictionCount = 0;
}
// functions
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-21 00:50:06.399948035 +0530
@@ -1,5 +1,6 @@
#include "cache.h"
#include "set.h"
+#include "ooo_cpu.h"
uint64_t l2pf_access = 0;
@@ -19,10 +20,65 @@
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);
+
+ //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){
+ //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);
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 00:50:03.979948044 +0530
@@ -446,6 +446,18 @@
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;
+}
+
int main(int argc, char** argv)
{
// interrupt signal hanlder
@@ -845,6 +857,9 @@
}
}
+ //Printing Backhits count
+ print_backhit_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);