-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.cpp
240 lines (210 loc) · 7.32 KB
/
controller.cpp
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
#include "controller.h"
using namespace std;
using namespace simple;
Controller::Controller(int num_cpus)
{
tid = 0;
cont_num_cpus = num_cpus;
cout << "TM controller:: cores == " << cont_num_cpus << "\n";
//trans_handler.setSize(cont_num_cpus);
tc = new Thrift_Client();
cout << "TM controller created a thrift client" << endl;
txs = new int[cont_num_cpus];
for(int i = 0; i < cont_num_cpus; i++)
{
trans_handler.push_back(new Transaction(i, tc));
txs[i] = 0;
}
}
Controller::~Controller()
{
for(int i = 0; i < cont_num_cpus; i++)
delete trans_handler[i];
}
/*void Controller::BeginTransactionPC(logical_address_t pc)
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
trans_handler[cpu_num]->SetBeginPC(pc);
}*/
void Controller::BeginTransaction()
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
//txs[cpu_num]++;
//cout << "[" << cpu_num << "] cont-begin == " << txs[cpu_num] << endl;
//assert(txs[cpu_num] == 1);
if(trans_handler[cpu_num]->nestingLevel() == 0) {
trans_handler[cpu_num]->BeginTransaction(tid);
tid++;
//SIM_stacked_post(SIM_get_processor(cpu_num), begin_transaction_idx, NULL);
//tc->operate(cpu_num, BEGIN, (int)SIM_cycle_count(SIM_current_processor()));
}
}
void Controller::BeginTransactionIdx(int cpu_num)
{
trans_handler[cpu_num]->BeginTransaction(tid++);
SIM_clear_exception();
}
void Controller::CommitTransaction()
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
int bufferSize = trans_handler[cpu_num]->getWriteBufferSize();
for(int i = 0; i < cont_num_cpus; i++)
{
if(i != cpu_num && trans_handler[i]->runningTransaction()) {
for(int w = 0; w < bufferSize; w++)
{
physical_address_t addr = trans_handler[cpu_num]->getBufferedWrite(w);
if(trans_handler[i]->CheckForReadConflict(addr & ~3))
{
//trans_handler[i]->AbortTransaction();
cout << "[" << cpu_num << "] aborts [" << i << "]" << endl;
SIM_stacked_post(SIM_get_processor(i), abort_transaction_idx, NULL);
break;
}
}
}
}
/* for(int w = 0; w < bufferSize; w++)
{
physical_address_t addr = trans_handler[cpu_num]->getBufferedWrite(w);
for(int i = 0; i < cont_num_cpus; i++)
{
if(i != cpu_num && trans_handler[i]->runningTransaction()) {
if(trans_handler[i]->CheckForReadConflict(addr & ~3))
{
//trans_handler[i]->AbortTransaction();
SIM_stacked_post(SIM_get_processor(i), abort_transaction_idx, NULL);
}
}
}
}
*/
SIM_stacked_post(SIM_current_processor(), commit_transaction_idx, NULL);
//trans_handler[cpu_num]->CommitTransaction();
}
void Controller::CommitTransactionIdx(int cpu_num)
{
trans_handler[cpu_num]->CommitTransaction();
if(SIM_get_pending_exception()) {
SIM_last_error();
}
SIM_clear_exception();
}
void Controller::AbortTransaction()
{
int cpu = SIM_get_processor_number(SIM_current_processor());
cout << "[" << cpu << "] self-aborting " << endl;
SIM_stacked_post(SIM_current_processor(), abort_transaction_idx, NULL);
//assert(0);
//int cpu_num = SIM_get_processor_number(SIM_current_processor());
//--//txs[cpu_num]--;
//--//cout << "[" << cpu_num << "] cont-abort == " << txs[cpu_num] << endl;
//--//assert(txs[cpu_num] == 0);
//trans_handler[cpu_num]->AbortTransaction();
//--//tc->operate(cpu_num, ABORT, (int)SIM_cycle_count(SIM_current_processor()));
}
void Controller::AbortTransactionIdx(int cpu_num)
{
if(trans_handler[cpu_num]->runningTransaction() || trans_handler[cpu_num]->inException()) {
trans_handler[cpu_num]->AbortTransaction();
if(SIM_get_pending_exception()) {
SIM_last_error();
}
SIM_clear_exception();
}
}
void Controller::ResumeTransaction()
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
trans_handler[cpu_num]->ResumeTransaction();
}
void Controller::DisableInterrupts()
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
trans_handler[cpu_num]->disableInterrupts();
}
void Controller::EnableInterrupts()
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
trans_handler[cpu_num]->enableInterrupts();
}
void Controller::EarlyRelease(int var)
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
trans_handler[cpu_num]->earlyRelease(var);
}
int Controller::MemoryOperation(generic_transaction_t *mop)
{
if(SIM_mem_op_is_from_cpu(mop) && ((x86_memory_transaction_t*)mop)->mode == Sim_CPU_Mode_User) {
int cpu_num = SIM_get_processor_number(SIM_current_processor());
if(trans_handler[cpu_num]->runningTransaction())
{
int res = trans_handler[cpu_num]->MemoryOperation(mop);
if(res == Sim_Trans_Load) {
//tc->operate(cpu_num, LOAD, (int)mop->physical_address);
if(!trans_handler[cpu_num]->lastLoad(mop->physical_address))
return 100;
}
else if(res == Sim_Trans_Store) {
//tc->operate(cpu_num, STORE, (int)mop->physical_address);
}
}
}
return 0;
}
int Controller::MemoryObserve(generic_transaction_t *mop)
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
if(trans_handler[cpu_num]->runningTransaction()
&& ((x86_memory_transaction_t*)mop)->mode == Sim_CPU_Mode_User)
{
int res = trans_handler[cpu_num]->MemoryObserve(mop);
if(res == Sim_Trans_Load) {
//tc->operate(cpu_num, LOAD, (int)mop->physical_address);
//return 10;
}
else if(res == Sim_Trans_Store) {
//tc->operate(cpu_num, STORE, (int)mop->physical_address);
}
}
else { //not transaction, need to compare to other transactions
for(int i = 0; i < cont_num_cpus; i++) {
if(i != cpu_num && trans_handler[i]->runningTransaction() && mop->type == Sim_Trans_Store) {
int addr = mop->physical_address;
int size = mop->size;
if(trans_handler[i]->CheckForReadConflict(addr, size))
{
cout << "Non-transactional write on core [" << cpu_num << "] kills core [" << i << "]!" << endl;
//trans_handler[i]->AbortTransaction();
SIM_stacked_post(SIM_get_processor(i), abort_transaction_idx, NULL);
//tc->operate(i, ABORT, (int)SIM_cycle_count(SIM_current_processor()));
}
}
}
}
return 0;
}
bool Controller::InTransaction(int cpu)
{
return trans_handler[cpu]->runningTransaction();
}
bool Controller::InException(int cpu)
{
return trans_handler[cpu]->inException();
}
int Controller::handlingException(int cpu, int exception)
{
int depth = trans_handler[cpu]->handlingException(exception);
//if(depth == 1)
//CommitTransaction();
return depth;
}
int Controller::clearingException(int cpu, int exception)
{
return trans_handler[cpu]->clearingException(exception);
}
void Controller::DumpStats(void)
{
int cpu_num = SIM_get_processor_number(SIM_current_processor());
tc->operate(cpu_num, TX_INFO, 0);
}