Skip to content

Commit 2648e4c

Browse files
committed
Code cleaned, need to add comments
1 parent 1e62e91 commit 2648e4c

12 files changed

+5
-86
lines changed

CacheSim/Bus.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ void Bus::init(int num_cores) {
2929
read_ex = true;
3030

3131
pending_work = std::vector<bool>(num_cores, false);
32-
/*for(int i = 0; i < Protocol::num_cores; i++) {
33-
pending_work.push_back(false);
34-
}
35-
std::cout<<pending_work[0];*/
3632
}
3733

3834
void Bus::wait_for_responses(int id, unsigned long address, operations oper) {

CacheSim/Cache.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Set::Set(unsigned long ass) {
3333
}
3434

3535
Cache::Cache() {
36-
//unsigned long line_size = cache_size / CACHE_LINE_SIZE;
3736
unsigned long num_sets = cache_size / associativity;
3837

3938
// #######

CacheSim/CompSnooping.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void *CompSnooping::response_worker(void *arg) {
2222
while(!Bus::pending_work[obj->id]) {
2323
pthread_cond_wait(&Bus::resp_cvar, &Bus::resp_lock);
2424
}
25-
//std::cout<<"Thread "<<obj->id<<" to respond\n";
2625
pthread_mutex_unlock(&Bus::resp_lock);
2726

2827
pthread_mutex_lock(&obj->lock);
@@ -92,7 +91,6 @@ void *CompSnooping::response_worker(void *arg) {
9291
if(Bus::resp_count == Protocol::num_cores - 1) {
9392
pthread_cond_signal(&Bus::req_cvar);
9493
}
95-
//std::cout<<"Thread "<<obj->id<<" done responding\n";
9694
}
9795
}
9896

@@ -103,11 +101,9 @@ void *CompSnooping::request_worker(void *arg) {
103101

104102
pthread_mutex_lock(&Protocol::lock);
105103
while(true) {
106-
//fflush(stdout);
107104
while(!Protocol::ready || Protocol::request_id != obj->id) {
108105
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
109106
}
110-
//fflush(stdout);
111107
std::cout<<"Thread "<<obj->id<< " got request\n";
112108
op = Protocol::request_op;
113109
addr = Protocol::request_addr;
@@ -122,7 +118,6 @@ void *CompSnooping::request_worker(void *arg) {
122118
handle_request(obj, op, addr);
123119
std::cout<<"Thread " << obj->id<<" Done with request\n";
124120
pthread_mutex_lock(&Protocol::lock);
125-
//std::cout<<"done handling\n";
126121
fflush(stdout);
127122
Protocol::trace_count++;
128123
}
@@ -163,9 +158,7 @@ void CompSnooping::handle_request(CompSnooping *obj, std::string op, unsigned lo
163158
obj->cache.cache_incr_counter(addr);
164159
obj->cache.update_cache_lru(addr);
165160
obj->opt = BusUpdt;
166-
//std::cout<<"Before wait\n";
167161
Bus::wait_for_responses(obj->id, addr, BusUpdt);
168-
//std::cout<<"After wait\n";
169162
if(Bus::read_ex == true) {
170163
obj->cache.cache_set_status(addr, Modified);
171164
} else {
@@ -180,9 +173,7 @@ void CompSnooping::handle_request(CompSnooping *obj, std::string op, unsigned lo
180173
obj->cache.cache_incr_counter(addr);
181174
obj->cache.update_cache_lru(addr);
182175
obj->opt = BusUpdt;
183-
//std::cout<<"Before wait\n";
184176
Bus::wait_for_responses(obj->id, addr, BusUpdt);
185-
//std::cout<<"After wait\n";
186177
if(Bus::read_ex == true) {
187178
obj->cache.cache_set_status(addr, Modified);
188179
} else {
@@ -195,9 +186,7 @@ void CompSnooping::handle_request(CompSnooping *obj, std::string op, unsigned lo
195186
case Invalid:
196187
if(op == "R") {
197188
obj->opt = BusRd;
198-
//std::cout<<"Before wait\n";
199189
Bus::wait_for_responses(obj->id, addr, BusRd);
200-
//std::cout<<"After wait\n";
201190

202191
if(Bus::read_ex == true) {
203192
obj->cache.insert_cache(addr, Exclusive);

CacheSim/Dragon.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void *Dragon::response_worker(void *arg) {
2222
while(!Bus::pending_work[obj->id]) {
2323
pthread_cond_wait(&Bus::resp_cvar, &Bus::resp_lock);
2424
}
25-
//std::cout<<"Thread "<<obj->id<<" to respond\n";
2625
pthread_mutex_unlock(&Bus::resp_lock);
2726

2827
pthread_mutex_lock(&obj->lock);
@@ -71,7 +70,6 @@ void *Dragon::response_worker(void *arg) {
7170
if(Bus::resp_count == Protocol::num_cores - 1) {
7271
pthread_cond_signal(&Bus::req_cvar);
7372
}
74-
//std::cout<<"Thread "<<obj->id<<" done responding\n";
7573
}
7674
}
7775

@@ -82,11 +80,9 @@ void *Dragon::request_worker(void *arg) {
8280

8381
pthread_mutex_lock(&Protocol::lock);
8482
while(true) {
85-
//fflush(stdout);
8683
while(!Protocol::ready || Protocol::request_id != obj->id) {
8784
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
8885
}
89-
//fflush(stdout);
9086
std::cout<<"Thread "<<obj->id<< " got request\n";
9187
op = Protocol::request_op;
9288
addr = Protocol::request_addr;
@@ -101,7 +97,6 @@ void *Dragon::request_worker(void *arg) {
10197
handle_request(obj, op, addr);
10298
std::cout<<"Thread " << obj->id<<" Done with request\n";
10399
pthread_mutex_lock(&Protocol::lock);
104-
//std::cout<<"done handling\n";
105100
fflush(stdout);
106101
Protocol::trace_count++;
107102
}
@@ -139,9 +134,7 @@ void Dragon::handle_request(Dragon *obj, std::string op, unsigned long addr) {
139134
assert(op == "W");
140135
obj->cache.update_cache_lru(addr);
141136
obj->opt = BusUpdt;
142-
//std::cout<<"Before wait\n";
143137
Bus::wait_for_responses(obj->id, addr, BusUpdt);
144-
//std::cout<<"After wait\n";
145138
if(Bus::read_ex == true) {
146139
obj->cache.cache_set_status(addr, Modified);
147140
} else {
@@ -155,9 +148,7 @@ void Dragon::handle_request(Dragon *obj, std::string op, unsigned long addr) {
155148
assert(op == "W");
156149
obj->cache.update_cache_lru(addr);
157150
obj->opt = BusUpdt;
158-
//std::cout<<"Before wait\n";
159151
Bus::wait_for_responses(obj->id, addr, BusUpdt);
160-
//std::cout<<"After wait\n";
161152
if(Bus::read_ex == true) {
162153
obj->cache.cache_set_status(addr, Modified);
163154
} else {
@@ -170,9 +161,7 @@ void Dragon::handle_request(Dragon *obj, std::string op, unsigned long addr) {
170161
case Invalid:
171162
if(op == "R") {
172163
obj->opt = BusRd;
173-
//std::cout<<"Before wait\n";
174164
Bus::wait_for_responses(obj->id, addr, BusRd);
175-
//std::cout<<"After wait\n";
176165

177166
if(Bus::read_ex == true) {
178167
obj->cache.insert_cache(addr, Exclusive);

CacheSim/MESI.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ void *MESI::request_worker(void *arg) {
9494

9595
pthread_mutex_lock(&Protocol::lock);
9696
while(true) {
97-
//fflush(stdout);
9897
while(!Protocol::ready || Protocol::request_id != obj->id) {
9998
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
10099
}
101-
//fflush(stdout);
102100
std::cout<<"Thread "<<obj->id<< " got request\n";
103101
op = Protocol::request_op;
104102
addr = Protocol::request_addr;
@@ -113,7 +111,6 @@ void *MESI::request_worker(void *arg) {
113111
handle_request(obj, op, addr);
114112
std::cout<<"Thread " << obj->id<<" Done with request\n";
115113
pthread_mutex_lock(&Protocol::lock);
116-
//std::cout<<"done handling\n";
117114
fflush(stdout);
118115
Protocol::trace_count++;
119116
}
@@ -211,7 +208,6 @@ void MESI::handle_request(MESI *obj, std::string op, unsigned long addr) {
211208
obj->pending_addr = 0;
212209
pthread_mutex_unlock(&obj->lock);
213210
}
214-
//std::cout<<"Done with memory request\n";
215211
}
216212

217213

CacheSim/MOESI.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void *MOESI::response_worker(void *arg) {
2222
while(!Bus::pending_work[obj->id]) {
2323
pthread_cond_wait(&Bus::resp_cvar, &Bus::resp_lock);
2424
}
25-
//std::cout<<"Thread "<<obj->id<<" to respond\n";
2625
pthread_mutex_unlock(&Bus::resp_lock);
2726

2827
pthread_mutex_lock(&obj->lock);
@@ -97,7 +96,6 @@ void *MOESI::response_worker(void *arg) {
9796
if(Bus::resp_count == Protocol::num_cores - 1) {
9897
pthread_cond_signal(&Bus::req_cvar);
9998
}
100-
//std::cout<<"Thread "<<obj->id<<" done responding\n";
10199
}
102100
}
103101

@@ -108,11 +106,9 @@ void *MOESI::request_worker(void *arg) {
108106

109107
pthread_mutex_lock(&Protocol::lock);
110108
while(true) {
111-
//fflush(stdout);
112109
while(!Protocol::ready || Protocol::request_id != obj->id) {
113110
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
114111
}
115-
//fflush(stdout);
116112
std::cout<<"Thread "<<obj->id<< " got request "<< op <<" " << Protocol::request_addr<<"\n";
117113
op = Protocol::request_op;
118114
addr = Protocol::request_addr;
@@ -127,7 +123,6 @@ void *MOESI::request_worker(void *arg) {
127123
handle_request(obj, op, addr);
128124
std::cout<<"Thread " << obj->id<<" Done with request\n";
129125
pthread_mutex_lock(&Protocol::lock);
130-
//std::cout<<"done handling\n";
131126
fflush(stdout);
132127
Protocol::trace_count++;
133128
}
@@ -170,9 +165,7 @@ void MOESI::handle_request(MOESI *obj, std::string op, unsigned long addr) {
170165
assert(op == "W");
171166
obj->cache.update_cache_lru(addr);
172167
obj->opt = BusUpg;
173-
//std::cout<<"Before wait\n";
174168
Bus::wait_for_responses(obj->id, addr, BusUpg);
175-
//std::cout<<"After wait\n";
176169
if(Bus::recv_nak) {
177170
done = false;
178171
} else {
@@ -183,9 +176,7 @@ void MOESI::handle_request(MOESI *obj, std::string op, unsigned long addr) {
183176
case Invalid:
184177
if(op == "R") {
185178
obj->opt = BusRd;
186-
//std::cout<<"Before wait\n";
187179
Bus::wait_for_responses(obj->id, addr, BusRd);
188-
//std::cout<<"After wait\n";
189180
if(Bus::recv_nak) {
190181
done = false;
191182
} else {
@@ -230,7 +221,6 @@ void MOESI::handle_request(MOESI *obj, std::string op, unsigned long addr) {
230221
obj->pending_addr = 0;
231222
pthread_mutex_unlock(&obj->lock);
232223
}
233-
//std::cout<<"Done with memory request\n";
234224
}
235225
}
236226
}

CacheSim/MOSI.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ void *MOSI::request_worker(void *arg) {
8989

9090
pthread_mutex_lock(&Protocol::lock);
9191
while(true) {
92-
//fflush(stdout);
9392
while(!Protocol::ready || Protocol::request_id != obj->id) {
9493
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
9594
}
96-
//fflush(stdout);
9795
std::cout<<"Thread "<<obj->id<< " got request\n";
9896
op = Protocol::request_op;
9997
addr = Protocol::request_addr;
@@ -108,7 +106,6 @@ void *MOSI::request_worker(void *arg) {
108106
handle_request(obj, op, addr);
109107
std::cout<<"Thread " << obj->id<<" Done with request\n";
110108
pthread_mutex_lock(&Protocol::lock);
111-
//std::cout<<"done handling\n";
112109
fflush(stdout);
113110
Protocol::trace_count++;
114111
}
@@ -201,7 +198,6 @@ void MOSI::handle_request(MOSI *obj, std::string op, unsigned long addr) {
201198
obj->pending_addr = 0;
202199
pthread_mutex_unlock(&obj->lock);
203200
}
204-
//std::cout<<"Done with memory request\n";
205201
}
206202
}
207203
}

CacheSim/MSI.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ void *MSI::response_worker(void *arg) {
2222
while(!Bus::pending_work[obj->id]) {
2323
pthread_cond_wait(&Bus::resp_cvar, &Bus::resp_lock);
2424
}
25-
//std::cout<<"Thread "<<obj->id<<" to respond\n";
2625
pthread_mutex_unlock(&Bus::resp_lock);
2726

2827
pthread_mutex_lock(&obj->lock);
@@ -71,7 +70,6 @@ void *MSI::response_worker(void *arg) {
7170
if(Bus::resp_count == Protocol::num_cores - 1) {
7271
pthread_cond_signal(&Bus::req_cvar);
7372
}
74-
//std::cout<<"Thread "<<obj->id<<" done responding\n";
7573
}
7674
}
7775

@@ -82,11 +80,9 @@ void *MSI::request_worker(void *arg) {
8280

8381
pthread_mutex_lock(&Protocol::lock);
8482
while(true) {
85-
//fflush(stdout);
8683
while(!Protocol::ready || Protocol::request_id != obj->id) {
8784
pthread_cond_wait(&Protocol::worker_cv, &Protocol::lock);
8885
}
89-
//fflush(stdout);
9086
std::cout<<"Thread "<<obj->id<< " got request\n";
9187
op = Protocol::request_op;
9288
addr = Protocol::request_addr;
@@ -101,7 +97,6 @@ void *MSI::request_worker(void *arg) {
10197
handle_request(obj, op, addr);
10298
std::cout<<"Thread " << obj->id<<" Done with request\n";
10399
pthread_mutex_lock(&Protocol::lock);
104-
//std::cout<<"done handling\n";
105100
fflush(stdout);
106101
Protocol::trace_count++;
107102
}
@@ -137,9 +132,7 @@ void MSI::handle_request(MSI *obj, std::string op, unsigned long addr) {
137132
assert(op == "W");
138133
obj->cache.update_cache_lru(addr);
139134
obj->opt = BusRdX;
140-
//std::cout<<"Before wait\n";
141135
Bus::wait_for_responses(obj->id, addr, BusRdX);
142-
//std::cout<<"After wait\n";
143136
if(Bus::recv_nak) {
144137
done = false;
145138
} else {
@@ -149,9 +142,7 @@ void MSI::handle_request(MSI *obj, std::string op, unsigned long addr) {
149142
case Invalid:
150143
if(op == "R") {
151144
obj->opt = BusRd;
152-
//std::cout<<"Before wait\n";
153145
Bus::wait_for_responses(obj->id, addr, BusRd);
154-
//std::cout<<"After wait\n";
155146
if(Bus::recv_nak) {
156147
done = false;
157148
} else {
@@ -189,7 +180,6 @@ void MSI::handle_request(MSI *obj, std::string op, unsigned long addr) {
189180
obj->pending_addr = 0;
190181
pthread_mutex_unlock(&obj->lock);
191182
}
192-
//std::cout<<"Done with memory request\n";
193183
}
194184

195185
}

CacheSim/Memory.cpp

+3-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ pthread_cond_t Memory::req_cv;
1111
//#pragma optimize( "", off )
1212
void dummy_instructions() {
1313

14-
//int x = 100000;
15-
//while(x-- != 0);
1614
usleep(2000); // 2 ms
1715
}
1816
//#pragma optimize( "", on )
@@ -34,28 +32,24 @@ void Memory::initialize() {
3432
}
3533

3634
void *Memory::memory_worker(void *arg) {
37-
//std::cout<<"Memory worker here\n";
3835
pthread_mutex_lock(&lock);
3936
while(true) {
4037
/* Wait while request table is empty */
4138
while(req_table.empty()) {
42-
//std::cout<<"request table empty\n";
4339
pthread_cond_wait(&req_cv, &lock);
44-
//std::cout<<"waking up\n";
4540
}
4641
Protocol::mem_reqs++;
47-
//std::cout<<"got a new request\n";
4842
pthread_mutex_unlock(&lock);
49-
// wait logic - add latency
43+
44+
// wait logic - adds latency
5045
dummy_instructions();
51-
//
46+
5247
pthread_mutex_lock(&lock);
5348
MemRequest *req = req_table.front();
5449
req->done = true;
5550
/* Multiple caches might be waiting on this */
5651
pthread_cond_broadcast(&req->cv);
5752
req_table.pop_front();
58-
//std::cout<<"Memory done with request\n";
5953
}
6054

6155
/* Never exits */
@@ -98,11 +92,8 @@ void Memory::request(unsigned long addr) {
9892
/* Original thread waits till request is done and while there are no more
9993
* additional waiters
10094
*/
101-
//std::cout<<"Waiting for memory\n";
10295
while(!req.done || req.waiters != 0) {
10396
pthread_cond_wait(&req.cv, &lock);
104-
//std::cout<<req.done<<"\t"<<req.waiters<<"\n";
10597
}
106-
//std::cout<<"Woke up\n";
10798
pthread_mutex_unlock(&lock);
10899
}

CacheSim/Protocol.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ void Protocol::initialize(std::string protocol, int num_cores, int cache_size,
6464
void Protocol::process_mem_access(int thread_id, std::string op,
6565
unsigned long addr) {
6666
pthread_mutex_lock(&lock);
67-
//std::cout<<"Protocol waiting\n";
6867
while(ready) {
6968
pthread_cond_wait(&trace_cv, &lock);
7069
}
71-
//std::cout<<"Protocol done waiting\n";
7270
request_id = thread_id;
7371
request_op = op;
7472
/* Reset the block bits of the address */

0 commit comments

Comments
 (0)