-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.cpp
More file actions
310 lines (268 loc) · 11.4 KB
/
Copy pathController.cpp
File metadata and controls
310 lines (268 loc) · 11.4 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include "Controller.h"
#include "SALP.h"
#include "ALDRAM.h"
//#include "TLDRAM.h"
//using namespace ramulator;
namespace ramulator
{
static vector<int> get_offending_subarray(DRAM<SALP>* channel, vector<int> & addr_vec){
int sa_id = 0;
auto rank = channel->children[addr_vec[int(SALP::Level::Rank)]];
auto bank = rank->children[addr_vec[int(SALP::Level::Bank)]];
auto sa = bank->children[addr_vec[int(SALP::Level::SubArray)]];
for (auto sa_other : bank->children)
if (sa != sa_other && sa_other->state == SALP::State::Opened){
sa_id = sa_other->id;
break;
}
vector<int> offending = addr_vec;
offending[int(SALP::Level::SubArray)] = sa_id;
offending[int(SALP::Level::Row)] = -1;
return offending;
}
template <>
vector<int> Controller<SALP>::get_addr_vec(SALP::Command cmd, list<Request>::iterator req){
if (cmd == SALP::Command::PRE_OTHER)
return get_offending_subarray(channel, req->addr_vec);
else
return req->addr_vec;
}
template <>
bool Controller<SALP>::is_ready(list<Request>::iterator req){
SALP::Command cmd = get_first_cmd(req);
if (cmd == SALP::Command::PRE_OTHER){
vector<int> addr_vec = get_offending_subarray(channel, req->addr_vec);
return channel->check(cmd, addr_vec.data(), clk);
}
else return channel->check(cmd, req->addr_vec.data(), clk);
}
template <>
void Controller<SALP>::initialize_crow_timing(vector<typename SALP::TimingEntry> timing[]
[int(SALP::Command::MAX)], const float trcd_factor, const float tras_factor,
const float twr_factor, const float tfaw_factor) {
assert(channel->spec->type == SALP::Type::MASA && "I didn't check timing for non-MASA implementations.");
if(timing == partial_crow_hit_partial_restore_timing)
printf("Initializing Partial CROW Hit to Partial Restoration Timing... \n");
else if(timing == partial_crow_hit_full_restore_timing)
printf("Initializing Partial CROW Hit to Full Restoration Timing... \n");
else if(timing == full_crow_hit_partial_restore_timing)
printf("Initializing Full CROW Hit to Partial Restoration Timing... \n");
else if(timing == full_crow_hit_full_restore_timing)
printf("Initializing Full CROW Hit to Full Restoration Timing... \n");
else if(timing == crow_copy_timing)
printf("Initializing CROW Copy Timing... \n");
else
assert(false && "Initializing unknown CROW timing.");
// copy the default timing parameters
for(uint l = 0; l < int(SALP::Level::MAX); l++) {
for(uint c = 0; c < int(SALP::Command::MAX); c++) {
timing[l][c] = channel->spec->timing[l][c];
}
}
vector<typename SALP::TimingEntry>* t;
int trcd = 0, tras = 0;
// apply trcd_factor to the related timing params
t = timing[int(SALP::Level::SubArray)];
for (auto& t : t[int(SALP::Command::ACT)]) {
if((t.cmd == SALP::Command::RD) || (t.cmd == SALP::Command::RDA)){
printf("Default ACT-to-RD cycles: %d\n", t.val);
t.val = (int)ceil(t.val * trcd_factor);
trcd = t.val;
printf("New ACT-to-RD cycles: %d\n", t.val);
}
if((t.cmd == SALP::Command::WR) || (t.cmd == SALP::Command::WRA)) {
printf("Default ACT-to-WR cycles: %d\n", t.val);
t.val = (int)ceil(t.val * trcd_factor);
printf("New ACT-to-WR cycles: %d\n", t.val);
}
}
// apply tras_factor to the related timing parameters
t = timing[int(SALP::Level::Rank)];
for (auto& t : t[int(SALP::Command::ACT)]) {
if(t.cmd == SALP::Command::PREA){
printf("Default ACT-to-PREA cycles: %d\n", t.val);
t.val = (int)ceil(t.val * tras_factor);
tras = t.val;
printf("New ACT-to-PREA cycles: %d\n", t.val);
}
}
t = timing[int(SALP::Level::SubArray)];
for (auto& t : t[int(SALP::Command::ACT)]) {
if(t.cmd == SALP::Command::PRE) {
printf("Default ACT-to-PRE cycles: %d\n", t.val);
t.val = (int)ceil(t.val * tras_factor);
printf("New ACT-to-PRE cycles: %d\n", t.val);
}
}
// apply both trcd_factor and tras_factor to tRC
assert(trcd != 0 && tras !=0 && "tRCD or tRAS was not set.");
t = timing[int(SALP::Level::SubArray)];
for (auto& t : t[int(SALP::Command::ACT)]) {
if(t.cmd == SALP::Command::ACT) {
printf("Default ACT-to-ACT cycles: %d\n", t.val);
t.val = trcd + tras;
printf("New ACT-to-ACT cycles: %d\n", t.val);
}
}
// apply twr_factor to the related timing parameters
t = timing[int(SALP::Level::Rank)];
for (auto& t : t[int(SALP::Command::WR)]) {
if(t.cmd == SALP::Command::PREA) {
printf("Default WR-to-PREA cycles: %d\n", t.val);
t.val = channel->spec->speed_entry.nCWL + channel->spec->speed_entry.nBL +
(int)ceil(channel->spec->speed_entry.nWR*twr_factor);
printf("New WR-to-PREA cycles: %d\n", t.val);
}
}
t = timing[int(SALP::Level::SubArray)];
int new_nWA = channel->spec->speed_entry.nCWL + channel->spec->speed_entry.nBL +
(int)ceil((channel->spec->speed_entry.nWR*twr_factor)/2);
for (auto& t : t[int(SALP::Command::WR)]) {
if(t.cmd == SALP::Command::PRE) {
printf("Default WR-to-PRE cycles: %d\n", t.val);
t.val = channel->spec->speed_entry.nCWL + channel->spec->speed_entry.nBL +
(int)ceil(channel->spec->speed_entry.nWR*twr_factor);
printf("New WR-to-PRE cycles: %d\n", t.val);
}
if(((t.cmd == SALP::Command::ACT) || (t.cmd == SALP::Command::SASEL) || (t.cmd == SALP::Command::WR)) && (t.sibling)) {
t.val = new_nWA;
}
}
for (auto& t : t[int(SALP::Command::WRA)]) {
if(t.cmd == SALP::Command::ACT) {
printf("Default WRA-to-ACT cycles: %d\n", t.val);
t.val = channel->spec->speed_entry.nCWL + channel->spec->speed_entry.nBL +
(int)ceil(channel->spec->speed_entry.nWR*twr_factor) +
channel->spec->speed_entry.nRP;
printf("New WRA-to-ACT cycles: %d\n", t.val);
}
if(((t.cmd == SALP::Command::ACT) || (t.cmd == SALP::Command::SASEL) || (t.cmd == SALP::Command::WRA)) && (t.sibling)) {
t.val = new_nWA;
}
}
// apply tfaw_factor to the related timing parameters
t = timing[int(SALP::Level::Rank)];
for (auto& t : t[int(SALP::Command::ACT)]) {
if(t.cmd == SALP::Command::ACT && (t.dist == 4)) {
printf("Default ACT-to-ACT (tFAW) cycles: %d\n", t.val);
t.val = (int)ceil(t.val*tfaw_factor);
printf("New ACT-to-ACT (tFAW) cycles: %d\n", t.val);
}
}
}
template <>
void Controller<ALDRAM>::update_temp(ALDRAM::Temp current_temperature){
channel->spec->aldram_timing(current_temperature);
}
//template <>
//void Controller<TLDRAM>::tick(){
// clk++;
// req_queue_length_sum += readq.size() + writeq.size();
// read_req_queue_length_sum += readq.size();
// write_req_queue_length_sum += writeq.size();
//
// /*** 1. Serve completed reads ***/
// if (pending.size()) {
// Request& req = pending[0];
// if (req.depart <= clk) {
// if (req.depart - req.arrive > 1) {
// read_latency_sum += req.depart - req.arrive;
// channel->update_serving_requests(
// req.addr_vec.data(), -1, clk);
// }
// req.callback(req);
// pending.pop_front();
// }
// }
//
// /*** 2. Should we schedule refreshes? ***/
// refresh->tick_ref();
//
// /*** 3. Should we schedule writes? ***/
// if (!write_mode) {
// // yes -- write queue is almost full or read queue is empty
// if (writeq.size() >= int(0.8 * writeq.max) || readq.size() == 0)
// write_mode = true;
// }
// else {
// // no -- write queue is almost empty and read queue is not empty
// if (writeq.size() <= int(0.2 * writeq.max) && readq.size() != 0)
// write_mode = false;
// }
//
// /*** 4. Find the best command to schedule, if any ***/
// Queue* queue = !write_mode ? &readq : &writeq;
// if (otherq.size())
// queue = &otherq; // "other" requests are rare, so we give them precedence over reads/writes
//
// auto req = scheduler->get_head(queue->q);
// if (req == queue->q.end() || !is_ready(req)) {
// // we couldn't find a command to schedule -- let's try to be speculative
// auto cmd = TLDRAM::Command::PRE;
// vector<int> victim = rowpolicy->get_victim(cmd);
// if (!victim.empty()){
// issue_cmd(cmd, victim);
// }
// return; // nothing more to be done this cycle
// }
//
// if (req->is_first_command) {
// int coreid = req->coreid;
// req->is_first_command = false;
// if (req->type == Request::Type::READ || req->type == Request::Type::WRITE) {
// channel->update_serving_requests(req->addr_vec.data(), 1, clk);
// }
// int tx = (channel->spec->prefetch_size * channel->spec->channel_width / 8);
// if (req->type == Request::Type::READ) {
// if (is_row_hit(req)) {
// ++read_row_hits[coreid];
// ++row_hits;
// } else if (is_row_open(req)) {
// ++read_row_conflicts[coreid];
// ++row_conflicts;
// } else {
// ++read_row_misses[coreid];
// ++row_misses;
// }
// read_transaction_bytes += tx;
// } else if (req->type == Request::Type::WRITE) {
// if (is_row_hit(req)) {
// ++write_row_hits[coreid];
// ++row_hits;
// } else if (is_row_open(req)) {
// ++write_row_conflicts[coreid];
// ++row_conflicts;
// } else {
// ++write_row_misses[coreid];
// ++row_misses;
// }
// write_transaction_bytes += tx;
// }
// }
//
// /*** 5. Change a read request to a migration request ***/
// if (req->type == Request::Type::READ) {
// req->type = Request::Type::EXTENSION;
// }
//
// // issue command on behalf of request
// auto cmd = get_first_cmd(req);
// issue_cmd(cmd, get_addr_vec(cmd, req));
//
// // check whether this is the last command (which finishes the request)
// if (cmd != channel->spec->translate[int(req->type)])
// return;
//
// // set a future completion time for read requests
// if (req->type == Request::Type::READ || req->type == Request::Type::EXTENSION) {
// req->depart = clk + channel->spec->read_latency;
// pending.push_back(*req);
// }
// if (req->type == Request::Type::WRITE) {
// channel->update_serving_requests(req->addr_vec.data(), -1, clk);
// }
//
// // remove request from queue
// queue->q.erase(req);
//}
} /* namespace ramulator */