gem5  v22.1.0.0
iew.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013, 2018-2019 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2004-2006 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 // @todo: Fix the instantaneous communication among all the stages within
43 // iew. There's a clear delay between issue and execute, yet backwards
44 // communication happens simultaneously.
45 
46 #include "cpu/o3/iew.hh"
47 
48 #include <queue>
49 
50 #include "cpu/checker/cpu.hh"
51 #include "cpu/o3/dyn_inst.hh"
52 #include "cpu/o3/fu_pool.hh"
53 #include "cpu/o3/limits.hh"
54 #include "cpu/timebuf.hh"
55 #include "debug/Activity.hh"
56 #include "debug/Drain.hh"
57 #include "debug/IEW.hh"
58 #include "debug/O3PipeView.hh"
59 #include "params/BaseO3CPU.hh"
60 
61 namespace gem5
62 {
63 
64 namespace o3
65 {
66 
67 IEW::IEW(CPU *_cpu, const BaseO3CPUParams &params)
68  : issueToExecQueue(params.backComSize, params.forwardComSize),
69  cpu(_cpu),
70  instQueue(_cpu, this, params),
71  ldstQueue(_cpu, this, params),
72  fuPool(params.fuPool),
73  commitToIEWDelay(params.commitToIEWDelay),
74  renameToIEWDelay(params.renameToIEWDelay),
75  issueToExecuteDelay(params.issueToExecuteDelay),
76  dispatchWidth(params.dispatchWidth),
77  issueWidth(params.issueWidth),
78  wbNumInst(0),
79  wbCycle(0),
80  wbWidth(params.wbWidth),
81  numThreads(params.numThreads),
82  iewStats(cpu)
83 {
84  if (dispatchWidth > MaxWidth)
85  fatal("dispatchWidth (%d) is larger than compiled limit (%d),\n"
86  "\tincrease MaxWidth in src/cpu/o3/limits.hh\n",
87  dispatchWidth, static_cast<int>(MaxWidth));
88  if (issueWidth > MaxWidth)
89  fatal("issueWidth (%d) is larger than compiled limit (%d),\n"
90  "\tincrease MaxWidth in src/cpu/o3/limits.hh\n",
91  issueWidth, static_cast<int>(MaxWidth));
92  if (wbWidth > MaxWidth)
93  fatal("wbWidth (%d) is larger than compiled limit (%d),\n"
94  "\tincrease MaxWidth in src/cpu/o3/limits.hh\n",
95  wbWidth, static_cast<int>(MaxWidth));
96 
97  _status = Active;
99  wbStatus = Idle;
100 
101  // Setup wire to read instructions coming from issue.
103 
104  // Instruction queue needs the queue between issue and execute.
106 
107  for (ThreadID tid = 0; tid < MaxThreads; tid++) {
108  dispatchStatus[tid] = Running;
109  fetchRedirect[tid] = false;
110  }
111 
112  updateLSQNextCycle = false;
113 
114  skidBufferMax = (renameToIEWDelay + 1) * params.renameWidth;
115 }
116 
117 std::string
118 IEW::name() const
119 {
120  return cpu->name() + ".iew";
121 }
122 
123 void
125 {
127  cpu->getProbeManager(), "Dispatch");
129  cpu->getProbeManager(), "Mispredict");
135  cpu->getProbeManager(), "Execute");
141  cpu->getProbeManager(), "ToCommit");
142 }
143 
145  : statistics::Group(cpu, "iew"),
146  ADD_STAT(idleCycles, statistics::units::Cycle::get(),
147  "Number of cycles IEW is idle"),
148  ADD_STAT(squashCycles, statistics::units::Cycle::get(),
149  "Number of cycles IEW is squashing"),
150  ADD_STAT(blockCycles, statistics::units::Cycle::get(),
151  "Number of cycles IEW is blocking"),
152  ADD_STAT(unblockCycles, statistics::units::Cycle::get(),
153  "Number of cycles IEW is unblocking"),
154  ADD_STAT(dispatchedInsts, statistics::units::Count::get(),
155  "Number of instructions dispatched to IQ"),
156  ADD_STAT(dispSquashedInsts, statistics::units::Count::get(),
157  "Number of squashed instructions skipped by dispatch"),
158  ADD_STAT(dispLoadInsts, statistics::units::Count::get(),
159  "Number of dispatched load instructions"),
160  ADD_STAT(dispStoreInsts, statistics::units::Count::get(),
161  "Number of dispatched store instructions"),
162  ADD_STAT(dispNonSpecInsts, statistics::units::Count::get(),
163  "Number of dispatched non-speculative instructions"),
164  ADD_STAT(iqFullEvents, statistics::units::Count::get(),
165  "Number of times the IQ has become full, causing a stall"),
166  ADD_STAT(lsqFullEvents, statistics::units::Count::get(),
167  "Number of times the LSQ has become full, causing a stall"),
168  ADD_STAT(memOrderViolationEvents, statistics::units::Count::get(),
169  "Number of memory order violations"),
170  ADD_STAT(predictedTakenIncorrect, statistics::units::Count::get(),
171  "Number of branches that were predicted taken incorrectly"),
172  ADD_STAT(predictedNotTakenIncorrect, statistics::units::Count::get(),
173  "Number of branches that were predicted not taken incorrectly"),
174  ADD_STAT(branchMispredicts, statistics::units::Count::get(),
175  "Number of branch mispredicts detected at execute",
176  predictedTakenIncorrect + predictedNotTakenIncorrect),
177  executedInstStats(cpu),
178  ADD_STAT(instsToCommit, statistics::units::Count::get(),
179  "Cumulative count of insts sent to commit"),
180  ADD_STAT(writebackCount, statistics::units::Count::get(),
181  "Cumulative count of insts written-back"),
182  ADD_STAT(producerInst, statistics::units::Count::get(),
183  "Number of instructions producing a value"),
184  ADD_STAT(consumerInst, statistics::units::Count::get(),
185  "Number of instructions consuming a value"),
186  ADD_STAT(wbRate, statistics::units::Rate<
187  statistics::units::Count, statistics::units::Cycle>::get(),
188  "Insts written-back per cycle"),
189  ADD_STAT(wbFanout, statistics::units::Rate<
190  statistics::units::Count, statistics::units::Count>::get(),
191  "Average fanout of values written-back")
192 {
194  .init(cpu->numThreads)
196 
198  .init(cpu->numThreads)
200 
202  .init(cpu->numThreads)
204 
206  .init(cpu->numThreads)
208 
209  wbRate
212 
213  wbFanout
216 }
217 
219  : statistics::Group(cpu),
220  ADD_STAT(numInsts, statistics::units::Count::get(),
221  "Number of executed instructions"),
222  ADD_STAT(numLoadInsts, statistics::units::Count::get(),
223  "Number of load instructions executed"),
224  ADD_STAT(numSquashedInsts, statistics::units::Count::get(),
225  "Number of squashed instructions skipped in execute"),
226  ADD_STAT(numSwp, statistics::units::Count::get(),
227  "Number of swp insts executed"),
228  ADD_STAT(numNop, statistics::units::Count::get(),
229  "Number of nop insts executed"),
230  ADD_STAT(numRefs, statistics::units::Count::get(),
231  "Number of memory reference insts executed"),
232  ADD_STAT(numBranches, statistics::units::Count::get(),
233  "Number of branches executed"),
234  ADD_STAT(numStoreInsts, statistics::units::Count::get(),
235  "Number of stores executed"),
236  ADD_STAT(numRate, statistics::units::Rate<
237  statistics::units::Count, statistics::units::Cycle>::get(),
238  "Inst execution rate", numInsts / cpu->baseStats.numCycles)
239 {
241  .init(cpu->numThreads)
243 
244  numSwp
245  .init(cpu->numThreads)
247 
248  numNop
249  .init(cpu->numThreads)
251 
252  numRefs
253  .init(cpu->numThreads)
255 
257  .init(cpu->numThreads)
259 
263 
264  numRate
266 }
267 
268 void
270 {
271  for (ThreadID tid = 0; tid < numThreads; tid++) {
272  toRename->iewInfo[tid].usedIQ = true;
273  toRename->iewInfo[tid].freeIQEntries =
275 
276  toRename->iewInfo[tid].usedLSQ = true;
277  toRename->iewInfo[tid].freeLQEntries =
279  toRename->iewInfo[tid].freeSQEntries =
281  }
282 
283  // Initialize the checker's dcache port here
284  if (cpu->checker) {
285  cpu->checker->setDcachePort(&ldstQueue.getDataPort());
286  }
287 
289 }
290 
291 void
293 {
294  toRename->iewInfo[tid].usedIQ = true;
295  toRename->iewInfo[tid].freeIQEntries =
297 
298  toRename->iewInfo[tid].usedLSQ = true;
299  toRename->iewInfo[tid].freeLQEntries = ldstQueue.numFreeLoadEntries(tid);
300  toRename->iewInfo[tid].freeSQEntries = ldstQueue.numFreeStoreEntries(tid);
301 }
302 
303 void
305 {
306  timeBuffer = tb_ptr;
307 
308  // Setup wire to read information from time buffer, from commit.
310 
311  // Setup wire to write information back to previous stages.
312  toRename = timeBuffer->getWire(0);
313 
314  toFetch = timeBuffer->getWire(0);
315 
316  // Instruction queue also needs main time buffer.
317  instQueue.setTimeBuffer(tb_ptr);
318 }
319 
320 void
322 {
323  renameQueue = rq_ptr;
324 
325  // Setup wire to read information from rename queue.
327 }
328 
329 void
331 {
332  iewQueue = iq_ptr;
333 
334  // Setup wire to write instructions to commit.
335  toCommit = iewQueue->getWire(0);
336 }
337 
338 void
340 {
341  activeThreads = at_ptr;
342 
343  ldstQueue.setActiveThreads(at_ptr);
344  instQueue.setActiveThreads(at_ptr);
345 }
346 
347 void
349 {
350  scoreboard = sb_ptr;
351 }
352 
353 bool
355 {
356  bool drained = ldstQueue.isDrained() && instQueue.isDrained();
357 
358  for (ThreadID tid = 0; tid < numThreads; tid++) {
359  if (!insts[tid].empty()) {
360  DPRINTF(Drain, "%i: Insts not empty.\n", tid);
361  drained = false;
362  }
363  if (!skidBuffer[tid].empty()) {
364  DPRINTF(Drain, "%i: Skid buffer not empty.\n", tid);
365  drained = false;
366  }
367  drained = drained && dispatchStatus[tid] == Running;
368  }
369 
370  // Also check the FU pool as instructions are "stored" in FU
371  // completion events until they are done and not accounted for
372  // above
373  if (drained && !fuPool->isDrained()) {
374  DPRINTF(Drain, "FU pool still busy.\n");
375  drained = false;
376  }
377 
378  return drained;
379 }
380 
381 void
383 {
384  assert(isDrained());
385 
388 }
389 
390 void
392 {
393  // Reset all state.
394  _status = Active;
395  exeStatus = Running;
396  wbStatus = Idle;
397 
400  fuPool->takeOverFrom();
401 
402  startupStage();
404 
405  for (ThreadID tid = 0; tid < numThreads; tid++) {
406  dispatchStatus[tid] = Running;
407  fetchRedirect[tid] = false;
408  }
409 
410  updateLSQNextCycle = false;
411 
412  for (int i = 0; i < issueToExecQueue.getSize(); ++i) {
413  issueToExecQueue.advance();
414  }
415 }
416 
417 void
419 {
420  DPRINTF(IEW, "[tid:%i] Squashing all instructions.\n", tid);
421 
422  // Tell the IQ to start squashing.
423  instQueue.squash(tid);
424 
425  // Tell the LDSTQ to start squashing.
426  ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
427  updatedQueues = true;
428 
429  // Clear the skid buffer in case it has any data in it.
430  DPRINTF(IEW,
431  "Removing skidbuffer instructions until "
432  "[sn:%llu] [tid:%i]\n",
433  fromCommit->commitInfo[tid].doneSeqNum, tid);
434 
435  while (!skidBuffer[tid].empty()) {
436  if (skidBuffer[tid].front()->isLoad()) {
437  toRename->iewInfo[tid].dispatchedToLQ++;
438  }
439  if (skidBuffer[tid].front()->isStore() ||
440  skidBuffer[tid].front()->isAtomic()) {
441  toRename->iewInfo[tid].dispatchedToSQ++;
442  }
443 
444  toRename->iewInfo[tid].dispatched++;
445 
446  skidBuffer[tid].pop();
447  }
448 
449  emptyRenameInsts(tid);
450 }
451 
452 void
454 {
455  DPRINTF(IEW, "[tid:%i] [sn:%llu] Squashing from a specific instruction,"
456  " PC: %s "
457  "\n", tid, inst->seqNum, inst->pcState() );
458 
459  if (!toCommit->squash[tid] ||
460  inst->seqNum < toCommit->squashedSeqNum[tid]) {
461  toCommit->squash[tid] = true;
462  toCommit->squashedSeqNum[tid] = inst->seqNum;
463  toCommit->branchTaken[tid] = inst->pcState().branching();
464 
465  set(toCommit->pc[tid], inst->pcState());
466  inst->staticInst->advancePC(*toCommit->pc[tid]);
467 
468  toCommit->mispredictInst[tid] = inst;
469  toCommit->includeSquashInst[tid] = false;
470 
471  wroteToTimeBuffer = true;
472  }
473 
474 }
475 
476 void
478 {
479  DPRINTF(IEW, "[tid:%i] Memory violation, squashing violator and younger "
480  "insts, PC: %s [sn:%llu].\n", tid, inst->pcState(), inst->seqNum);
481  // Need to include inst->seqNum in the following comparison to cover the
482  // corner case when a branch misprediction and a memory violation for the
483  // same instruction (e.g. load PC) are detected in the same cycle. In this
484  // case the memory violator should take precedence over the branch
485  // misprediction because it requires the violator itself to be included in
486  // the squash.
487  if (!toCommit->squash[tid] ||
488  inst->seqNum <= toCommit->squashedSeqNum[tid]) {
489  toCommit->squash[tid] = true;
490 
491  toCommit->squashedSeqNum[tid] = inst->seqNum;
492  set(toCommit->pc[tid], inst->pcState());
493  toCommit->mispredictInst[tid] = NULL;
494 
495  // Must include the memory violator in the squash.
496  toCommit->includeSquashInst[tid] = true;
497 
498  wroteToTimeBuffer = true;
499  }
500 }
501 
502 void
504 {
505  DPRINTF(IEW, "[tid:%i] Blocking.\n", tid);
506 
507  if (dispatchStatus[tid] != Blocked &&
508  dispatchStatus[tid] != Unblocking) {
509  toRename->iewBlock[tid] = true;
510  wroteToTimeBuffer = true;
511  }
512 
513  // Add the current inputs to the skid buffer so they can be
514  // reprocessed when this stage unblocks.
515  skidInsert(tid);
516 
517  dispatchStatus[tid] = Blocked;
518 }
519 
520 void
522 {
523  DPRINTF(IEW, "[tid:%i] Reading instructions out of the skid "
524  "buffer %u.\n",tid, tid);
525 
526  // If the skid bufffer is empty, signal back to previous stages to unblock.
527  // Also switch status to running.
528  if (skidBuffer[tid].empty()) {
529  toRename->iewUnblock[tid] = true;
530  wroteToTimeBuffer = true;
531  DPRINTF(IEW, "[tid:%i] Done unblocking.\n",tid);
532  dispatchStatus[tid] = Running;
533  }
534 }
535 
536 void
538 {
540 }
541 
542 void
544 {
546 }
547 
548 void
550 {
551  instQueue.replayMemInst(inst);
552 }
553 
554 void
556 {
557  instQueue.blockMemInst(inst);
558 }
559 
560 void
562 {
564 }
565 
566 void
568 {
569  // This function should not be called after writebackInsts in a
570  // single cycle. That will cause problems with an instruction
571  // being added to the queue to commit without being processed by
572  // writebackInsts prior to being sent to commit.
573 
574  // First check the time slot that this instruction will write
575  // to. If there are free write ports at the time, then go ahead
576  // and write the instruction to that time. If there are not,
577  // keep looking back to see where's the first time there's a
578  // free slot.
579  while ((*iewQueue)[wbCycle].insts[wbNumInst]) {
580  ++wbNumInst;
581  if (wbNumInst == wbWidth) {
582  ++wbCycle;
583  wbNumInst = 0;
584  }
585  }
586 
587  DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n",
589  // Add finished instruction to queue to commit.
590  (*iewQueue)[wbCycle].insts[wbNumInst] = inst;
591  (*iewQueue)[wbCycle].size++;
592 }
593 
594 void
596 {
597  DynInstPtr inst = NULL;
598 
599  while (!insts[tid].empty()) {
600  inst = insts[tid].front();
601 
602  insts[tid].pop();
603 
604  DPRINTF(IEW,"[tid:%i] Inserting [sn:%lli] PC:%s into "
605  "dispatch skidBuffer %i\n",tid, inst->seqNum,
606  inst->pcState(),tid);
607 
608  skidBuffer[tid].push(inst);
609  }
610 
611  assert(skidBuffer[tid].size() <= skidBufferMax &&
612  "Skidbuffer Exceeded Max Size");
613 }
614 
615 int
617 {
618  int max=0;
619 
620  std::list<ThreadID>::iterator threads = activeThreads->begin();
622 
623  while (threads != end) {
624  ThreadID tid = *threads++;
625  unsigned thread_count = skidBuffer[tid].size();
626  if (max < thread_count)
627  max = thread_count;
628  }
629 
630  return max;
631 }
632 
633 bool
635 {
636  std::list<ThreadID>::iterator threads = activeThreads->begin();
638 
639  while (threads != end) {
640  ThreadID tid = *threads++;
641 
642  if (!skidBuffer[tid].empty())
643  return false;
644  }
645 
646  return true;
647 }
648 
649 void
651 {
652  bool any_unblocking = false;
653 
654  std::list<ThreadID>::iterator threads = activeThreads->begin();
656 
657  while (threads != end) {
658  ThreadID tid = *threads++;
659 
660  if (dispatchStatus[tid] == Unblocking) {
661  any_unblocking = true;
662  break;
663  }
664  }
665 
666  // If there are no ready instructions waiting to be scheduled by the IQ,
667  // and there's no stores waiting to write back, and dispatch is not
668  // unblocking, then there is no internal activity for the IEW stage.
670  if (_status == Active && !instQueue.hasReadyInsts() &&
671  !ldstQueue.willWB() && !any_unblocking) {
672  DPRINTF(IEW, "IEW switching to idle\n");
673 
674  deactivateStage();
675 
676  _status = Inactive;
677  } else if (_status == Inactive && (instQueue.hasReadyInsts() ||
678  ldstQueue.willWB() ||
679  any_unblocking)) {
680  // Otherwise there is internal activity. Set to active.
681  DPRINTF(IEW, "IEW switching to active\n");
682 
683  activateStage();
684 
685  _status = Active;
686  }
687 }
688 
689 bool
691 {
692  bool ret_val(false);
693 
694  if (fromCommit->commitInfo[tid].robSquashing) {
695  DPRINTF(IEW,"[tid:%i] Stall from Commit stage detected.\n",tid);
696  ret_val = true;
697  } else if (instQueue.isFull(tid)) {
698  DPRINTF(IEW,"[tid:%i] Stall: IQ is full.\n",tid);
699  ret_val = true;
700  }
701 
702  return ret_val;
703 }
704 
705 void
707 {
708  // Check if there's a squash signal, squash if there is
709  // Check stall signals, block if there is.
710  // If status was Blocked
711  // if so then go to unblocking
712  // If status was Squashing
713  // check if squashing is not high. Switch to running this cycle.
714 
715  if (fromCommit->commitInfo[tid].squash) {
716  squash(tid);
717 
718  if (dispatchStatus[tid] == Blocked ||
719  dispatchStatus[tid] == Unblocking) {
720  toRename->iewUnblock[tid] = true;
721  wroteToTimeBuffer = true;
722  }
723 
724  dispatchStatus[tid] = Squashing;
725  fetchRedirect[tid] = false;
726  return;
727  }
728 
729  if (fromCommit->commitInfo[tid].robSquashing) {
730  DPRINTF(IEW, "[tid:%i] ROB is still squashing.\n", tid);
731 
732  dispatchStatus[tid] = Squashing;
733  emptyRenameInsts(tid);
734  wroteToTimeBuffer = true;
735  }
736 
737  if (checkStall(tid)) {
738  block(tid);
739  dispatchStatus[tid] = Blocked;
740  return;
741  }
742 
743  if (dispatchStatus[tid] == Blocked) {
744  // Status from previous cycle was blocked, but there are no more stall
745  // conditions. Switch over to unblocking.
746  DPRINTF(IEW, "[tid:%i] Done blocking, switching to unblocking.\n",
747  tid);
748 
749  dispatchStatus[tid] = Unblocking;
750 
751  unblock(tid);
752 
753  return;
754  }
755 
756  if (dispatchStatus[tid] == Squashing) {
757  // Switch status to running if rename isn't being told to block or
758  // squash this cycle.
759  DPRINTF(IEW, "[tid:%i] Done squashing, switching to running.\n",
760  tid);
761 
762  dispatchStatus[tid] = Running;
763 
764  return;
765  }
766 }
767 
768 void
770 {
771  int insts_from_rename = fromRename->size;
772 #ifdef DEBUG
773  for (ThreadID tid = 0; tid < numThreads; tid++)
774  assert(insts[tid].empty());
775 #endif
776  for (int i = 0; i < insts_from_rename; ++i) {
777  insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]);
778  }
779 }
780 
781 void
783 {
784  DPRINTF(IEW, "[tid:%i] Removing incoming rename instructions\n", tid);
785 
786  while (!insts[tid].empty()) {
787 
788  if (insts[tid].front()->isLoad()) {
789  toRename->iewInfo[tid].dispatchedToLQ++;
790  }
791  if (insts[tid].front()->isStore() ||
792  insts[tid].front()->isAtomic()) {
793  toRename->iewInfo[tid].dispatchedToSQ++;
794  }
795 
796  toRename->iewInfo[tid].dispatched++;
797 
798  insts[tid].pop();
799  }
800 }
801 
802 void
804 {
805  cpu->wakeCPU();
806 }
807 
808 void
810 {
811  DPRINTF(Activity, "Activity this cycle.\n");
813 }
814 
815 void
817 {
818  DPRINTF(Activity, "Activating stage.\n");
820 }
821 
822 void
824 {
825  DPRINTF(Activity, "Deactivating stage.\n");
827 }
828 
829 void
831 {
832  // If status is Running or idle,
833  // call dispatchInsts()
834  // If status is Unblocking,
835  // buffer any instructions coming from rename
836  // continue trying to empty skid buffer
837  // check if stall conditions have passed
838 
839  if (dispatchStatus[tid] == Blocked) {
841 
842  } else if (dispatchStatus[tid] == Squashing) {
844  }
845 
846  // Dispatch should try to dispatch as many instructions as its bandwidth
847  // will allow, as long as it is not currently blocked.
848  if (dispatchStatus[tid] == Running ||
849  dispatchStatus[tid] == Idle) {
850  DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run "
851  "dispatch.\n", tid);
852 
853  dispatchInsts(tid);
854  } else if (dispatchStatus[tid] == Unblocking) {
855  // Make sure that the skid buffer has something in it if the
856  // status is unblocking.
857  assert(!skidsEmpty());
858 
859  // If the status was unblocking, then instructions from the skid
860  // buffer were used. Remove those instructions and handle
861  // the rest of unblocking.
862  dispatchInsts(tid);
863 
865 
866  if (fromRename->size != 0) {
867  // Add the current inputs to the skid buffer so they can be
868  // reprocessed when this stage unblocks.
869  skidInsert(tid);
870  }
871 
872  unblock(tid);
873  }
874 }
875 
876 void
878 {
879  // Obtain instructions from skid buffer if unblocking, or queue from rename
880  // otherwise.
881  std::queue<DynInstPtr> &insts_to_dispatch =
882  dispatchStatus[tid] == Unblocking ?
883  skidBuffer[tid] : insts[tid];
884 
885  int insts_to_add = insts_to_dispatch.size();
886 
887  DynInstPtr inst;
888  bool add_to_iq = false;
889  int dis_num_inst = 0;
890 
891  // Loop through the instructions, putting them in the instruction
892  // queue.
893  for ( ; dis_num_inst < insts_to_add &&
894  dis_num_inst < dispatchWidth;
895  ++dis_num_inst)
896  {
897  inst = insts_to_dispatch.front();
898 
899  if (dispatchStatus[tid] == Unblocking) {
900  DPRINTF(IEW, "[tid:%i] Issue: Examining instruction from skid "
901  "buffer\n", tid);
902  }
903 
904  // Make sure there's a valid instruction there.
905  assert(inst);
906 
907  DPRINTF(IEW, "[tid:%i] Issue: Adding PC %s [sn:%lli] [tid:%i] to "
908  "IQ.\n",
909  tid, inst->pcState(), inst->seqNum, inst->threadNumber);
910 
911  // Be sure to mark these instructions as ready so that the
912  // commit stage can go ahead and execute them, and mark
913  // them as issued so the IQ doesn't reprocess them.
914 
915  // Check for squashed instructions.
916  if (inst->isSquashed()) {
917  DPRINTF(IEW, "[tid:%i] Issue: Squashed instruction encountered, "
918  "not adding to IQ.\n", tid);
919 
921 
922  insts_to_dispatch.pop();
923 
924  //Tell Rename That An Instruction has been processed
925  if (inst->isLoad()) {
926  toRename->iewInfo[tid].dispatchedToLQ++;
927  }
928  if (inst->isStore() || inst->isAtomic()) {
929  toRename->iewInfo[tid].dispatchedToSQ++;
930  }
931 
932  toRename->iewInfo[tid].dispatched++;
933 
934  continue;
935  }
936 
937  // Check for full conditions.
938  if (instQueue.isFull(tid)) {
939  DPRINTF(IEW, "[tid:%i] Issue: IQ has become full.\n", tid);
940 
941  // Call function to start blocking.
942  block(tid);
943 
944  // Set unblock to false. Special case where we are using
945  // skidbuffer (unblocking) instructions but then we still
946  // get full in the IQ.
947  toRename->iewUnblock[tid] = false;
948 
950  break;
951  }
952 
953  // Check LSQ if inst is LD/ST
954  if ((inst->isAtomic() && ldstQueue.sqFull(tid)) ||
955  (inst->isLoad() && ldstQueue.lqFull(tid)) ||
956  (inst->isStore() && ldstQueue.sqFull(tid))) {
957  DPRINTF(IEW, "[tid:%i] Issue: %s has become full.\n",tid,
958  inst->isLoad() ? "LQ" : "SQ");
959 
960  // Call function to start blocking.
961  block(tid);
962 
963  // Set unblock to false. Special case where we are using
964  // skidbuffer (unblocking) instructions but then we still
965  // get full in the IQ.
966  toRename->iewUnblock[tid] = false;
967 
969  break;
970  }
971 
972  // hardware transactional memory
973  // CPU needs to track transactional state in program order.
974  const int numHtmStarts = ldstQueue.numHtmStarts(tid);
975  const int numHtmStops = ldstQueue.numHtmStops(tid);
976  const int htmDepth = numHtmStarts - numHtmStops;
977 
978  if (htmDepth > 0) {
979  inst->setHtmTransactionalState(ldstQueue.getLatestHtmUid(tid),
980  htmDepth);
981  } else {
982  inst->clearHtmTransactionalState();
983  }
984 
985 
986  // Otherwise issue the instruction just fine.
987  if (inst->isAtomic()) {
988  DPRINTF(IEW, "[tid:%i] Issue: Memory instruction "
989  "encountered, adding to LSQ.\n", tid);
990 
991  ldstQueue.insertStore(inst);
992 
994 
995  // AMOs need to be set as "canCommit()"
996  // so that commit can process them when they reach the
997  // head of commit.
998  inst->setCanCommit();
999  instQueue.insertNonSpec(inst);
1000  add_to_iq = false;
1001 
1003 
1004  toRename->iewInfo[tid].dispatchedToSQ++;
1005  } else if (inst->isLoad()) {
1006  DPRINTF(IEW, "[tid:%i] Issue: Memory instruction "
1007  "encountered, adding to LSQ.\n", tid);
1008 
1009  // Reserve a spot in the load store queue for this
1010  // memory access.
1011  ldstQueue.insertLoad(inst);
1012 
1014 
1015  add_to_iq = true;
1016 
1017  toRename->iewInfo[tid].dispatchedToLQ++;
1018  } else if (inst->isStore()) {
1019  DPRINTF(IEW, "[tid:%i] Issue: Memory instruction "
1020  "encountered, adding to LSQ.\n", tid);
1021 
1022  ldstQueue.insertStore(inst);
1023 
1025 
1026  if (inst->isStoreConditional()) {
1027  // Store conditionals need to be set as "canCommit()"
1028  // so that commit can process them when they reach the
1029  // head of commit.
1030  // @todo: This is somewhat specific to Alpha.
1031  inst->setCanCommit();
1032  instQueue.insertNonSpec(inst);
1033  add_to_iq = false;
1034 
1036  } else {
1037  add_to_iq = true;
1038  }
1039 
1040  toRename->iewInfo[tid].dispatchedToSQ++;
1041  } else if (inst->isReadBarrier() || inst->isWriteBarrier()) {
1042  // Same as non-speculative stores.
1043  inst->setCanCommit();
1044  instQueue.insertBarrier(inst);
1045  add_to_iq = false;
1046  } else if (inst->isNop()) {
1047  DPRINTF(IEW, "[tid:%i] Issue: Nop instruction encountered, "
1048  "skipping.\n", tid);
1049 
1050  inst->setIssued();
1051  inst->setExecuted();
1052  inst->setCanCommit();
1053 
1054  instQueue.recordProducer(inst);
1055 
1057 
1058  add_to_iq = false;
1059  } else {
1060  assert(!inst->isExecuted());
1061  add_to_iq = true;
1062  }
1063 
1064  if (add_to_iq && inst->isNonSpeculative()) {
1065  DPRINTF(IEW, "[tid:%i] Issue: Nonspeculative instruction "
1066  "encountered, skipping.\n", tid);
1067 
1068  // Same as non-speculative stores.
1069  inst->setCanCommit();
1070 
1071  // Specifically insert it as nonspeculative.
1072  instQueue.insertNonSpec(inst);
1073 
1075 
1076  add_to_iq = false;
1077  }
1078 
1079  // If the instruction queue is not full, then add the
1080  // instruction.
1081  if (add_to_iq) {
1082  instQueue.insert(inst);
1083  }
1084 
1085  insts_to_dispatch.pop();
1086 
1087  toRename->iewInfo[tid].dispatched++;
1088 
1090 
1091 #if TRACING_ON
1092  inst->dispatchTick = curTick() - inst->fetchTick;
1093 #endif
1094  ppDispatch->notify(inst);
1095  }
1096 
1097  if (!insts_to_dispatch.empty()) {
1098  DPRINTF(IEW,"[tid:%i] Issue: Bandwidth Full. Blocking.\n", tid);
1099  block(tid);
1100  toRename->iewUnblock[tid] = false;
1101  }
1102 
1103  if (dispatchStatus[tid] == Idle && dis_num_inst) {
1104  dispatchStatus[tid] = Running;
1105 
1106  updatedQueues = true;
1107  }
1108 
1109  dis_num_inst = 0;
1110 }
1111 
1112 void
1114 {
1115  int inst = 0;
1116 
1117  std::cout << "Available Instructions: ";
1118 
1119  while (fromIssue->insts[inst]) {
1120 
1121  if (inst%3==0) std::cout << "\n\t";
1122 
1123  std::cout << "PC: " << fromIssue->insts[inst]->pcState()
1124  << " TN: " << fromIssue->insts[inst]->threadNumber
1125  << " SN: " << fromIssue->insts[inst]->seqNum << " | ";
1126 
1127  inst++;
1128 
1129  }
1130 
1131  std::cout << "\n";
1132 }
1133 
1134 void
1136 {
1137  wbNumInst = 0;
1138  wbCycle = 0;
1139 
1140  std::list<ThreadID>::iterator threads = activeThreads->begin();
1142 
1143  while (threads != end) {
1144  ThreadID tid = *threads++;
1145  fetchRedirect[tid] = false;
1146  }
1147 
1148  // Uncomment this if you want to see all available instructions.
1149  // @todo This doesn't actually work anymore, we should fix it.
1150 // printAvailableInsts();
1151 
1152  // Execute/writeback any instructions that are available.
1153  int insts_to_execute = fromIssue->size;
1154  int inst_num = 0;
1155  for (; inst_num < insts_to_execute;
1156  ++inst_num) {
1157 
1158  DPRINTF(IEW, "Execute: Executing instructions from IQ.\n");
1159 
1161 
1162  DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%llu].\n",
1163  inst->pcState(), inst->threadNumber,inst->seqNum);
1164 
1165  // Notify potential listeners that this instruction has started
1166  // executing
1167  ppExecute->notify(inst);
1168 
1169  // Check if the instruction is squashed; if so then skip it
1170  if (inst->isSquashed()) {
1171  DPRINTF(IEW, "Execute: Instruction was squashed. PC: %s, [tid:%i]"
1172  " [sn:%llu]\n", inst->pcState(), inst->threadNumber,
1173  inst->seqNum);
1174 
1175  // Consider this instruction executed so that commit can go
1176  // ahead and retire the instruction.
1177  inst->setExecuted();
1178 
1179  // Not sure if I should set this here or just let commit try to
1180  // commit any squashed instructions. I like the latter a bit more.
1181  inst->setCanCommit();
1182 
1184 
1185  continue;
1186  }
1187 
1188  Fault fault = NoFault;
1189 
1190  // Execute instruction.
1191  // Note that if the instruction faults, it will be handled
1192  // at the commit stage.
1193  if (inst->isMemRef()) {
1194  DPRINTF(IEW, "Execute: Calculating address for memory "
1195  "reference.\n");
1196 
1197  // Tell the LDSTQ to execute this instruction (if it is a load).
1198  if (inst->isAtomic()) {
1199  // AMOs are treated like store requests
1200  fault = ldstQueue.executeStore(inst);
1201 
1202  if (inst->isTranslationDelayed() &&
1203  fault == NoFault) {
1204  // A hw page table walk is currently going on; the
1205  // instruction must be deferred.
1206  DPRINTF(IEW, "Execute: Delayed translation, deferring "
1207  "store.\n");
1208  instQueue.deferMemInst(inst);
1209  continue;
1210  }
1211  } else if (inst->isLoad()) {
1212  // Loads will mark themselves as executed, and their writeback
1213  // event adds the instruction to the queue to commit
1214  fault = ldstQueue.executeLoad(inst);
1215 
1216  if (inst->isTranslationDelayed() &&
1217  fault == NoFault) {
1218  // A hw page table walk is currently going on; the
1219  // instruction must be deferred.
1220  DPRINTF(IEW, "Execute: Delayed translation, deferring "
1221  "load.\n");
1222  instQueue.deferMemInst(inst);
1223  continue;
1224  }
1225 
1226  if (inst->isDataPrefetch() || inst->isInstPrefetch()) {
1227  inst->fault = NoFault;
1228  }
1229  } else if (inst->isStore()) {
1230  fault = ldstQueue.executeStore(inst);
1231 
1232  if (inst->isTranslationDelayed() &&
1233  fault == NoFault) {
1234  // A hw page table walk is currently going on; the
1235  // instruction must be deferred.
1236  DPRINTF(IEW, "Execute: Delayed translation, deferring "
1237  "store.\n");
1238  instQueue.deferMemInst(inst);
1239  continue;
1240  }
1241 
1242  // If the store had a fault then it may not have a mem req
1243  if (fault != NoFault || !inst->readPredicate() ||
1244  !inst->isStoreConditional()) {
1245  // If the instruction faulted, then we need to send it
1246  // along to commit without the instruction completing.
1247  // Send this instruction to commit, also make sure iew
1248  // stage realizes there is activity.
1249  inst->setExecuted();
1250  instToCommit(inst);
1252  }
1253 
1254  // Store conditionals will mark themselves as
1255  // executed, and their writeback event will add the
1256  // instruction to the queue to commit.
1257  } else {
1258  panic("Unexpected memory type!\n");
1259  }
1260 
1261  } else {
1262  // If the instruction has already faulted, then skip executing it.
1263  // Such case can happen when it faulted during ITLB translation.
1264  // If we execute the instruction (even if it's a nop) the fault
1265  // will be replaced and we will lose it.
1266  if (inst->getFault() == NoFault) {
1267  inst->execute();
1268  if (!inst->readPredicate())
1269  inst->forwardOldRegs();
1270  }
1271 
1272  inst->setExecuted();
1273 
1274  instToCommit(inst);
1275  }
1276 
1277  updateExeInstStats(inst);
1278 
1279  // Check if branch prediction was correct, if not then we need
1280  // to tell commit to squash in flight instructions. Only
1281  // handle this if there hasn't already been something that
1282  // redirects fetch in this group of instructions.
1283 
1284  // This probably needs to prioritize the redirects if a different
1285  // scheduler is used. Currently the scheduler schedules the oldest
1286  // instruction first, so the branch resolution order will be correct.
1287  ThreadID tid = inst->threadNumber;
1288 
1289  if (!fetchRedirect[tid] ||
1290  !toCommit->squash[tid] ||
1291  toCommit->squashedSeqNum[tid] > inst->seqNum) {
1292 
1293  // Prevent testing for misprediction on load instructions,
1294  // that have not been executed.
1295  bool loadNotExecuted = !inst->isExecuted() && inst->isLoad();
1296 
1297  if (inst->mispredicted() && !loadNotExecuted) {
1298  fetchRedirect[tid] = true;
1299 
1300  DPRINTF(IEW, "[tid:%i] [sn:%llu] Execute: "
1301  "Branch mispredict detected.\n",
1302  tid, inst->seqNum);
1303  DPRINTF(IEW, "[tid:%i] [sn:%llu] "
1304  "Predicted target was PC: %s\n",
1305  tid, inst->seqNum, inst->readPredTarg());
1306  DPRINTF(IEW, "[tid:%i] [sn:%llu] Execute: "
1307  "Redirecting fetch to PC: %s\n",
1308  tid, inst->seqNum, inst->pcState());
1309  // If incorrect, then signal the ROB that it must be squashed.
1310  squashDueToBranch(inst, tid);
1311 
1312  ppMispredict->notify(inst);
1313 
1314  if (inst->readPredTaken()) {
1316  } else {
1318  }
1319  } else if (ldstQueue.violation(tid)) {
1320  assert(inst->isMemRef());
1321  // If there was an ordering violation, then get the
1322  // DynInst that caused the violation. Note that this
1323  // clears the violation signal.
1324  DynInstPtr violator;
1325  violator = ldstQueue.getMemDepViolator(tid);
1326 
1327  DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s "
1328  "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n",
1329  violator->pcState(), violator->seqNum,
1330  inst->pcState(), inst->seqNum, inst->physEffAddr);
1331 
1332  fetchRedirect[tid] = true;
1333 
1334  // Tell the instruction queue that a violation has occured.
1335  instQueue.violation(inst, violator);
1336 
1337  // Squash.
1338  squashDueToMemOrder(violator, tid);
1339 
1341  }
1342  } else {
1343  // Reset any state associated with redirects that will not
1344  // be used.
1345  if (ldstQueue.violation(tid)) {
1346  assert(inst->isMemRef());
1347 
1348  DynInstPtr violator = ldstQueue.getMemDepViolator(tid);
1349 
1350  DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: "
1351  "%s, inst PC: %s. Addr is: %#x.\n",
1352  violator->pcState(), inst->pcState(),
1353  inst->physEffAddr);
1354  DPRINTF(IEW, "Violation will not be handled because "
1355  "already squashing\n");
1356 
1358  }
1359  }
1360  }
1361 
1362  // Update and record activity if we processed any instructions.
1363  if (inst_num) {
1364  if (exeStatus == Idle) {
1365  exeStatus = Running;
1366  }
1367 
1368  updatedQueues = true;
1369 
1371  }
1372 
1373  // Need to reset this in case a writeback event needs to write into the
1374  // iew queue. That way the writeback event will write into the correct
1375  // spot in the queue.
1376  wbNumInst = 0;
1377 
1378 }
1379 
1380 void
1382 {
1383  // Loop through the head of the time buffer and wake any
1384  // dependents. These instructions are about to write back. Also
1385  // mark scoreboard that this instruction is finally complete.
1386  // Either have IEW have direct access to scoreboard, or have this
1387  // as part of backwards communication.
1388  for (int inst_num = 0; inst_num < wbWidth &&
1389  toCommit->insts[inst_num]; inst_num++) {
1390  DynInstPtr inst = toCommit->insts[inst_num];
1391  ThreadID tid = inst->threadNumber;
1392 
1393  DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n",
1394  inst->seqNum, inst->pcState());
1395 
1396  iewStats.instsToCommit[tid]++;
1397  // Notify potential listeners that execution is complete for this
1398  // instruction.
1399  ppToCommit->notify(inst);
1400 
1401  // Some instructions will be sent to commit without having
1402  // executed because they need commit to handle them.
1403  // E.g. Strictly ordered loads have not actually executed when they
1404  // are first sent to commit. Instead commit must tell the LSQ
1405  // when it's ready to execute the strictly ordered load.
1406  if (!inst->isSquashed() && inst->isExecuted() &&
1407  inst->getFault() == NoFault) {
1408  int dependents = instQueue.wakeDependents(inst);
1409 
1410  for (int i = 0; i < inst->numDestRegs(); i++) {
1411  // Mark register as ready if not pinned
1412  if (inst->renamedDestIdx(i)->
1413  getNumPinnedWritesToComplete() == 0) {
1414  DPRINTF(IEW,"Setting Destination Register %i (%s)\n",
1415  inst->renamedDestIdx(i)->index(),
1416  inst->renamedDestIdx(i)->className());
1417  scoreboard->setReg(inst->renamedDestIdx(i));
1418  }
1419  }
1420 
1421  if (dependents) {
1422  iewStats.producerInst[tid]++;
1423  iewStats.consumerInst[tid]+= dependents;
1424  }
1425  iewStats.writebackCount[tid]++;
1426  }
1427  }
1428 }
1429 
1430 void
1432 {
1433  wbNumInst = 0;
1434  wbCycle = 0;
1435 
1436  wroteToTimeBuffer = false;
1437  updatedQueues = false;
1438 
1439  ldstQueue.tick();
1440 
1441  sortInsts();
1442 
1443  // Free function units marked as being freed this cycle.
1445 
1446  std::list<ThreadID>::iterator threads = activeThreads->begin();
1448 
1449  // Check stall and squash signals, dispatch any instructions.
1450  while (threads != end) {
1451  ThreadID tid = *threads++;
1452 
1453  DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid);
1454 
1455  checkSignalsAndUpdate(tid);
1456  dispatch(tid);
1457  }
1458 
1459  if (exeStatus != Squashing) {
1460  executeInsts();
1461 
1462  writebackInsts();
1463 
1464  // Have the instruction queue try to schedule any ready instructions.
1465  // (In actuality, this scheduling is for instructions that will
1466  // be executed next cycle.)
1468 
1469  // Also should advance its own time buffers if the stage ran.
1470  // Not the best place for it, but this works (hopefully).
1471  issueToExecQueue.advance();
1472  }
1473 
1474  bool broadcast_free_entries = false;
1475 
1477  exeStatus = Idle;
1478  updateLSQNextCycle = false;
1479 
1480  broadcast_free_entries = true;
1481  }
1482 
1483  // Writeback any stores using any leftover bandwidth.
1485 
1486  // Check the committed load/store signals to see if there's a load
1487  // or store to commit. Also check if it's being told to execute a
1488  // nonspeculative instruction.
1489  // This is pretty inefficient...
1490 
1491  threads = activeThreads->begin();
1492  while (threads != end) {
1493  ThreadID tid = (*threads++);
1494 
1495  DPRINTF(IEW,"Processing [tid:%i]\n",tid);
1496 
1497  // Update structures based on instructions committed.
1498  if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
1499  !fromCommit->commitInfo[tid].squash &&
1500  !fromCommit->commitInfo[tid].robSquashing) {
1501 
1502  ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid);
1503 
1504  ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid);
1505 
1506  updateLSQNextCycle = true;
1507  instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid);
1508  }
1509 
1510  if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) {
1511 
1512  //DPRINTF(IEW,"NonspecInst from thread %i",tid);
1513  if (fromCommit->commitInfo[tid].strictlyOrdered) {
1515  fromCommit->commitInfo[tid].strictlyOrderedLoad);
1516  fromCommit->commitInfo[tid].strictlyOrderedLoad->setAtCommit();
1517  } else {
1519  fromCommit->commitInfo[tid].nonSpecSeqNum);
1520  }
1521  }
1522 
1523  if (broadcast_free_entries) {
1524  toFetch->iewInfo[tid].iqCount =
1525  instQueue.getCount(tid);
1526  toFetch->iewInfo[tid].ldstqCount =
1527  ldstQueue.getCount(tid);
1528 
1529  toRename->iewInfo[tid].usedIQ = true;
1530  toRename->iewInfo[tid].freeIQEntries =
1532  toRename->iewInfo[tid].usedLSQ = true;
1533 
1534  toRename->iewInfo[tid].freeLQEntries =
1536  toRename->iewInfo[tid].freeSQEntries =
1538 
1539  wroteToTimeBuffer = true;
1540  }
1541 
1542  DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n",
1543  tid, toRename->iewInfo[tid].dispatched);
1544  }
1545 
1546  DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i). "
1547  "LQ has %i free entries. SQ has %i free entries.\n",
1550 
1551  updateStatus();
1552 
1553  if (wroteToTimeBuffer) {
1554  DPRINTF(Activity, "Activity this cycle.\n");
1556  }
1557 }
1558 
1559 void
1561 {
1562  ThreadID tid = inst->threadNumber;
1563 
1565 
1566 #if TRACING_ON
1567  if (debug::O3PipeView) {
1568  inst->completeTick = curTick() - inst->fetchTick;
1569  }
1570 #endif
1571 
1572  //
1573  // Control operations
1574  //
1575  if (inst->isControl())
1577 
1578  //
1579  // Memory operations
1580  //
1581  if (inst->isMemRef()) {
1583 
1584  if (inst->isLoad()) {
1586  }
1587  }
1588 }
1589 
1590 void
1592 {
1593  ThreadID tid = inst->threadNumber;
1594 
1595  if (!fetchRedirect[tid] ||
1596  !toCommit->squash[tid] ||
1597  toCommit->squashedSeqNum[tid] > inst->seqNum) {
1598 
1599  if (inst->mispredicted()) {
1600  fetchRedirect[tid] = true;
1601 
1602  DPRINTF(IEW, "[tid:%i] [sn:%llu] Execute: "
1603  "Branch mispredict detected.\n",
1604  tid, inst->seqNum);
1605  DPRINTF(IEW, "[tid:%i] [sn:%llu] Predicted target was PC: %s\n",
1606  tid, inst->seqNum, inst->readPredTarg());
1607  DPRINTF(IEW, "[tid:%i] [sn:%llu] Execute: "
1608  "Redirecting fetch to PC: %s\n",
1609  tid, inst->seqNum, inst->pcState());
1610  // If incorrect, then signal the ROB that it must be squashed.
1611  squashDueToBranch(inst, tid);
1612 
1613  if (inst->readPredTaken()) {
1615  } else {
1617  }
1618  }
1619  }
1620 }
1621 
1622 } // namespace o3
1623 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::BaseCPU::BaseCPUStats baseStats
ThreadID numThreads
Number of threads we're actually simulating (<= SMT_MAX_THREADS).
Definition: base.hh:367
virtual std::string name() const
Definition: named.hh:47
ProbePointArg generates a point for the class of Arg.
Definition: probe.hh:264
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition: cpu.hh:94
gem5::Checker< DynInstPtr > * checker
Pointer to the checker, which can dynamically verify instruction results at run time.
Definition: cpu.hh:524
void activityThisCycle()
Records that there was time buffer activity this cycle.
Definition: cpu.hh:485
void deactivateStage(const StageIdx idx)
Changes a stage's status to inactive within the activity recorder.
Definition: cpu.hh:496
void activateStage(const StageIdx idx)
Changes a stage's status to active within the activity recorder.
Definition: cpu.hh:489
void wakeCPU()
Wakes the CPU, rescheduling the CPU if it's not already active.
Definition: cpu.cc:1399
void processFreeUnits()
Frees all FUs on the list.
Definition: fu_pool.cc:197
bool isDrained() const
Have all the FUs drained?
Definition: fu_pool.cc:244
void takeOverFrom()
Takes over from another CPU's thread.
Definition: fu_pool.hh:182
IEW handles both single threaded and SMT IEW (issue/execute/writeback).
Definition: iew.hh:88
void printAvailableInsts()
Debug function to print instructions that are issued this cycle.
Definition: iew.cc:1113
@ Inactive
Definition: iew.hh:96
@ Active
Definition: iew.hh:95
void updateStatus()
Updates overall IEW status based on all of the stages' statuses.
Definition: iew.cc:650
void deactivateStage()
Tells CPU that the IEW stage is inactive and idle.
Definition: iew.cc:823
TimeBuffer< IEWStruct > * iewQueue
IEW stage time buffer.
Definition: iew.hh:327
TimeBuffer< TimeStruct >::wire fromCommit
Wire to get commit's output from backwards time buffer.
Definition: iew.hh:306
StageStatus dispatchStatus[MaxThreads]
Dispatch status.
Definition: iew.hh:114
std::list< ThreadID > * activeThreads
Pointer to list of active threads.
Definition: iew.hh:412
void takeOverFrom()
Takes over from another CPU's thread.
Definition: iew.cc:391
void setTimeBuffer(TimeBuffer< TimeStruct > *tb_ptr)
Sets main time buffer used for backwards communication.
Definition: iew.cc:304
int skidCount()
Returns the max of the number of entries in all of the skid buffers.
Definition: iew.cc:616
void instToCommit(const DynInstPtr &inst)
Sends an instruction to commit through the time buffer.
Definition: iew.cc:567
FUPool * fuPool
Pointer to the functional unit pool.
Definition: iew.hh:361
void squashDueToBranch(const DynInstPtr &inst, ThreadID tid)
Sends commit proper information for a squash due to a branch mispredict.
Definition: iew.cc:453
void squashDueToMemOrder(const DynInstPtr &inst, ThreadID tid)
Sends commit proper information for a squash due to a memory order violation.
Definition: iew.cc:477
unsigned wbWidth
Writeback width.
Definition: iew.hh:406
std::queue< DynInstPtr > insts[MaxThreads]
Queue of all instructions coming from rename this cycle.
Definition: iew.hh:333
void block(ThreadID tid)
Sets Dispatch to blocked, and signals back to other stages to block.
Definition: iew.cc:503
StageStatus exeStatus
Execute status.
Definition: iew.hh:116
void clearStates(ThreadID tid)
Clear all thread-specific states.
Definition: iew.cc:292
void dispatch(ThreadID tid)
Determines proper actions to take given Dispatch's status.
Definition: iew.cc:830
void startupStage()
Initializes stage; sends back the number of free IQ and LSQ entries.
Definition: iew.cc:269
void blockMemInst(const DynInstPtr &inst)
Moves memory instruction onto the list of cache blocked instructions.
Definition: iew.cc:555
void unblock(ThreadID tid)
Unblocks Dispatch if the skid buffer is empty, and signals back to other stages to unblock.
Definition: iew.cc:521
void sortInsts()
Sorts instructions coming from rename into lists separated by thread.
Definition: iew.cc:769
void wakeDependents(const DynInstPtr &inst)
Wakes all dependents of a completed instruction.
Definition: iew.cc:537
unsigned issueWidth
Width of issue, in instructions.
Definition: iew.hh:393
void updateExeInstStats(const DynInstPtr &inst)
Updates execution stats based on the instruction.
Definition: iew.cc:1560
void dispatchInsts(ThreadID tid)
Dispatches instructions to IQ and LSQ.
Definition: iew.cc:877
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: iew.cc:382
TimeBuffer< IssueStruct > issueToExecQueue
Issue stage queue.
Definition: iew.hh:318
void checkSignalsAndUpdate(ThreadID tid)
Processes inputs and changes state accordingly.
Definition: iew.cc:706
void activateStage()
Tells CPU that the IEW stage is active and running.
Definition: iew.cc:816
TimeBuffer< TimeStruct >::wire toRename
Wire to write information heading to previous stages.
Definition: iew.hh:309
bool wroteToTimeBuffer
Records if IEW has written to the time buffer this cycle, so that the CPU can deschedule itself if th...
Definition: iew.hh:348
CPU * cpu
CPU pointer.
Definition: iew.hh:343
void activityThisCycle()
Reports to the CPU that there is activity this cycle.
Definition: iew.cc:809
void setScoreboard(Scoreboard *sb_ptr)
Sets pointer to the scoreboard.
Definition: iew.cc:348
Scoreboard * scoreboard
Scoreboard pointer.
Definition: iew.hh:339
std::queue< DynInstPtr > skidBuffer[MaxThreads]
Skid buffer between rename and IEW.
Definition: iew.hh:336
TimeBuffer< IssueStruct >::wire fromIssue
Wire to read information from the issue stage time queue.
Definition: iew.hh:321
Cycles renameToIEWDelay
Rename to IEW delay.
Definition: iew.hh:380
TimeBuffer< TimeStruct > * timeBuffer
Pointer to main time buffer used for backwards communication.
Definition: iew.hh:300
void writebackInsts()
Writebacks instructions.
Definition: iew.cc:1381
void wakeCPU()
Tells the CPU to wakeup if it has descheduled itself due to no activity.
Definition: iew.cc:803
void squash(ThreadID tid)
Squashes instructions in IEW for a specific thread.
Definition: iew.cc:418
void setIEWQueue(TimeBuffer< IEWStruct > *iq_ptr)
Sets time buffer to pass on instructions to commit.
Definition: iew.cc:330
ProbePointArg< DynInstPtr > * ppExecute
To probe when instruction execution begins.
Definition: iew.hh:124
void rescheduleMemInst(const DynInstPtr &inst)
Tells memory dependence unit that a memory instruction needs to be rescheduled.
Definition: iew.cc:543
ThreadID numThreads
Number of active threads.
Definition: iew.hh:409
unsigned skidBufferMax
Maximum size of the skid buffer.
Definition: iew.hh:415
Status _status
Overall stage status.
Definition: iew.hh:112
TimeBuffer< RenameStruct >::wire fromRename
Wire to get rename's output from rename queue.
Definition: iew.hh:315
ProbePointArg< DynInstPtr > * ppMispredict
Probe points.
Definition: iew.hh:121
TimeBuffer< TimeStruct >::wire toFetch
Wire to write information heading to previous stages.
Definition: iew.hh:303
gem5::o3::IEW::IEWStats iewStats
bool isDrained() const
Has the stage drained?
Definition: iew.cc:354
InstructionQueue instQueue
Instruction queue.
Definition: iew.hh:355
bool fetchRedirect[MaxThreads]
Records if there is a fetch redirect on this cycle for each thread.
Definition: iew.hh:369
TimeBuffer< RenameStruct > * renameQueue
Rename instruction queue interface.
Definition: iew.hh:312
IEW(CPU *_cpu, const BaseO3CPUParams &params)
Constructs a IEW with the given parameters.
Definition: iew.cc:67
unsigned dispatchWidth
Width of dispatch, in instructions.
Definition: iew.hh:390
ProbePointArg< DynInstPtr > * ppDispatch
Definition: iew.hh:122
std::string name() const
Returns the name of the IEW stage.
Definition: iew.cc:118
void tick()
Ticks IEW stage, causing Dispatch, the IQ, the LSQ, Execute, and Writeback to run for one cycle.
Definition: iew.cc:1431
ProbePointArg< DynInstPtr > * ppToCommit
To probe when instruction execution is complete.
Definition: iew.hh:126
bool updatedQueues
Records if the queues have been changed (inserted or issued insts), so that IEW knows to broadcast th...
Definition: iew.hh:374
void checkMisprediction(const DynInstPtr &inst)
Check misprediction
Definition: iew.cc:1591
LSQ ldstQueue
Load / store queue.
Definition: iew.hh:358
Cycles issueToExecuteDelay
Issue to execute delay.
Definition: iew.hh:387
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
Definition: iew.cc:339
bool skidsEmpty()
Returns if all of the skid buffers are empty.
Definition: iew.cc:634
bool updateLSQNextCycle
Records if the LSQ needs to be updated on the next cycle, so that IEW knows if there will be activity...
Definition: iew.hh:365
void emptyRenameInsts(ThreadID tid)
Removes instructions from rename from a thread's instruction list.
Definition: iew.cc:782
void replayMemInst(const DynInstPtr &inst)
Re-executes all rescheduled memory instructions.
Definition: iew.cc:549
Cycles commitToIEWDelay
Commit to IEW delay.
Definition: iew.hh:377
unsigned wbCycle
Cycle number within the queue of instructions being written back.
Definition: iew.hh:403
void skidInsert(ThreadID tid)
Inserts unused instructions of a thread into the skid buffer.
Definition: iew.cc:595
void cacheUnblocked()
Notifies that the cache has become unblocked.
Definition: iew.cc:561
TimeBuffer< IEWStruct >::wire toCommit
Wire to write infromation heading to commit.
Definition: iew.hh:330
void regProbePoints()
Registers probes.
Definition: iew.cc:124
bool checkStall(ThreadID tid)
Checks if any of the stall conditions are currently true.
Definition: iew.cc:690
void executeInsts()
Executes instructions.
Definition: iew.cc:1135
unsigned wbNumInst
Index into queue of instructions being written back.
Definition: iew.hh:396
void setRenameQueue(TimeBuffer< RenameStruct > *rq_ptr)
Sets time buffer for getting instructions coming from rename.
Definition: iew.cc:321
StageStatus wbStatus
Writeback status.
Definition: iew.hh:118
@ Unblocking
Definition: iew.hh:107
@ Squashing
Definition: iew.hh:106
void commit(const InstSeqNum &inst, ThreadID tid=0)
Commits all instructions up to and including the given sequence number, for a specific thread.
Definition: inst_queue.cc:948
void deferMemInst(const DynInstPtr &deferred_inst)
Defers a memory instruction when its DTB translation incurs a hw page table walk.
Definition: inst_queue.cc:1107
void insertBarrier(const DynInstPtr &barr_inst)
Inserts a memory or write barrier into the IQ to make sure loads and stores are ordered properly.
Definition: inst_queue.cc:653
int wakeDependents(const DynInstPtr &completed_inst)
Wakes all dependents of a completed instruction.
Definition: inst_queue.cc:965
void setTimeBuffer(TimeBuffer< TimeStruct > *tb_ptr)
Sets the global time buffer.
Definition: inst_queue.cc:444
unsigned numFreeEntries()
Returns total number of free entries.
Definition: inst_queue.cc:512
void rescheduleMemInst(const DynInstPtr &resched_inst)
Reschedules a memory instruction.
Definition: inst_queue.cc:1088
void insertNonSpec(const DynInstPtr &new_inst)
Inserts a new, non-speculative instruction into the IQ.
Definition: inst_queue.cc:607
unsigned getCount(ThreadID tid)
Returns the number of used entries for a thread.
Definition: inst_queue.hh:275
void replayMemInst(const DynInstPtr &replay_inst)
Replays a memory instruction.
Definition: inst_queue.cc:1101
void recordProducer(const DynInstPtr &inst)
Records the instruction as the producer of a register without adding it to the rest of the IQ.
Definition: inst_queue.hh:215
bool isDrained() const
Determine if we are drained.
Definition: inst_queue.cc:452
void cacheUnblocked()
Notify instruction queue that a previous blockage has resolved.
Definition: inst_queue.cc:1124
void blockMemInst(const DynInstPtr &blocked_inst)
Defers a memory instruction when it is cache blocked.
Definition: inst_queue.cc:1113
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: inst_queue.cc:464
void takeOverFrom()
Takes over execution from another CPU's thread.
Definition: inst_queue.cc:473
gem5::o3::InstructionQueue::IQIOStats iqIOStats
void violation(const DynInstPtr &store, const DynInstPtr &faulting_load)
Indicates an ordering violation between a store and a load.
Definition: inst_queue.cc:1160
bool hasReadyInsts()
Returns if there are any ready instructions in the IQ.
Definition: inst_queue.cc:546
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets active threads list.
Definition: inst_queue.cc:432
void scheduleNonSpec(const InstSeqNum &inst)
Schedules a single specific non-speculative instruction.
Definition: inst_queue.cc:921
void scheduleReadyInsts()
Schedules ready instructions, adding the ready ones (oldest first) to the queue to execute.
Definition: inst_queue.cc:751
bool isFull()
Returns whether or not the IQ is full.
Definition: inst_queue.cc:526
void squash(ThreadID tid)
Squashes instructions for a thread.
Definition: inst_queue.cc:1168
void setIssueToExecuteQueue(TimeBuffer< IssueStruct > *i2eQueue)
Sets the timer buffer between issue and execute.
Definition: inst_queue.cc:438
void insert(const DynInstPtr &new_inst)
Inserts a new instruction into the IQ.
Definition: inst_queue.cc:562
DynInstPtr getInstToExecute()
Returns the oldest scheduled instruction, and removes it from the list of instructions waiting to exe...
Definition: inst_queue.cc:661
bool isDrained() const
Has the LSQ drained?
Definition: lsq.cc:146
int numHtmStarts(ThreadID tid) const
Definition: lsq.cc:344
void commitStores(InstSeqNum &youngest_inst, ThreadID tid)
Commits stores up until the given sequence number for a specific thread.
Definition: lsq.cc:259
RequestPort & getDataPort()
Definition: lsq.hh:892
void squash(const InstSeqNum &squashed_num, ThreadID tid)
Squash instructions from a thread until the specified sequence number.
Definition: lsq.cc:283
unsigned numFreeLoadEntries()
Returns the number of free load entries.
Definition: lsq.cc:524
void takeOverFrom()
Takes over execution from another CPU's thread.
Definition: lsq.cc:164
DynInstPtr getMemDepViolator(ThreadID tid)
Gets the instruction that caused the memory ordering violation.
Definition: lsq.cc:308
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets the pointer to the list of active threads.
Definition: lsq.cc:130
void insertStore(const DynInstPtr &store_inst)
Inserts a store into the LSQ.
Definition: lsq.cc:229
void commitLoads(InstSeqNum &youngest_inst, ThreadID tid)
Commits loads up until the given sequence number for a specific thread.
Definition: lsq.cc:253
uint64_t getLatestHtmUid(ThreadID tid) const
Definition: lsq.cc:368
bool willWB()
Returns if the LSQ will write back to memory this cycle.
Definition: lsq.cc:742
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: lsq.cc:137
int numHtmStops(ThreadID tid) const
Definition: lsq.cc:352
void writebackStores()
Attempts to write back stores until all cache ports are used or the interface becomes blocked.
Definition: lsq.cc:265
bool lqFull()
Returns if any of the LQs are full.
Definition: lsq.cc:635
int getCount()
Returns the number of instructions in all of the queues.
Definition: lsq.cc:473
Fault executeStore(const DynInstPtr &inst)
Executes a store.
Definition: lsq.cc:245
void tick()
Ticks the LSQ.
Definition: lsq.cc:175
void insertLoad(const DynInstPtr &load_inst)
Inserts a load into the LSQ.
Definition: lsq.cc:221
Fault executeLoad(const DynInstPtr &inst)
Executes a load.
Definition: lsq.cc:237
bool violation()
Returns whether or not there was a memory ordering violation.
Definition: lsq.cc:289
unsigned numFreeStoreEntries()
Returns the number of free store entries.
Definition: lsq.cc:541
bool sqFull()
Returns if any of the SQs are full.
Definition: lsq.cc:662
Implements a simple scoreboard to track which registers are ready.
Definition: scoreboard.hh:55
void setReg(PhysRegIdPtr phys_reg)
Sets the register as ready.
Definition: scoreboard.hh:97
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:358
Statistics container.
Definition: group.hh:94
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1040
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition: group.hh:75
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:120
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 12, 11 > set
Definition: misc_types.hh:709
static constexpr int MaxThreads
Definition: limits.hh:38
static constexpr int MaxWidth
Definition: limits.hh:37
const FlagsType total
Print the total.
Definition: info.hh:60
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:235
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
constexpr decltype(nullptr) NoFault
Definition: types.hh:253
statistics::Scalar numCycles
Definition: base.hh:620
statistics::Formula numStoreInsts
Number of executed store instructions.
Definition: iew.hh:474
statistics::Vector numLoadInsts
Stat for total number of executed load instructions.
Definition: iew.hh:461
statistics::Vector numSwp
Number of executed software prefetches.
Definition: iew.hh:466
statistics::Vector numBranches
Number of executed branches.
Definition: iew.hh:472
statistics::Scalar numInsts
Stat for total number of executed instructions.
Definition: iew.hh:459
statistics::Vector numRefs
Number of executed meomory references.
Definition: iew.hh:470
statistics::Scalar numSquashedInsts
Stat for total number of squashed instructions skipped at execute.
Definition: iew.hh:464
statistics::Vector numNop
Number of executed nops.
Definition: iew.hh:468
statistics::Formula numRate
Number of instructions executed per cycle.
Definition: iew.hh:476
statistics::Scalar dispatchedInsts
Stat for total number of instructions dispatched.
Definition: iew.hh:431
statistics::Formula wbFanout
Average number of woken instructions per writeback.
Definition: iew.hh:490
statistics::Scalar squashCycles
Stat for total number of squashing cycles.
Definition: iew.hh:425
statistics::Vector consumerInst
Number of instructions that wake up from producers.
Definition: iew.hh:486
statistics::Scalar predictedNotTakenIncorrect
Stat for total number of incorrect predicted not taken branches.
Definition: iew.hh:449
statistics::Scalar dispLoadInsts
Stat for total number of dispatched load instructions.
Definition: iew.hh:435
statistics::Scalar dispNonSpecInsts
Stat for total number of dispatched non speculative insts.
Definition: iew.hh:439
statistics::Vector instsToCommit
Number of instructions sent to commit.
Definition: iew.hh:480
gem5::o3::IEW::IEWStats::ExecutedInstStats executedInstStats
statistics::Formula wbRate
Number of instructions per cycle written back.
Definition: iew.hh:488
statistics::Scalar dispSquashedInsts
Stat for total number of squashed instructions dispatch skips.
Definition: iew.hh:433
statistics::Scalar predictedTakenIncorrect
Stat for total number of incorrect predicted taken branches.
Definition: iew.hh:447
statistics::Scalar blockCycles
Stat for total number of blocking cycles.
Definition: iew.hh:427
statistics::Vector writebackCount
Number of instructions that writeback.
Definition: iew.hh:482
statistics::Scalar memOrderViolationEvents
Stat for total number of memory ordering violation events.
Definition: iew.hh:445
statistics::Vector producerInst
Number of instructions that wake consumers.
Definition: iew.hh:484
IEWStats(CPU *cpu)
Definition: iew.cc:144
statistics::Scalar iqFullEvents
Stat for number of times the IQ becomes full.
Definition: iew.hh:441
statistics::Scalar unblockCycles
Stat for total number of unblocking cycles.
Definition: iew.hh:429
statistics::Scalar lsqFullEvents
Stat for number of times the LSQ becomes full.
Definition: iew.hh:443
statistics::Scalar dispStoreInsts
Stat for total number of dispatched store instructions.
Definition: iew.hh:437

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1