41 #ifndef __CPU_O3_ROB_IMPL_HH__
42 #define __CPU_O3_ROB_IMPL_HH__
48 #include "debug/Fetch.hh"
49 #include "debug/ROB.hh"
50 #include "params/DerivO3CPU.hh"
56 : robPolicy(params->smtROBPolicy),
58 numEntries(params->numROBEntries),
59 squashWidth(params->squashWidth),
61 numThreads(params->numThreads),
65 if (
robPolicy == SMTQueuePolicy::Dynamic) {
71 }
else if (
robPolicy == SMTQueuePolicy::Partitioned) {
72 DPRINTF(Fetch,
"ROB sharing policy set to Partitioned\n");
82 }
else if (
robPolicy == SMTQueuePolicy::Threshold) {
83 DPRINTF(Fetch,
"ROB sharing policy set to Threshold\n");
85 int threshold = params->smtROBThreshold;;
100 template <
class Impl>
104 for (
ThreadID tid = 0; tid < Impl::MaxThreads; tid++) {
105 threadEntries[tid] = 0;
106 squashIt[tid] = instList[tid].end();
107 squashedSeqNum[tid] = 0;
108 doneSquashing[tid] =
true;
114 head = instList[0].end();
115 tail = instList[0].end();
118 template <
class Impl>
122 return cpu->name() +
".rob";
125 template <
class Impl>
129 DPRINTF(
ROB,
"Setting active threads list pointer.\n");
130 activeThreads = at_ptr;
133 template <
class Impl>
137 for (
ThreadID tid = 0; tid < numThreads; tid++)
138 assert(instList[tid].empty());
142 template <
class Impl>
149 template <
class Impl>
153 if (robPolicy != SMTQueuePolicy::Dynamic || numThreads > 1) {
154 auto active_threads = activeThreads->size();
159 while (threads != end) {
162 if (robPolicy == SMTQueuePolicy::Partitioned) {
163 maxEntries[tid] = numEntries / active_threads;
164 }
else if (robPolicy == SMTQueuePolicy::Threshold &&
165 active_threads == 1) {
166 maxEntries[tid] = numEntries;
172 template <
class Impl>
176 if (robPolicy == SMTQueuePolicy::Partitioned) {
177 return numEntries / num_threads;
183 template <
class Impl>
189 for (
ThreadID tid = 0; tid < numThreads; tid++)
190 total += countInsts(tid);
195 template <
class Impl>
199 return instList[tid].size();
202 template <
class Impl>
210 DPRINTF(
ROB,
"Adding inst PC %s to the ROB.\n", inst->pcState());
212 assert(numInstsInROB != numEntries);
216 instList[tid].push_back(inst);
219 if (numInstsInROB == 0) {
220 head = instList[tid].begin();
221 assert((*head) == inst);
226 tail = instList[tid].end();
232 ++threadEntries[tid];
234 assert((*tail) == inst);
236 DPRINTF(
ROB,
"[tid:%i] Now has %d instructions.\n", tid, threadEntries[tid]);
239 template <
class Impl>
245 assert(numInstsInROB > 0);
248 InstIt head_it = instList[tid].begin();
251 instList[tid].erase(head_it);
253 assert(head_inst->readyToCommit());
255 DPRINTF(
ROB,
"[tid:%i] Retiring head instruction, "
256 "instruction PC %s, [sn:%llu]\n", tid, head_inst->pcState(),
260 --threadEntries[tid];
262 head_inst->clearInROB();
263 head_inst->setCommitted();
271 cpu->removeFrontInst(head_inst);
274 template <
class Impl>
279 if (threadEntries[tid] != 0) {
280 return instList[tid].front()->readyToCommit();
286 template <
class Impl>
294 while (threads != end) {
297 if (isHeadReady(tid)) {
305 template <
class Impl>
309 return numEntries - numInstsInROB;
312 template <
class Impl>
316 return maxEntries[tid] - threadEntries[tid];
319 template <
class Impl>
324 DPRINTF(
ROB,
"[tid:%i] Squashing instructions until [sn:%llu].\n",
325 tid, squashedSeqNum[tid]);
327 assert(squashIt[tid] != instList[tid].end());
329 if ((*squashIt[tid])->seqNum < squashedSeqNum[tid]) {
330 DPRINTF(
ROB,
"[tid:%i] Done squashing instructions.\n",
333 squashIt[tid] = instList[tid].end();
335 doneSquashing[tid] =
true;
339 bool robTailUpdate =
false;
341 for (
int numSquashed = 0;
342 numSquashed < squashWidth &&
343 squashIt[tid] != instList[tid].end() &&
344 (*squashIt[tid])->seqNum > squashedSeqNum[tid];
347 DPRINTF(
ROB,
"[tid:%i] Squashing instruction PC %s, seq num %i.\n",
348 (*squashIt[tid])->threadNumber,
349 (*squashIt[tid])->pcState(),
350 (*squashIt[tid])->seqNum);
354 (*squashIt[tid])->setSquashed();
356 (*squashIt[tid])->setCanCommit();
359 if (squashIt[tid] == instList[tid].begin()) {
360 DPRINTF(
ROB,
"Reached head of instruction list while "
363 squashIt[tid] = instList[tid].end();
365 doneSquashing[tid] =
true;
370 InstIt tail_thread = instList[tid].end();
373 if ((*squashIt[tid]) == (*tail_thread))
374 robTailUpdate =
true;
381 if ((*squashIt[tid])->seqNum <= squashedSeqNum[tid]) {
382 DPRINTF(
ROB,
"[tid:%i] Done squashing instructions.\n",
385 squashIt[tid] = instList[tid].end();
387 doneSquashing[tid] =
true;
396 template <
class Impl>
401 bool first_valid =
true;
407 while (threads != end) {
410 if (instList[tid].empty())
414 head = instList[tid].begin();
415 lowest_num = (*head)->seqNum;
420 InstIt head_thread = instList[tid].begin();
424 assert(head_inst != 0);
426 if (head_inst->seqNum < lowest_num) {
428 lowest_num = head_inst->seqNum;
433 head = instList[0].end();
438 template <
class Impl>
442 tail = instList[0].end();
443 bool first_valid =
true;
448 while (threads != end) {
451 if (instList[tid].empty()) {
458 tail = instList[tid].end();
466 InstIt tail_thread = instList[tid].end();
469 if ((*tail_thread)->seqNum > (*tail)->seqNum) {
476 template <
class Impl>
481 DPRINTF(
ROB,
"Does not need to squash due to being empty "
488 DPRINTF(
ROB,
"Starting to squash within the ROB.\n");
490 robStatus[tid] = ROBSquashing;
492 doneSquashing[tid] =
false;
494 squashedSeqNum[tid] = squash_num;
496 if (!instList[tid].empty()) {
497 InstIt tail_thread = instList[tid].end();
500 squashIt[tid] = tail_thread;
506 template <
class Impl>
507 const typename Impl::DynInstPtr&
510 if (threadEntries[tid] != 0) {
511 InstIt head_thread = instList[tid].begin();
513 assert((*head_thread)->isInROB());
521 template <
class Impl>
522 typename Impl::DynInstPtr
525 InstIt tail_thread = instList[tid].end();
531 template <
class Impl>
533 :
Stats::Group(parent,
"rob"),
534 ADD_STAT(reads,
"The number of ROB reads"),
535 ADD_STAT(writes,
"The number of ROB writes")
539 template <
class Impl>
540 typename Impl::DynInstPtr
544 if ((*it)->seqNum == squash_inst) {
551 #endif//__CPU_O3_ROB_IMPL_HH__