2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "config/use_checker.hh"
33 #include "cpu/ozone/lw_back_end.hh"
34 #include "cpu/op_class.hh"
37 #include "cpu/checker/cpu.hh"
42 LWBackEnd<Impl>::generateTrapEvent(Tick latency)
44 DPRINTF(BE, "Generating trap event\n");
46 TrapEvent *trap = new TrapEvent(this);
48 trap->schedule(curTick + cpu->cycles(latency));
50 thread->trapPending = true;
55 LWBackEnd<Impl>::wakeDependents(DynInstPtr &inst, bool memory_deps)
57 assert(!inst->isSquashed());
58 std::vector<DynInstPtr> &dependents = memory_deps ? inst->getMemDeps() :
59 inst->getDependents();
60 int num_outputs = dependents.size();
62 DPRINTF(BE, "Waking instruction [sn:%lli] dependents in IQ\n", inst->seqNum);
64 for (int i = 0; i < num_outputs; i++) {
65 DynInstPtr dep_inst = dependents[i];
67 dep_inst->markSrcRegReady();
69 if (!dep_inst->isSquashed())
70 dep_inst->markMemInstReady(inst.get());
73 DPRINTF(BE, "Marking source reg ready [sn:%lli] in IQ\n", dep_inst->seqNum);
75 if (dep_inst->readyToIssue() && dep_inst->isInROB() &&
76 !dep_inst->isNonSpeculative() && !dep_inst->isStoreConditional() &&
77 dep_inst->memDepReady() && !dep_inst->isMemBarrier() &&
78 !dep_inst->isWriteBarrier()) {
79 DPRINTF(BE, "Adding instruction to exeList [sn:%lli]\n",
81 exeList.push(dep_inst);
82 if (dep_inst->iqItValid) {
83 DPRINTF(BE, "Removing instruction from waiting list\n");
84 waitingList.erase(dep_inst->iqIt);
86 dep_inst->iqItValid = false;
87 assert(waitingInsts >= 0);
89 if (dep_inst->isMemRef()) {
90 removeWaitingMemOp(dep_inst);
91 DPRINTF(BE, "Issued a waiting mem op [sn:%lli]\n",
101 LWBackEnd<Impl>::rescheduleMemInst(DynInstPtr &inst)
103 replayList.push_front(inst);
106 template <class Impl>
107 LWBackEnd<Impl>::TrapEvent::TrapEvent(LWBackEnd<Impl> *_be)
108 : Event(&mainEventQueue, CPU_Tick_Pri), be(_be)
110 this->setFlags(Event::AutoDelete);
113 template <class Impl>
115 LWBackEnd<Impl>::TrapEvent::process()
117 be->trapSquash = true;
120 template <class Impl>
122 LWBackEnd<Impl>::TrapEvent::description()
127 template <class Impl>
129 LWBackEnd<Impl>::replayMemInst(DynInstPtr &inst)
131 bool found_inst = false;
132 while (!replayList.empty()) {
133 exeList.push(replayList.front());
134 if (replayList.front() == inst) {
137 replayList.pop_front();
142 template <class Impl>
143 LWBackEnd<Impl>::LWBackEnd(Params *params)
144 : d2i(5, 5), i2e(5, 5), e2c(5, 5), numInstsToWB(5, 5),
145 trapSquash(false), tcSquash(false),
146 width(params->backEndWidth), exactFullStall(true)
148 numROBEntries = params->numROBEntries;
150 numDispatchEntries = 32;
151 maxOutstandingMemOps = params->maxOutstandingMemOps;
152 numWaitingMemOps = 0;
155 switchPending = false;
159 // Setup IQ and LSQ with their parameters here.
160 instsToDispatch = d2i.getWire(-1);
162 instsToExecute = i2e.getWire(-1);
164 dispatchWidth = params->dispatchWidth ? params->dispatchWidth : width;
165 issueWidth = params->issueWidth ? params->issueWidth : width;
166 wbWidth = params->wbWidth ? params->wbWidth : width;
167 commitWidth = params->commitWidth ? params->commitWidth : width;
169 LSQ.init(params, params->LQEntries, params->SQEntries, 0);
171 dispatchStatus = Running;
172 commitStatus = Running;
175 template <class Impl>
177 LWBackEnd<Impl>::name() const
179 return cpu->name() + ".backend";
182 template <class Impl>
184 LWBackEnd<Impl>::regStats()
186 using namespace Stats;
188 .init(cpu->number_of_threads)
189 .name(name() + ".ROB:cap_events")
190 .desc("number of cycles where ROB cap was active")
195 .init(cpu->number_of_threads)
196 .name(name() + ".ROB:cap_inst")
197 .desc("number of instructions held up by ROB cap")
202 .init(cpu->number_of_threads)
203 .name(name() +".IQ:cap_events" )
204 .desc("number of cycles where IQ cap was active")
209 .init(cpu->number_of_threads)
210 .name(name() + ".IQ:cap_inst")
211 .desc("number of instructions held up by IQ cap")
217 .init(cpu->number_of_threads)
218 .name(name() + ".ISSUE:count")
219 .desc("number of insts issued")
224 .init(cpu->number_of_threads)
225 .name(name() + ".ISSUE:swp")
226 .desc("number of swp insts issued")
231 .init(cpu->number_of_threads)
232 .name(name() + ".ISSUE:nop")
233 .desc("number of nop insts issued")
238 .init(cpu->number_of_threads)
239 .name(name() + ".ISSUE:refs")
240 .desc("number of memory reference insts issued")
245 .init(cpu->number_of_threads)
246 .name(name() + ".ISSUE:loads")
247 .desc("number of load insts issued")
252 .init(cpu->number_of_threads)
253 .name(name() + ".ISSUE:branches")
254 .desc("Number of branches issued")
259 .init(cpu->number_of_threads)
260 .name(name() + ".ISSUE:op_count")
261 .desc("number of insts issued")
266 for (int i=0; i<Num_OpClasses; ++i) {
267 stringstream subname;
268 subname << opClassStrings[i] << "_delay";
269 issue_delay_dist.subname(i, subname.str());
276 .init(cpu->number_of_threads)
277 .name(name() + ".LSQ:forw_loads")
278 .desc("number of loads forwarded via LSQ")
283 .init(cpu->number_of_threads)
284 .name(name() + ".ISSUE:addr_loads")
285 .desc("number of invalid-address loads")
290 .init(cpu->number_of_threads)
291 .name(name() + ".ISSUE:addr_swpfs")
292 .desc("number of invalid-address SW prefetches")
297 .init(cpu->number_of_threads)
298 .name(name() + ".LSQ:blocked_loads")
299 .desc("number of ready loads not issued due to memory disambiguation")
304 .name(name() + ".ISSUE:lsq_invert")
305 .desc("Number of times LSQ instruction issued early")
309 .init(issueWidth + 1)
310 .name(name() + ".ISSUE:issued_per_cycle")
311 .desc("Number of insts issued each cycle")
312 .flags(total | pdf | dist)
315 .init(Num_OpClasses,0,99,2)
316 .name(name() + ".ISSUE:")
317 .desc("cycles from operands ready to issue")
322 .init(Num_OpClasses, 0, 99, 2)
323 .name(name() + ".IQ:residence:")
324 .desc("cycles from dispatch to issue")
325 .flags(total | pdf | cdf )
327 for (int i = 0; i < Num_OpClasses; ++i) {
328 queue_res_dist.subname(i, opClassStrings[i]);
332 .init(cpu->number_of_threads)
333 .name(name() + ".WB:count")
334 .desc("cumulative count of insts written-back")
339 .init(cpu->number_of_threads)
340 .name(name() + ".WB:producers")
341 .desc("num instructions producing a value")
346 .init(cpu->number_of_threads)
347 .name(name() + ".WB:consumers")
348 .desc("num instructions consuming a value")
353 .init(cpu->number_of_threads)
354 .name(name() + ".WB:penalized")
355 .desc("number of instrctions required to write to 'other' IQ")
361 .name(name() + ".WB:penalized_rate")
362 .desc ("fraction of instructions written-back that wrote to 'other' IQ")
366 wb_penalized_rate = wb_penalized / writeback_count;
369 .name(name() + ".WB:fanout")
370 .desc("average fanout of values written-back")
374 wb_fanout = producer_inst / consumer_inst;
377 .name(name() + ".WB:rate")
378 .desc("insts written-back per cycle")
381 wb_rate = writeback_count / cpu->numCycles;
384 .init(cpu->number_of_threads)
385 .name(name() + ".COM:count")
386 .desc("Number of instructions committed")
391 .init(cpu->number_of_threads)
392 .name(name() + ".COM:swp_count")
393 .desc("Number of s/w prefetches committed")
398 .init(cpu->number_of_threads)
399 .name(name() + ".COM:refs")
400 .desc("Number of memory references committed")
405 .init(cpu->number_of_threads)
406 .name(name() + ".COM:loads")
407 .desc("Number of loads committed")
412 .init(cpu->number_of_threads)
413 .name(name() + ".COM:membars")
414 .desc("Number of memory barriers committed")
419 .init(cpu->number_of_threads)
420 .name(name() + ".COM:branches")
421 .desc("Number of branches committed")
425 .init(0,commitWidth,1)
426 .name(name() + ".COM:committed_per_cycle")
427 .desc("Number of insts commited each cycle")
432 // Commit-Eligible instructions...
434 // -> The number of instructions eligible to commit in those
435 // cycles where we reached our commit BW limit (less the number
436 // actually committed)
438 // -> The average value is computed over ALL CYCLES... not just
439 // the BW limited cycles
441 // -> The standard deviation is computed only over cycles where
442 // we reached the BW limit
445 .init(cpu->number_of_threads)
446 .name(name() + ".COM:bw_limited")
447 .desc("number of insts not committed due to BW limits")
451 commit_eligible_samples
452 .name(name() + ".COM:bw_lim_events")
453 .desc("number cycles where commit BW limit reached")
457 .init(cpu->number_of_threads)
458 .name(name() + ".COM:squashed_insts")
459 .desc("Number of instructions removed from inst list")
463 .init(cpu->number_of_threads)
464 .name(name() + ".COM:rob_squashed_insts")
465 .desc("Number of instructions removed from inst list when they reached the head of the ROB")
469 .name(name() + ".ROB:full_count")
470 .desc("number of cycles where ROB was full")
474 .init(cpu->number_of_threads)
475 .name(name() + ".ROB:occupancy")
476 .desc(name() + ".ROB occupancy (cumulative)")
481 .name(name() + ".ROB:full_rate")
482 .desc("ROB full per cycle")
484 ROB_full_rate = ROB_fcount / cpu->numCycles;
487 .name(name() + ".ROB:occ_rate")
488 .desc("ROB occupancy rate")
491 ROB_occ_rate = ROB_count / cpu->numCycles;
494 .init(cpu->number_of_threads,0,numROBEntries,2)
495 .name(name() + ".ROB:occ_dist")
496 .desc("ROB Occupancy per cycle")
501 template <class Impl>
503 LWBackEnd<Impl>::setCPU(OzoneCPU *cpu_ptr)
507 checker = cpu->checker;
510 template <class Impl>
512 LWBackEnd<Impl>::setCommBuffer(TimeBuffer<CommStruct> *_comm)
515 toIEW = comm->getWire(0);
516 fromCommit = comm->getWire(-1);
520 template <class Impl>
522 LWBackEnd<Impl>::checkInterrupts()
524 if (cpu->checkInterrupts &&
525 cpu->check_interrupts() &&
526 !cpu->inPalMode(thread->readPC()) &&
529 frontEnd->interruptPending = true;
530 if (robEmpty() && !LSQ.hasStoresToWB()) {
531 // Will need to squash all instructions currently in flight and have
532 // the interrupt handler restart at the last non-committed inst.
533 // Most of that can be handled through the trap() function. The
534 // processInterrupts() function really just checks for interrupts
535 // and then calls trap() if there is an interrupt present.
537 // Not sure which thread should be the one to interrupt. For now
538 // always do thread 0.
539 assert(!thread->inSyscall);
540 thread->inSyscall = true;
542 // CPU will handle implementation of the interrupt.
543 cpu->processInterrupts();
545 // Now squash or record that I need to squash this cycle.
546 commitStatus = TrapPending;
548 // Exit state update mode to avoid accidental updating.
549 thread->inSyscall = false;
551 // Generate trap squash event.
554 DPRINTF(BE, "Interrupt detected.\n");
556 DPRINTF(BE, "Interrupt must wait for ROB to drain.\n");
562 template <class Impl>
564 LWBackEnd<Impl>::handleFault(Fault &fault, Tick latency)
566 DPRINTF(BE, "Handling fault!\n");
568 assert(!thread->inSyscall);
570 thread->inSyscall = true;
572 // Consider holding onto the trap and waiting until the trap event
573 // happens for this to be executed.
574 fault->invoke(thread->getTC());
576 // Exit state update mode to avoid accidental updating.
577 thread->inSyscall = false;
579 commitStatus = TrapPending;
581 // Generate trap squash event.
582 generateTrapEvent(latency);
585 template <class Impl>
587 LWBackEnd<Impl>::tick()
589 DPRINTF(BE, "Ticking back end\n");
591 if (switchPending && robEmpty() && !LSQ.hasStoresToWB()) {
592 cpu->signalSwitched();
596 ROB_count[0]+= numInsts;
600 // Read in any done instruction information and update the IQ or LSQ.
610 } else if (tcSquash) {
614 if (dispatchStatus != Blocked) {
617 checkDispatchStatus();
620 if (commitStatus != TrapPending) {
626 LSQ.writebackStores();
628 DPRINTF(BE, "Waiting insts: %i, mem ops: %i, ROB entries in use: %i, "
629 "LSQ loads: %i, LSQ stores: %i\n",
630 waitingInsts, numWaitingMemOps, numInsts,
631 LSQ.numLoads(), LSQ.numStores());
634 assert(numInsts == instList.size());
635 assert(waitingInsts == waitingList.size());
636 assert(numWaitingMemOps == waitingMemOps.size());
637 assert(!switchedOut);
641 template <class Impl>
643 LWBackEnd<Impl>::updateStructures()
645 if (fromCommit->doneSeqNum) {
646 LSQ.commitLoads(fromCommit->doneSeqNum);
647 LSQ.commitStores(fromCommit->doneSeqNum);
650 if (fromCommit->nonSpecSeqNum) {
651 if (fromCommit->uncached) {
652 // LSQ.executeLoad(fromCommit->lqIdx);
654 // IQ.scheduleNonSpec(
655 // fromCommit->nonSpecSeqNum);
660 template <class Impl>
662 LWBackEnd<Impl>::addToLSQ(DynInstPtr &inst)
664 // Do anything LSQ specific here?
668 template <class Impl>
670 LWBackEnd<Impl>::dispatchInsts()
672 DPRINTF(BE, "Trying to dispatch instructions.\n");
674 while (numInsts < numROBEntries &&
675 numWaitingMemOps < maxOutstandingMemOps) {
676 // Get instruction from front of time buffer
677 DynInstPtr inst = frontEnd->getInst();
680 } else if (inst->isSquashed()) {
685 instList.push_front(inst);
689 DPRINTF(BE, "Dispatching instruction [sn:%lli] PC:%#x\n",
690 inst->seqNum, inst->readPC());
692 for (int i = 0; i < inst->numDestRegs(); ++i)
693 renameTable[inst->destRegIdx(i)] = inst;
695 if (inst->isMemBarrier() || inst->isWriteBarrier()) {
697 DPRINTF(BE, "Instruction [sn:%lli] is waiting on "
698 "barrier [sn:%lli].\n",
699 inst->seqNum, memBarrier->seqNum);
700 memBarrier->addMemDependent(inst);
701 inst->addSrcMemInst(memBarrier);
704 inst->setCanCommit();
705 } else if (inst->readyToIssue() &&
706 !inst->isNonSpeculative() &&
707 !inst->isStoreConditional()) {
708 if (inst->isMemRef()) {
712 DPRINTF(BE, "Instruction [sn:%lli] is waiting on "
713 "barrier [sn:%lli].\n",
714 inst->seqNum, memBarrier->seqNum);
715 memBarrier->addMemDependent(inst);
716 inst->addSrcMemInst(memBarrier);
717 addWaitingMemOp(inst);
719 waitingList.push_front(inst);
720 inst->iqIt = waitingList.begin();
721 inst->iqItValid = true;
724 DPRINTF(BE, "Instruction [sn:%lli] ready, addding to "
729 } else if (inst->isNop()) {
730 DPRINTF(BE, "Nop encountered [sn:%lli], skipping exeList.\n",
734 inst->setCanCommit();
736 DPRINTF(BE, "Instruction [sn:%lli] ready, addding to "
742 if (inst->isNonSpeculative() || inst->isStoreConditional()) {
743 inst->setCanCommit();
744 DPRINTF(BE, "Adding non speculative instruction\n");
747 if (inst->isMemRef()) {
748 addWaitingMemOp(inst);
751 memBarrier->addMemDependent(inst);
752 inst->addSrcMemInst(memBarrier);
754 DPRINTF(BE, "Instruction [sn:%lli] is waiting on "
755 "barrier [sn:%lli].\n",
756 inst->seqNum, memBarrier->seqNum);
760 DPRINTF(BE, "Instruction [sn:%lli] not ready, addding to "
763 waitingList.push_front(inst);
764 inst->iqIt = waitingList.begin();
765 inst->iqItValid = true;
770 // Check if IQ or LSQ is full. If so we'll need to break and stop
771 // removing instructions. Also update the number of insts to remove
772 // from the queue. Check here if we don't care about exact stall
777 DPRINTF(BE, "IQ is full!\n");
779 } else if (LSQ.isFull()) {
780 DPRINTF(BE, "LSQ is full!\n");
782 } else if (isFull()) {
783 DPRINTF(BE, "ROB is full!\n");
795 template <class Impl>
797 LWBackEnd<Impl>::dispatchStall()
799 dispatchStatus = Blocked;
800 if (!cpu->decoupledFrontEnd) {
801 // Tell front end to stall here through a timebuffer, or just tell
806 template <class Impl>
808 LWBackEnd<Impl>::checkDispatchStatus()
810 DPRINTF(BE, "Checking dispatch status\n");
811 assert(dispatchStatus == Blocked);
812 if (!LSQ.isFull() && !isFull()) {
813 DPRINTF(BE, "Dispatch no longer blocked\n");
814 dispatchStatus = Running;
819 template <class Impl>
821 LWBackEnd<Impl>::executeInsts()
823 DPRINTF(BE, "Trying to execute instructions\n");
825 int num_executed = 0;
826 while (!exeList.empty() && num_executed < issueWidth) {
827 DynInstPtr inst = exeList.top();
829 DPRINTF(BE, "Executing inst [sn:%lli] PC: %#x\n",
830 inst->seqNum, inst->readPC());
832 // Check if the instruction is squashed; if so then skip it
833 // and don't count it towards the FU usage.
834 if (inst->isSquashed()) {
835 DPRINTF(BE, "Execute: Instruction was squashed.\n");
837 // Not sure how to handle this plus the method of sending # of
838 // instructions to use. Probably will just have to count it
839 // towards the bandwidth usage, but not the FU usage.
842 // Consider this instruction executed so that commit can go
843 // ahead and retire the instruction.
846 // Not sure if I should set this here or just let commit try to
847 // commit any squashed instructions. I like the latter a bit more.
848 inst->setCanCommit();
850 // ++iewExecSquashedInsts;
856 Fault fault = NoFault;
858 // Execute instruction.
859 // Note that if the instruction faults, it will be handled
860 // at the commit stage.
861 if (inst->isMemRef() &&
862 (!inst->isDataPrefetch() && !inst->isInstPrefetch())) {
863 DPRINTF(BE, "Execute: Initiating access for memory "
866 if (inst->isLoad()) {
867 LSQ.executeLoad(inst);
868 } else if (inst->isStore()) {
869 LSQ.executeStore(inst);
870 if (inst->req && !(inst->req->getFlags() & LOCKED)) {
876 panic("Unknown mem type!");
886 updateExeInstStats(inst);
893 if (inst->mispredicted()) {
894 squashDueToBranch(inst);
896 } else if (LSQ.violation()) {
897 // Get the DynInst that caused the violation. Note that this
898 // clears the violation signal.
900 violator = LSQ.getMemDepViolator();
902 DPRINTF(BE, "LDSTQ detected a violation. Violator PC: "
903 "%#x, inst PC: %#x. Addr is: %#x.\n",
904 violator->readPC(), inst->readPC(), inst->physEffAddr);
907 squashDueToMemViolation(inst);
911 issued_ops[0]+= num_executed;
912 n_issued_dist[num_executed]++;
917 LWBackEnd<Impl>::instToCommit(DynInstPtr &inst)
920 DPRINTF(BE, "Sending instructions to commit [sn:%lli] PC %#x.\n",
921 inst->seqNum, inst->readPC());
923 if (!inst->isSquashed()) {
924 DPRINTF(BE, "Writing back instruction [sn:%lli] PC %#x.\n",
925 inst->seqNum, inst->readPC());
927 inst->setCanCommit();
929 if (inst->isExecuted()) {
930 inst->setResultReady();
931 int dependents = wakeDependents(inst);
934 consumer_inst[0]+= dependents;
939 writeback_count[0]++;
942 template <class Impl>
944 LWBackEnd<Impl>::writebackInsts()
946 int wb_width = wbWidth;
947 // Using this method I'm not quite sure how to prevent an
948 // instruction from waking its own dependents multiple times,
949 // without the guarantee that commit always has enough bandwidth
950 // to accept all instructions being written back. This guarantee
951 // might not be too unrealistic.
952 InstListIt wb_inst_it = writeback.begin();
953 InstListIt wb_end_it = writeback.end();
955 int consumer_insts = 0;
957 for (; inst_num < wb_width &&
958 wb_inst_it != wb_end_it; inst_num++) {
959 DynInstPtr inst = (*wb_inst_it);
961 // Some instructions will be sent to commit without having
962 // executed because they need commit to handle them.
963 // E.g. Uncached loads have not actually executed when they
964 // are first sent to commit. Instead commit must tell the LSQ
965 // when it's ready to execute the uncached load.
966 if (!inst->isSquashed()) {
967 DPRINTF(BE, "Writing back instruction [sn:%lli] PC %#x.\n",
968 inst->seqNum, inst->readPC());
970 inst->setCanCommit();
971 inst->setResultReady();
973 if (inst->isExecuted()) {
974 int dependents = wakeDependents(inst);
977 consumer_insts+= dependents;
982 writeback.erase(wb_inst_it++);
984 LSQ.writebackStores();
985 consumer_inst[0]+= consumer_insts;
986 writeback_count[0]+= inst_num;
989 template <class Impl>
991 LWBackEnd<Impl>::commitInst(int inst_num)
993 // Read instruction from the head of the ROB
994 DynInstPtr inst = instList.back();
996 // Make sure instruction is valid
999 if (!inst->readyToCommit())
1002 DPRINTF(BE, "Trying to commit instruction [sn:%lli] PC:%#x\n",
1003 inst->seqNum, inst->readPC());
1005 thread->setPC(inst->readPC());
1006 thread->setNextPC(inst->readNextPC());
1007 inst->setAtCommit();
1009 // If the instruction is not executed yet, then it is a non-speculative
1010 // or store inst. Signal backwards that it should be executed.
1011 if (!inst->isExecuted()) {
1012 if (inst->isNonSpeculative() ||
1013 inst->isStoreConditional() ||
1014 inst->isMemBarrier() ||
1015 inst->isWriteBarrier()) {
1017 // Hack to make sure syscalls aren't executed until all stores
1018 // write back their data. This direct communication shouldn't
1019 // be used for anything other than this.
1020 if (inst_num > 0 || LSQ.hasStoresToWB())
1022 if ((inst->isMemBarrier() || inst->isWriteBarrier() ||
1023 inst->isQuiesce()) &&
1024 LSQ.hasStoresToWB())
1027 DPRINTF(BE, "Waiting for all stores to writeback.\n");
1031 DPRINTF(BE, "Encountered a store or non-speculative "
1032 "instruction at the head of the ROB, PC %#x.\n",
1035 if (inst->isMemBarrier() || inst->isWriteBarrier()) {
1036 DPRINTF(BE, "Waking dependents on barrier [sn:%lli]\n",
1039 wakeDependents(inst, true);
1040 if (memBarrier == inst)
1042 inst->clearMemDependents();
1045 // Send back the non-speculative instruction's sequence number.
1046 if (inst->iqItValid) {
1047 DPRINTF(BE, "Removing instruction from waiting list\n");
1048 waitingList.erase(inst->iqIt);
1049 inst->iqItValid = false;
1051 assert(waitingInsts >= 0);
1052 if (inst->isStore())
1053 removeWaitingMemOp(inst);
1058 // Change the instruction so it won't try to commit again until
1060 inst->clearCanCommit();
1062 // ++commitNonSpecStalls;
1065 } else if (inst->isLoad()) {
1066 DPRINTF(BE, "[sn:%lli]: Uncached load, PC %#x.\n",
1067 inst->seqNum, inst->readPC());
1069 // Send back the non-speculative instruction's sequence
1070 // number. Maybe just tell the lsq to re-execute the load.
1072 // Send back the non-speculative instruction's sequence number.
1073 if (inst->iqItValid) {
1074 DPRINTF(BE, "Removing instruction from waiting list\n");
1075 waitingList.erase(inst->iqIt);
1076 inst->iqItValid = false;
1078 assert(waitingInsts >= 0);
1079 removeWaitingMemOp(inst);
1081 replayMemInst(inst);
1083 inst->clearCanCommit();
1087 panic("Trying to commit un-executed instruction "
1088 "of unknown type!\n");
1092 // Not handled for now.
1093 assert(!inst->isThreadSync());
1094 assert(inst->memDepReady());
1095 // Stores will mark themselves as totally completed as they need
1096 // to wait to writeback to memory. @todo: Hack...attempt to fix
1097 // having the checker be forced to wait until a store completes in
1098 // order to check all of the instructions. If the store at the
1099 // head of the check list misses, but a later store hits, then
1100 // loads in the checker may see the younger store values instead
1101 // of the store they should see. Either the checker needs its own
1102 // memory (annoying to update), its own store buffer (how to tell
1103 // which value is correct?), or something else...
1104 if (!inst->isStore()) {
1105 inst->setCompleted();
1107 // Check if the instruction caused a fault. If so, trap.
1108 Fault inst_fault = inst->getFault();
1110 // Use checker prior to updating anything due to traps or PC
1114 checker->verify(inst);
1118 if (inst_fault != NoFault) {
1119 DPRINTF(BE, "Inst [sn:%lli] PC %#x has a fault\n",
1120 inst->seqNum, inst->readPC());
1122 // Instruction is completed as it has a fault.
1123 inst->setCompleted();
1125 if (LSQ.hasStoresToWB()) {
1126 DPRINTF(BE, "Stores still in flight, will wait until drained.\n");
1128 } else if (inst_num != 0) {
1129 DPRINTF(BE, "Will wait until instruction is head of commit group.\n");
1133 else if (checker && inst->isStore()) {
1134 checker->verify(inst);
1139 static_cast<TheISA::MachInst>(inst->staticInst->machInst));
1141 handleFault(inst_fault);
1147 for (int i = 0; i < inst->numDestRegs(); ++i) {
1148 DPRINTF(BE, "Commit rename map setting reg %i to [sn:%lli]\n",
1149 (int)inst->destRegIdx(i), inst->seqNum);
1150 thread->renameTable[inst->destRegIdx(i)] = inst;
1154 if (inst->traceData) {
1155 inst->traceData->setFetchSeq(inst->seqNum);
1156 inst->traceData->setCPSeq(thread->numInst);
1157 inst->traceData->finalize();
1158 inst->traceData = NULL;
1161 inst->clearDependents();
1163 frontEnd->addFreeRegs(freed_regs);
1165 instList.pop_back();
1168 ++thread->funcExeInst;
1169 // Maybe move this to where the fault is handled; if the fault is
1170 // handled, don't try to set this myself as the fault will set it.
1171 // If not, then I set thread->PC = thread->nextPC and
1172 // thread->nextPC = thread->nextPC + 4.
1173 thread->setPC(thread->readNextPC());
1174 thread->setNextPC(thread->readNextPC() + sizeof(TheISA::MachInst));
1175 updateComInstStats(inst);
1177 // Write the done sequence number here.
1178 toIEW->doneSeqNum = inst->seqNum;
1179 lastCommitCycle = curTick;
1186 assert(!thread->inSyscall && !thread->trapPending);
1187 oldpc = thread->readPC();
1188 cpu->system->pcEventQueue.service(
1191 } while (oldpc != thread->readPC());
1193 DPRINTF(BE, "PC skip function event, stopping commit\n");
1201 template <class Impl>
1203 LWBackEnd<Impl>::commitInsts()
1205 // Not sure this should be a loop or not.
1207 while (!instList.empty() && inst_num < commitWidth) {
1208 if (instList.back()->isSquashed()) {
1209 instList.back()->clearDependents();
1210 instList.pop_back();
1212 ROBSquashedInsts[instList.back()->threadNumber]++;
1216 if (!commitInst(inst_num++)) {
1217 DPRINTF(BE, "Can't commit, Instruction [sn:%lli] PC "
1218 "%#x is head of ROB and not ready\n",
1219 instList.back()->seqNum, instList.back()->readPC());
1224 n_committed_dist.sample(inst_num);
1227 template <class Impl>
1229 LWBackEnd<Impl>::squash(const InstSeqNum &sn)
1234 InstListIt waiting_list_end = waitingList.end();
1235 InstListIt insts_it = waitingList.begin();
1237 while (insts_it != waiting_list_end && (*insts_it)->seqNum > sn)
1239 if ((*insts_it)->isSquashed()) {
1243 DPRINTF(BE, "Squashing instruction on waitingList PC %#x, [sn:%lli].\n",
1244 (*insts_it)->readPC(),
1245 (*insts_it)->seqNum);
1247 if ((*insts_it)->isMemRef()) {
1248 DPRINTF(BE, "Squashing a waiting mem op [sn:%lli]\n",
1249 (*insts_it)->seqNum);
1250 removeWaitingMemOp((*insts_it));
1253 waitingList.erase(insts_it++);
1256 assert(waitingInsts >= 0);
1258 insts_it = instList.begin();
1260 while (!instList.empty() && (*insts_it)->seqNum > sn)
1262 if ((*insts_it)->isSquashed()) {
1266 DPRINTF(BE, "Squashing instruction on inst list PC %#x, [sn:%lli].\n",
1267 (*insts_it)->readPC(),
1268 (*insts_it)->seqNum);
1270 // Mark the instruction as squashed, and ready to commit so that
1271 // it can drain out of the pipeline.
1272 (*insts_it)->setSquashed();
1274 (*insts_it)->setCanCommit();
1276 (*insts_it)->clearInROB();
1278 for (int i = 0; i < (*insts_it)->numDestRegs(); ++i) {
1279 DynInstPtr prev_dest = (*insts_it)->getPrevDestInst(i);
1280 DPRINTF(BE, "Commit rename map setting reg %i to [sn:%lli]\n",
1281 (int)(*insts_it)->destRegIdx(i), prev_dest->seqNum);
1282 renameTable[(*insts_it)->destRegIdx(i)] = prev_dest;
1286 (*insts_it)->clearDependents();
1288 squashedInsts[(*insts_it)->threadNumber]++;
1290 instList.erase(insts_it++);
1294 insts_it = waitingList.begin();
1295 while (!waitingList.empty() && insts_it != waitingList.end()) {
1296 if ((*insts_it)->seqNum < sn) {
1300 assert((*insts_it)->isSquashed());
1302 waitingList.erase(insts_it++);
1306 while (memBarrier && memBarrier->seqNum > sn) {
1307 DPRINTF(BE, "[sn:%lli] Memory barrier squashed (or previously "
1308 "squashed)\n", memBarrier->seqNum);
1309 memBarrier->clearMemDependents();
1310 if (memBarrier->memDepReady()) {
1311 DPRINTF(BE, "No previous barrier\n");
1314 std::list<DynInstPtr> &srcs = memBarrier->getMemSrcs();
1315 memBarrier = srcs.front();
1317 assert(srcs.empty());
1318 DPRINTF(BE, "Previous barrier: [sn:%lli]\n",
1319 memBarrier->seqNum);
1323 frontEnd->addFreeRegs(freed_regs);
1326 template <class Impl>
1328 LWBackEnd<Impl>::squashFromTC()
1330 InstSeqNum squashed_inst = robEmpty() ? 0 : instList.back()->seqNum - 1;
1331 squash(squashed_inst);
1332 frontEnd->squash(squashed_inst, thread->readPC(),
1334 frontEnd->interruptPending = false;
1336 thread->trapPending = false;
1337 thread->inSyscall = false;
1339 commitStatus = Running;
1342 template <class Impl>
1344 LWBackEnd<Impl>::squashFromTrap()
1346 InstSeqNum squashed_inst = robEmpty() ? 0 : instList.back()->seqNum - 1;
1347 squash(squashed_inst);
1348 frontEnd->squash(squashed_inst, thread->readPC(),
1350 frontEnd->interruptPending = false;
1352 thread->trapPending = false;
1353 thread->inSyscall = false;
1355 commitStatus = Running;
1358 template <class Impl>
1360 LWBackEnd<Impl>::squashDueToBranch(DynInstPtr &inst)
1362 // Update the branch predictor state I guess
1363 DPRINTF(BE, "Squashing due to branch [sn:%lli], will restart at PC %#x\n",
1364 inst->seqNum, inst->readNextPC());
1365 squash(inst->seqNum);
1366 frontEnd->squash(inst->seqNum, inst->readNextPC(),
1367 true, inst->mispredicted());
1370 template <class Impl>
1372 LWBackEnd<Impl>::squashDueToMemViolation(DynInstPtr &inst)
1374 // Update the branch predictor state I guess
1375 DPRINTF(BE, "Squashing due to violation [sn:%lli], will restart at PC %#x\n",
1376 inst->seqNum, inst->readNextPC());
1377 squash(inst->seqNum);
1378 frontEnd->squash(inst->seqNum, inst->readNextPC(),
1379 false, inst->mispredicted());
1382 template <class Impl>
1384 LWBackEnd<Impl>::squashDueToMemBlocked(DynInstPtr &inst)
1386 DPRINTF(IEW, "Memory blocked, squashing load and younger insts, "
1387 "PC: %#x [sn:%i].\n", inst->readPC(), inst->seqNum);
1389 squash(inst->seqNum - 1);
1390 frontEnd->squash(inst->seqNum - 1, inst->readPC());
1393 template <class Impl>
1395 LWBackEnd<Impl>::fetchFault(Fault &fault)
1397 faultFromFetch = fault;
1398 fetchHasFault = true;
1401 template <class Impl>
1403 LWBackEnd<Impl>::switchOut()
1405 switchPending = true;
1408 template <class Impl>
1410 LWBackEnd<Impl>::doSwitchOut()
1413 switchPending = false;
1414 // Need to get rid of all committed, non-speculative state and write it
1415 // to memory/TC. In this case this is stores that have committed and not
1416 // yet written back.
1418 assert(!LSQ.hasStoresToWB());
1425 template <class Impl>
1427 LWBackEnd<Impl>::takeOverFrom(ThreadContext *old_tc)
1429 switchedOut = false;
1434 numWaitingMemOps = 0;
1435 waitingMemOps.clear();
1437 switchedOut = false;
1438 dispatchStatus = Running;
1439 commitStatus = Running;
1440 LSQ.takeOverFrom(old_tc);
1443 template <class Impl>
1445 LWBackEnd<Impl>::updateExeInstStats(DynInstPtr &inst)
1447 int thread_number = inst->threadNumber;
1450 // Pick off the software prefetches
1453 if (inst->isDataPrefetch())
1454 exe_swp[thread_number]++;
1456 exe_inst[thread_number]++;
1458 exe_inst[thread_number]++;
1462 // Control operations
1464 if (inst->isControl())
1465 exe_branches[thread_number]++;
1468 // Memory operations
1470 if (inst->isMemRef()) {
1471 exe_refs[thread_number]++;
1474 exe_loads[thread_number]++;
1478 template <class Impl>
1480 LWBackEnd<Impl>::updateComInstStats(DynInstPtr &inst)
1482 unsigned tid = inst->threadNumber;
1484 // keep an instruction count
1490 // Pick off the software prefetches
1493 if (inst->isDataPrefetch()) {
1494 stat_com_swp[tid]++;
1496 stat_com_inst[tid]++;
1499 stat_com_inst[tid]++;
1503 // Control Instructions
1505 if (inst->isControl())
1506 stat_com_branches[tid]++;
1509 // Memory references
1511 if (inst->isMemRef()) {
1512 stat_com_refs[tid]++;
1514 if (inst->isLoad()) {
1515 stat_com_loads[tid]++;
1519 if (inst->isMemBarrier()) {
1520 stat_com_membars[tid]++;
1524 template <class Impl>
1526 LWBackEnd<Impl>::dumpInsts()
1531 InstListIt inst_list_it = --(instList.end());
1533 cprintf("ExeList size: %i\n", exeList.size());
1535 cprintf("Inst list size: %i\n", instList.size());
1537 while (inst_list_it != instList.end())
1539 cprintf("Instruction:%i\n",
1541 if (!(*inst_list_it)->isSquashed()) {
1542 if (!(*inst_list_it)->isIssued()) {
1544 cprintf("Count:%i\n", valid_num);
1545 } else if ((*inst_list_it)->isMemRef() &&
1546 !(*inst_list_it)->memOpDone) {
1547 // Loads that have not been marked as executed still count
1548 // towards the total instructions.
1550 cprintf("Count:%i\n", valid_num);
1554 cprintf("PC:%#x\n[sn:%lli]\n[tid:%i]\n"
1555 "Issued:%i\nSquashed:%i\n",
1556 (*inst_list_it)->readPC(),
1557 (*inst_list_it)->seqNum,
1558 (*inst_list_it)->threadNumber,
1559 (*inst_list_it)->isIssued(),
1560 (*inst_list_it)->isSquashed());
1562 if ((*inst_list_it)->isMemRef()) {
1563 cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone);
1572 cprintf("Waiting list size: %i\n", waitingList.size());
1574 inst_list_it = --(waitingList.end());
1576 while (inst_list_it != waitingList.end())
1578 cprintf("Instruction:%i\n",
1580 if (!(*inst_list_it)->isSquashed()) {
1581 if (!(*inst_list_it)->isIssued()) {
1583 cprintf("Count:%i\n", valid_num);
1584 } else if ((*inst_list_it)->isMemRef() &&
1585 !(*inst_list_it)->memOpDone) {
1586 // Loads that have not been marked as executed still count
1587 // towards the total instructions.
1589 cprintf("Count:%i\n", valid_num);
1593 cprintf("PC:%#x\n[sn:%lli]\n[tid:%i]\n"
1594 "Issued:%i\nSquashed:%i\n",
1595 (*inst_list_it)->readPC(),
1596 (*inst_list_it)->seqNum,
1597 (*inst_list_it)->threadNumber,
1598 (*inst_list_it)->isIssued(),
1599 (*inst_list_it)->isSquashed());
1601 if ((*inst_list_it)->isMemRef()) {
1602 cprintf("MemOpDone:%i\n", (*inst_list_it)->memOpDone);
1611 cprintf("waitingMemOps list size: %i\n", waitingMemOps.size());
1613 MemIt waiting_it = waitingMemOps.begin();
1615 while (waiting_it != waitingMemOps.end())
1617 cprintf("[sn:%lli] ", (*waiting_it));