2 * Copyright (c) 2010-2014 ARM Limited
3 * Copyright (c) 2012-2013 AMD
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.
15 * Copyright (c) 2004-2006 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
45 #ifndef __CPU_O3_FETCH_IMPL_HH__
46 #define __CPU_O3_FETCH_IMPL_HH__
54 #include "arch/generic/tlb.hh"
55 #include "arch/isa_traits.hh"
56 #include "arch/utility.hh"
57 #include "arch/vtophys.hh"
58 #include "base/random.hh"
59 #include "base/types.hh"
60 #include "config/the_isa.hh"
61 #include "cpu/base.hh"
62 //#include "cpu/checker/cpu.hh"
63 #include "cpu/o3/fetch.hh"
64 #include "cpu/exetrace.hh"
65 #include "debug/Activity.hh"
66 #include "debug/Drain.hh"
67 #include "debug/Fetch.hh"
68 #include "debug/O3PipeView.hh"
69 #include "mem/packet.hh"
70 #include "params/DerivO3CPU.hh"
71 #include "sim/byteswap.hh"
72 #include "sim/core.hh"
73 #include "sim/eventq.hh"
74 #include "sim/full_system.hh"
75 #include "sim/system.hh"
76 #include "cpu/o3/isa_specific.hh"
81 DefaultFetch<Impl>::DefaultFetch(O3CPU *_cpu, DerivO3CPUParams *params)
82 : fetchPolicy(params->smtFetchPolicy),
85 decodeToFetchDelay(params->decodeToFetchDelay),
86 renameToFetchDelay(params->renameToFetchDelay),
87 iewToFetchDelay(params->iewToFetchDelay),
88 commitToFetchDelay(params->commitToFetchDelay),
89 fetchWidth(params->fetchWidth),
90 decodeWidth(params->decodeWidth),
92 retryTid(InvalidThreadID),
93 cacheBlkSize(cpu->cacheLineSize()),
94 fetchBufferSize(params->fetchBufferSize),
95 fetchBufferMask(fetchBufferSize - 1),
96 fetchQueueSize(params->fetchQueueSize),
97 numThreads(params->numThreads),
98 numFetchingThreads(params->smtNumFetchingThreads),
99 finishTranslationEvent(this)
101 if (numThreads > Impl::MaxThreads)
102 fatal("numThreads (%d) is larger than compiled limit (%d),\n"
103 "\tincrease MaxThreads in src/cpu/o3/impl.hh\n",
104 numThreads, static_cast<int>(Impl::MaxThreads));
105 if (fetchWidth > Impl::MaxWidth)
106 fatal("fetchWidth (%d) is larger than compiled limit (%d),\n"
107 "\tincrease MaxWidth in src/cpu/o3/impl.hh\n",
108 fetchWidth, static_cast<int>(Impl::MaxWidth));
109 if (fetchBufferSize > cacheBlkSize)
110 fatal("fetch buffer size (%u bytes) is greater than the cache "
111 "block size (%u bytes)\n", fetchBufferSize, cacheBlkSize);
112 if (cacheBlkSize % fetchBufferSize)
113 fatal("cache block (%u bytes) is not a multiple of the "
114 "fetch buffer (%u bytes)\n", cacheBlkSize, fetchBufferSize);
116 // Figure out fetch policy
117 panic_if(fetchPolicy == FetchPolicy::SingleThread && numThreads > 1,
118 "Invalid Fetch Policy for a SMT workload.");
120 // Get the size of an instruction.
121 instSize = sizeof(TheISA::MachInst);
123 for (int i = 0; i < Impl::MaxThreads; i++) {
124 fetchStatus[i] = Idle;
125 decoder[i] = nullptr;
128 macroop[i] = nullptr;
129 delayedCommit[i] = false;
131 stalls[i] = {false, false};
132 fetchBuffer[i] = NULL;
133 fetchBufferPC[i] = 0;
134 fetchBufferValid[i] = false;
135 lastIcacheStall[i] = 0;
136 issuePipelinedIfetch[i] = false;
139 branchPred = params->branchPred;
141 for (ThreadID tid = 0; tid < numThreads; tid++) {
142 decoder[tid] = new TheISA::Decoder(params->isa[tid]);
143 // Create space to buffer the cache line data,
144 // which may not hold the entire cache line.
145 fetchBuffer[tid] = new uint8_t[fetchBufferSize];
149 template <class Impl>
151 DefaultFetch<Impl>::name() const
153 return cpu->name() + ".fetch";
156 template <class Impl>
158 DefaultFetch<Impl>::regProbePoints()
160 ppFetch = new ProbePointArg<DynInstPtr>(cpu->getProbeManager(), "Fetch");
161 ppFetchRequestSent = new ProbePointArg<RequestPtr>(cpu->getProbeManager(),
166 template <class Impl>
168 DefaultFetch<Impl>::regStats()
171 .name(name() + ".icacheStallCycles")
172 .desc("Number of cycles fetch is stalled on an Icache miss")
173 .prereq(icacheStallCycles);
176 .name(name() + ".Insts")
177 .desc("Number of instructions fetch has processed")
178 .prereq(fetchedInsts);
181 .name(name() + ".Branches")
182 .desc("Number of branches that fetch encountered")
183 .prereq(fetchedBranches);
186 .name(name() + ".predictedBranches")
187 .desc("Number of branches that fetch has predicted taken")
188 .prereq(predictedBranches);
191 .name(name() + ".Cycles")
192 .desc("Number of cycles fetch has run and was not squashing or"
194 .prereq(fetchCycles);
197 .name(name() + ".SquashCycles")
198 .desc("Number of cycles fetch has spent squashing")
199 .prereq(fetchSquashCycles);
202 .name(name() + ".TlbCycles")
203 .desc("Number of cycles fetch has spent waiting for tlb")
204 .prereq(fetchTlbCycles);
207 .name(name() + ".IdleCycles")
208 .desc("Number of cycles fetch was idle")
209 .prereq(fetchIdleCycles);
212 .name(name() + ".BlockedCycles")
213 .desc("Number of cycles fetch has spent blocked")
214 .prereq(fetchBlockedCycles);
217 .name(name() + ".CacheLines")
218 .desc("Number of cache lines fetched")
219 .prereq(fetchedCacheLines);
222 .name(name() + ".MiscStallCycles")
223 .desc("Number of cycles fetch has spent waiting on interrupts, or "
224 "bad addresses, or out of MSHRs")
225 .prereq(fetchMiscStallCycles);
227 fetchPendingDrainCycles
228 .name(name() + ".PendingDrainCycles")
229 .desc("Number of cycles fetch has spent waiting on pipes to drain")
230 .prereq(fetchPendingDrainCycles);
232 fetchNoActiveThreadStallCycles
233 .name(name() + ".NoActiveThreadStallCycles")
234 .desc("Number of stall cycles due to no active thread to fetch from")
235 .prereq(fetchNoActiveThreadStallCycles);
237 fetchPendingTrapStallCycles
238 .name(name() + ".PendingTrapStallCycles")
239 .desc("Number of stall cycles due to pending traps")
240 .prereq(fetchPendingTrapStallCycles);
242 fetchPendingQuiesceStallCycles
243 .name(name() + ".PendingQuiesceStallCycles")
244 .desc("Number of stall cycles due to pending quiesce instructions")
245 .prereq(fetchPendingQuiesceStallCycles);
247 fetchIcacheWaitRetryStallCycles
248 .name(name() + ".IcacheWaitRetryStallCycles")
249 .desc("Number of stall cycles due to full MSHR")
250 .prereq(fetchIcacheWaitRetryStallCycles);
253 .name(name() + ".IcacheSquashes")
254 .desc("Number of outstanding Icache misses that were squashed")
255 .prereq(fetchIcacheSquashes);
258 .name(name() + ".ItlbSquashes")
259 .desc("Number of outstanding ITLB misses that were squashed")
260 .prereq(fetchTlbSquashes);
263 .init(/* base value */ 0,
264 /* last value */ fetchWidth,
266 .name(name() + ".rateDist")
267 .desc("Number of instructions fetched each cycle (Total)")
271 .name(name() + ".idleRate")
272 .desc("Percent of cycles fetch was idle")
274 idleRate = fetchIdleCycles * 100 / cpu->numCycles;
277 .name(name() + ".branchRate")
278 .desc("Number of branch fetches per cycle")
279 .flags(Stats::total);
280 branchRate = fetchedBranches / cpu->numCycles;
283 .name(name() + ".rate")
284 .desc("Number of inst fetches per cycle")
285 .flags(Stats::total);
286 fetchRate = fetchedInsts / cpu->numCycles;
291 DefaultFetch<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer)
293 timeBuffer = time_buffer;
295 // Create wires to get information from proper places in time buffer.
296 fromDecode = timeBuffer->getWire(-decodeToFetchDelay);
297 fromRename = timeBuffer->getWire(-renameToFetchDelay);
298 fromIEW = timeBuffer->getWire(-iewToFetchDelay);
299 fromCommit = timeBuffer->getWire(-commitToFetchDelay);
304 DefaultFetch<Impl>::setActiveThreads(std::list<ThreadID> *at_ptr)
306 activeThreads = at_ptr;
311 DefaultFetch<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *ftb_ptr)
313 // Create wire to write information to proper place in fetch time buf.
314 toDecode = ftb_ptr->getWire(0);
319 DefaultFetch<Impl>::startupStage()
321 assert(priorityList.empty());
324 // Fetch needs to start fetching instructions at the very beginning,
325 // so it must start up in active state.
331 DefaultFetch<Impl>::clearStates(ThreadID tid)
333 fetchStatus[tid] = Running;
334 pc[tid] = cpu->pcState(tid);
335 fetchOffset[tid] = 0;
337 delayedCommit[tid] = false;
339 stalls[tid].decode = false;
340 stalls[tid].drain = false;
341 fetchBufferPC[tid] = 0;
342 fetchBufferValid[tid] = false;
343 fetchQueue[tid].clear();
345 // TODO not sure what to do with priorityList for now
346 // priorityList.push_back(tid);
351 DefaultFetch<Impl>::resetStage()
354 interruptPending = false;
355 cacheBlocked = false;
357 priorityList.clear();
359 // Setup PC and nextPC with initial state.
360 for (ThreadID tid = 0; tid < numThreads; ++tid) {
361 fetchStatus[tid] = Running;
362 pc[tid] = cpu->pcState(tid);
363 fetchOffset[tid] = 0;
366 delayedCommit[tid] = false;
369 stalls[tid].decode = false;
370 stalls[tid].drain = false;
372 fetchBufferPC[tid] = 0;
373 fetchBufferValid[tid] = false;
375 fetchQueue[tid].clear();
377 priorityList.push_back(tid);
380 wroteToTimeBuffer = false;
386 DefaultFetch<Impl>::processCacheCompletion(PacketPtr pkt)
388 ThreadID tid = cpu->contextToThread(pkt->req->contextId());
390 DPRINTF(Fetch, "[tid:%u] Waking up from cache miss.\n", tid);
391 assert(!cpu->switchedOut());
393 // Only change the status if it's still waiting on the icache access
395 if (fetchStatus[tid] != IcacheWaitResponse ||
396 pkt->req != memReq[tid]) {
397 ++fetchIcacheSquashes;
402 memcpy(fetchBuffer[tid], pkt->getConstPtr<uint8_t>(), fetchBufferSize);
403 fetchBufferValid[tid] = true;
405 // Wake up the CPU (if it went to sleep and was waiting on
406 // this completion event).
409 DPRINTF(Activity, "[tid:%u] Activating fetch due to cache completion\n",
414 // Only switch to IcacheAccessComplete if we're not stalled as well.
415 if (checkStall(tid)) {
416 fetchStatus[tid] = Blocked;
418 fetchStatus[tid] = IcacheAccessComplete;
421 pkt->req->setAccessLatency();
422 cpu->ppInstAccessComplete->notify(pkt);
423 // Reset the mem req to NULL.
428 template <class Impl>
430 DefaultFetch<Impl>::drainResume()
432 for (ThreadID i = 0; i < numThreads; ++i) {
433 stalls[i].decode = false;
434 stalls[i].drain = false;
438 template <class Impl>
440 DefaultFetch<Impl>::drainSanityCheck() const
443 assert(retryPkt == NULL);
444 assert(retryTid == InvalidThreadID);
445 assert(!cacheBlocked);
446 assert(!interruptPending);
448 for (ThreadID i = 0; i < numThreads; ++i) {
450 assert(fetchStatus[i] == Idle || stalls[i].drain);
453 branchPred->drainSanityCheck();
456 template <class Impl>
458 DefaultFetch<Impl>::isDrained() const
460 /* Make sure that threads are either idle of that the commit stage
461 * has signaled that draining has completed by setting the drain
462 * stall flag. This effectively forces the pipeline to be disabled
463 * until the whole system is drained (simulation may continue to
464 * drain other components).
466 for (ThreadID i = 0; i < numThreads; ++i) {
467 // Verify fetch queues are drained
468 if (!fetchQueue[i].empty())
471 // Return false if not idle or drain stalled
472 if (fetchStatus[i] != Idle) {
473 if (fetchStatus[i] == Blocked && stalls[i].drain)
480 /* The pipeline might start up again in the middle of the drain
481 * cycle if the finish translation event is scheduled, so make
482 * sure that's not the case.
484 return !finishTranslationEvent.scheduled();
487 template <class Impl>
489 DefaultFetch<Impl>::takeOverFrom()
491 assert(cpu->getInstPort().isConnected());
496 template <class Impl>
498 DefaultFetch<Impl>::drainStall(ThreadID tid)
500 assert(cpu->isDraining());
501 assert(!stalls[tid].drain);
502 DPRINTF(Drain, "%i: Thread drained.\n", tid);
503 stalls[tid].drain = true;
506 template <class Impl>
508 DefaultFetch<Impl>::wakeFromQuiesce()
510 DPRINTF(Fetch, "Waking up from quiesce\n");
511 // Hopefully this is safe
512 // @todo: Allow other threads to wake from quiesce.
513 fetchStatus[0] = Running;
516 template <class Impl>
518 DefaultFetch<Impl>::switchToActive()
520 if (_status == Inactive) {
521 DPRINTF(Activity, "Activating stage.\n");
523 cpu->activateStage(O3CPU::FetchIdx);
529 template <class Impl>
531 DefaultFetch<Impl>::switchToInactive()
533 if (_status == Active) {
534 DPRINTF(Activity, "Deactivating stage.\n");
536 cpu->deactivateStage(O3CPU::FetchIdx);
542 template <class Impl>
544 DefaultFetch<Impl>::deactivateThread(ThreadID tid)
546 // Update priority list
547 auto thread_it = std::find(priorityList.begin(), priorityList.end(), tid);
548 if (thread_it != priorityList.end()) {
549 priorityList.erase(thread_it);
553 template <class Impl>
555 DefaultFetch<Impl>::lookupAndUpdateNextPC(
556 const DynInstPtr &inst, TheISA::PCState &nextPC)
558 // Do branch prediction check here.
559 // A bit of a misnomer...next_PC is actually the current PC until
560 // this function updates it.
563 if (!inst->isControl()) {
564 TheISA::advancePC(nextPC, inst->staticInst);
565 inst->setPredTarg(nextPC);
566 inst->setPredTaken(false);
570 ThreadID tid = inst->threadNumber;
571 predict_taken = branchPred->predict(inst->staticInst, inst->seqNum,
575 DPRINTF(Fetch, "[tid:%i]: [sn:%i]: Branch predicted to be taken to %s.\n",
576 tid, inst->seqNum, nextPC);
578 DPRINTF(Fetch, "[tid:%i]: [sn:%i]:Branch predicted to be not taken.\n",
582 DPRINTF(Fetch, "[tid:%i]: [sn:%i] Branch predicted to go to %s.\n",
583 tid, inst->seqNum, nextPC);
584 inst->setPredTarg(nextPC);
585 inst->setPredTaken(predict_taken);
593 return predict_taken;
596 template <class Impl>
598 DefaultFetch<Impl>::fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc)
600 Fault fault = NoFault;
602 assert(!cpu->switchedOut());
604 // @todo: not sure if these should block translation.
607 DPRINTF(Fetch, "[tid:%i] Can't fetch cache line, cache blocked\n",
610 } else if (checkInterrupt(pc) && !delayedCommit[tid]) {
611 // Hold off fetch from getting new instructions when:
612 // Cache is blocked, or
613 // while an interrupt is pending and we're not in PAL mode, or
614 // fetch is switched out.
615 DPRINTF(Fetch, "[tid:%i] Can't fetch cache line, interrupt pending\n",
620 // Align the fetch address to the start of a fetch buffer segment.
621 Addr fetchBufferBlockPC = fetchBufferAlignPC(vaddr);
623 DPRINTF(Fetch, "[tid:%i] Fetching cache line %#x for addr %#x\n",
624 tid, fetchBufferBlockPC, vaddr);
626 // Setup the memReq to do a read of the first instruction's address.
627 // Set the appropriate read size and flags as well.
628 // Build request here.
629 RequestPtr mem_req = std::make_shared<Request>(
630 tid, fetchBufferBlockPC, fetchBufferSize,
631 Request::INST_FETCH, cpu->instMasterId(), pc,
632 cpu->thread[tid]->contextId());
634 mem_req->taskId(cpu->taskId());
636 memReq[tid] = mem_req;
638 // Initiate translation of the icache block
639 fetchStatus[tid] = ItlbWait;
640 FetchTranslation *trans = new FetchTranslation(this);
641 cpu->itb->translateTiming(mem_req, cpu->thread[tid]->getTC(),
642 trans, BaseTLB::Execute);
646 template <class Impl>
648 DefaultFetch<Impl>::finishTranslation(const Fault &fault,
649 const RequestPtr &mem_req)
651 ThreadID tid = cpu->contextToThread(mem_req->contextId());
652 Addr fetchBufferBlockPC = mem_req->getVaddr();
654 assert(!cpu->switchedOut());
656 // Wake up CPU if it was idle
659 if (fetchStatus[tid] != ItlbWait || mem_req != memReq[tid] ||
660 mem_req->getVaddr() != memReq[tid]->getVaddr()) {
661 DPRINTF(Fetch, "[tid:%i] Ignoring itlb completed after squash\n",
668 // If translation was successful, attempt to read the icache block.
669 if (fault == NoFault) {
670 // Check that we're not going off into random memory
671 // If we have, just wait around for commit to squash something and put
672 // us on the right track
673 if (!cpu->system->isMemAddr(mem_req->getPaddr())) {
674 warn("Address %#x is outside of physical memory, stopping fetch\n",
675 mem_req->getPaddr());
676 fetchStatus[tid] = NoGoodAddr;
681 // Build packet here.
682 PacketPtr data_pkt = new Packet(mem_req, MemCmd::ReadReq);
683 data_pkt->dataDynamic(new uint8_t[fetchBufferSize]);
685 fetchBufferPC[tid] = fetchBufferBlockPC;
686 fetchBufferValid[tid] = false;
687 DPRINTF(Fetch, "Fetch: Doing instruction read.\n");
692 if (!cpu->getInstPort().sendTimingReq(data_pkt)) {
693 assert(retryPkt == NULL);
694 assert(retryTid == InvalidThreadID);
695 DPRINTF(Fetch, "[tid:%i] Out of MSHRs!\n", tid);
697 fetchStatus[tid] = IcacheWaitRetry;
702 DPRINTF(Fetch, "[tid:%i]: Doing Icache access.\n", tid);
703 DPRINTF(Activity, "[tid:%i]: Activity: Waiting on I-cache "
705 lastIcacheStall[tid] = curTick();
706 fetchStatus[tid] = IcacheWaitResponse;
707 // Notify Fetch Request probe when a packet containing a fetch
708 // request is successfully sent
709 ppFetchRequestSent->notify(mem_req);
712 // Don't send an instruction to decode if we can't handle it.
713 if (!(numInst < fetchWidth) || !(fetchQueue[tid].size() < fetchQueueSize)) {
714 assert(!finishTranslationEvent.scheduled());
715 finishTranslationEvent.setFault(fault);
716 finishTranslationEvent.setReq(mem_req);
717 cpu->schedule(finishTranslationEvent,
718 cpu->clockEdge(Cycles(1)));
721 DPRINTF(Fetch, "[tid:%i] Got back req with addr %#x but expected %#x\n",
722 tid, mem_req->getVaddr(), memReq[tid]->getVaddr());
723 // Translation faulted, icache request won't be sent.
726 // Send the fault to commit. This thread will not do anything
727 // until commit handles the fault. The only other way it can
728 // wake up is if a squash comes along and changes the PC.
729 TheISA::PCState fetchPC = pc[tid];
731 DPRINTF(Fetch, "[tid:%i]: Translation faulted, building noop.\n", tid);
732 // We will use a nop in ordier to carry the fault.
733 DynInstPtr instruction = buildInst(tid, StaticInst::nopStaticInstPtr,
734 NULL, fetchPC, fetchPC, false);
735 instruction->setNotAnInst();
737 instruction->setPredTarg(fetchPC);
738 instruction->fault = fault;
739 wroteToTimeBuffer = true;
741 DPRINTF(Activity, "Activity this cycle.\n");
742 cpu->activityThisCycle();
744 fetchStatus[tid] = TrapPending;
746 DPRINTF(Fetch, "[tid:%i]: Blocked, need to handle the trap.\n", tid);
747 DPRINTF(Fetch, "[tid:%i]: fault (%s) detected @ PC %s.\n",
748 tid, fault->name(), pc[tid]);
750 _status = updateFetchStatus();
753 template <class Impl>
755 DefaultFetch<Impl>::doSquash(const TheISA::PCState &newPC,
756 const DynInstPtr squashInst, ThreadID tid)
758 DPRINTF(Fetch, "[tid:%i]: Squashing, setting PC to: %s.\n",
762 fetchOffset[tid] = 0;
763 if (squashInst && squashInst->pcState().instAddr() == newPC.instAddr())
764 macroop[tid] = squashInst->macroop;
767 decoder[tid]->reset();
769 // Clear the icache miss if it's outstanding.
770 if (fetchStatus[tid] == IcacheWaitResponse) {
771 DPRINTF(Fetch, "[tid:%i]: Squashing outstanding Icache miss.\n",
774 } else if (fetchStatus[tid] == ItlbWait) {
775 DPRINTF(Fetch, "[tid:%i]: Squashing outstanding ITLB miss.\n",
780 // Get rid of the retrying packet if it was from this thread.
781 if (retryTid == tid) {
782 assert(cacheBlocked);
787 retryTid = InvalidThreadID;
790 fetchStatus[tid] = Squashing;
793 fetchQueue[tid].clear();
795 // microops are being squashed, it is not known wheather the
796 // youngest non-squashed microop was marked delayed commit
797 // or not. Setting the flag to true ensures that the
798 // interrupts are not handled when they cannot be, though
799 // some opportunities to handle interrupts may be missed.
800 delayedCommit[tid] = true;
807 DefaultFetch<Impl>::squashFromDecode(const TheISA::PCState &newPC,
808 const DynInstPtr squashInst,
809 const InstSeqNum seq_num, ThreadID tid)
811 DPRINTF(Fetch, "[tid:%i]: Squashing from decode.\n", tid);
813 doSquash(newPC, squashInst, tid);
815 // Tell the CPU to remove any instructions that are in flight between
817 cpu->removeInstsUntil(seq_num, tid);
822 DefaultFetch<Impl>::checkStall(ThreadID tid) const
824 bool ret_val = false;
826 if (stalls[tid].drain) {
827 assert(cpu->isDraining());
828 DPRINTF(Fetch,"[tid:%i]: Drain stall detected.\n",tid);
836 typename DefaultFetch<Impl>::FetchStatus
837 DefaultFetch<Impl>::updateFetchStatus()
840 list<ThreadID>::iterator threads = activeThreads->begin();
841 list<ThreadID>::iterator end = activeThreads->end();
843 while (threads != end) {
844 ThreadID tid = *threads++;
846 if (fetchStatus[tid] == Running ||
847 fetchStatus[tid] == Squashing ||
848 fetchStatus[tid] == IcacheAccessComplete) {
850 if (_status == Inactive) {
851 DPRINTF(Activity, "[tid:%i]: Activating stage.\n",tid);
853 if (fetchStatus[tid] == IcacheAccessComplete) {
854 DPRINTF(Activity, "[tid:%i]: Activating fetch due to cache"
858 cpu->activateStage(O3CPU::FetchIdx);
865 // Stage is switching from active to inactive, notify CPU of it.
866 if (_status == Active) {
867 DPRINTF(Activity, "Deactivating stage.\n");
869 cpu->deactivateStage(O3CPU::FetchIdx);
875 template <class Impl>
877 DefaultFetch<Impl>::squash(const TheISA::PCState &newPC,
878 const InstSeqNum seq_num, DynInstPtr squashInst,
881 DPRINTF(Fetch, "[tid:%u]: Squash from commit.\n", tid);
883 doSquash(newPC, squashInst, tid);
885 // Tell the CPU to remove any instructions that are not in the ROB.
886 cpu->removeInstsNotInROB(tid);
889 template <class Impl>
891 DefaultFetch<Impl>::tick()
893 list<ThreadID>::iterator threads = activeThreads->begin();
894 list<ThreadID>::iterator end = activeThreads->end();
895 bool status_change = false;
897 wroteToTimeBuffer = false;
899 for (ThreadID i = 0; i < numThreads; ++i) {
900 issuePipelinedIfetch[i] = false;
903 while (threads != end) {
904 ThreadID tid = *threads++;
906 // Check the signals for each thread to determine the proper status
908 bool updated_status = checkSignalsAndUpdate(tid);
909 status_change = status_change || updated_status;
912 DPRINTF(Fetch, "Running stage.\n");
915 if (fromCommit->commitInfo[0].interruptPending) {
916 interruptPending = true;
919 if (fromCommit->commitInfo[0].clearInterrupt) {
920 interruptPending = false;
924 for (threadFetched = 0; threadFetched < numFetchingThreads;
926 // Fetch each of the actively fetching threads.
927 fetch(status_change);
930 // Record number of instructions fetched this cycle for distribution.
931 fetchNisnDist.sample(numInst);
934 // Change the fetch stage status if there was a status change.
935 _status = updateFetchStatus();
938 // Issue the next I-cache request if possible.
939 for (ThreadID i = 0; i < numThreads; ++i) {
940 if (issuePipelinedIfetch[i]) {
941 pipelineIcacheAccesses(i);
945 // Send instructions enqueued into the fetch queue to decode.
946 // Limit rate by fetchWidth. Stall if decode is stalled.
947 unsigned insts_to_decode = 0;
948 unsigned available_insts = 0;
950 for (auto tid : *activeThreads) {
951 if (!stalls[tid].decode) {
952 available_insts += fetchQueue[tid].size();
956 // Pick a random thread to start trying to grab instructions from
957 auto tid_itr = activeThreads->begin();
958 std::advance(tid_itr, random_mt.random<uint8_t>(0, activeThreads->size() - 1));
960 while (available_insts != 0 && insts_to_decode < decodeWidth) {
961 ThreadID tid = *tid_itr;
962 if (!stalls[tid].decode && !fetchQueue[tid].empty()) {
963 const auto& inst = fetchQueue[tid].front();
964 toDecode->insts[toDecode->size++] = inst;
965 DPRINTF(Fetch, "[tid:%i][sn:%i]: Sending instruction to decode from "
966 "fetch queue. Fetch queue size: %i.\n",
967 tid, inst->seqNum, fetchQueue[tid].size());
969 wroteToTimeBuffer = true;
970 fetchQueue[tid].pop_front();
976 // Wrap around if at end of active threads list
977 if (tid_itr == activeThreads->end())
978 tid_itr = activeThreads->begin();
981 // If there was activity this cycle, inform the CPU of it.
982 if (wroteToTimeBuffer) {
983 DPRINTF(Activity, "Activity this cycle.\n");
984 cpu->activityThisCycle();
987 // Reset the number of the instruction we've fetched.
991 template <class Impl>
993 DefaultFetch<Impl>::checkSignalsAndUpdate(ThreadID tid)
995 // Update the per thread stall statuses.
996 if (fromDecode->decodeBlock[tid]) {
997 stalls[tid].decode = true;
1000 if (fromDecode->decodeUnblock[tid]) {
1001 assert(stalls[tid].decode);
1002 assert(!fromDecode->decodeBlock[tid]);
1003 stalls[tid].decode = false;
1006 // Check squash signals from commit.
1007 if (fromCommit->commitInfo[tid].squash) {
1009 DPRINTF(Fetch, "[tid:%u]: Squashing instructions due to squash "
1010 "from commit.\n",tid);
1011 // In any case, squash.
1012 squash(fromCommit->commitInfo[tid].pc,
1013 fromCommit->commitInfo[tid].doneSeqNum,
1014 fromCommit->commitInfo[tid].squashInst, tid);
1016 // If it was a branch mispredict on a control instruction, update the
1017 // branch predictor with that instruction, otherwise just kill the
1018 // invalid state we generated in after sequence number
1019 if (fromCommit->commitInfo[tid].mispredictInst &&
1020 fromCommit->commitInfo[tid].mispredictInst->isControl()) {
1021 branchPred->squash(fromCommit->commitInfo[tid].doneSeqNum,
1022 fromCommit->commitInfo[tid].pc,
1023 fromCommit->commitInfo[tid].branchTaken,
1026 branchPred->squash(fromCommit->commitInfo[tid].doneSeqNum,
1031 } else if (fromCommit->commitInfo[tid].doneSeqNum) {
1032 // Update the branch predictor if it wasn't a squashed instruction
1033 // that was broadcasted.
1034 branchPred->update(fromCommit->commitInfo[tid].doneSeqNum, tid);
1037 // Check squash signals from decode.
1038 if (fromDecode->decodeInfo[tid].squash) {
1039 DPRINTF(Fetch, "[tid:%u]: Squashing instructions due to squash "
1040 "from decode.\n",tid);
1042 // Update the branch predictor.
1043 if (fromDecode->decodeInfo[tid].branchMispredict) {
1044 branchPred->squash(fromDecode->decodeInfo[tid].doneSeqNum,
1045 fromDecode->decodeInfo[tid].nextPC,
1046 fromDecode->decodeInfo[tid].branchTaken,
1049 branchPred->squash(fromDecode->decodeInfo[tid].doneSeqNum,
1053 if (fetchStatus[tid] != Squashing) {
1055 DPRINTF(Fetch, "Squashing from decode with PC = %s\n",
1056 fromDecode->decodeInfo[tid].nextPC);
1057 // Squash unless we're already squashing
1058 squashFromDecode(fromDecode->decodeInfo[tid].nextPC,
1059 fromDecode->decodeInfo[tid].squashInst,
1060 fromDecode->decodeInfo[tid].doneSeqNum,
1067 if (checkStall(tid) &&
1068 fetchStatus[tid] != IcacheWaitResponse &&
1069 fetchStatus[tid] != IcacheWaitRetry &&
1070 fetchStatus[tid] != ItlbWait &&
1071 fetchStatus[tid] != QuiescePending) {
1072 DPRINTF(Fetch, "[tid:%i]: Setting to blocked\n",tid);
1074 fetchStatus[tid] = Blocked;
1079 if (fetchStatus[tid] == Blocked ||
1080 fetchStatus[tid] == Squashing) {
1081 // Switch status to running if fetch isn't being told to block or
1082 // squash this cycle.
1083 DPRINTF(Fetch, "[tid:%i]: Done squashing, switching to running.\n",
1086 fetchStatus[tid] = Running;
1091 // If we've reached this point, we have not gotten any signals that
1092 // cause fetch to change its status. Fetch remains the same as before.
1096 template<class Impl>
1097 typename Impl::DynInstPtr
1098 DefaultFetch<Impl>::buildInst(ThreadID tid, StaticInstPtr staticInst,
1099 StaticInstPtr curMacroop, TheISA::PCState thisPC,
1100 TheISA::PCState nextPC, bool trace)
1102 // Get a sequence number.
1103 InstSeqNum seq = cpu->getAndIncrementInstSeq();
1105 // Create a new DynInst from the instruction fetched.
1106 DynInstPtr instruction =
1107 new DynInst(staticInst, curMacroop, thisPC, nextPC, seq, cpu);
1108 instruction->setTid(tid);
1110 instruction->setASID(tid);
1112 instruction->setThreadState(cpu->thread[tid]);
1114 DPRINTF(Fetch, "[tid:%i]: Instruction PC %#x (%d) created "
1115 "[sn:%lli].\n", tid, thisPC.instAddr(),
1116 thisPC.microPC(), seq);
1118 DPRINTF(Fetch, "[tid:%i]: Instruction is: %s\n", tid,
1119 instruction->staticInst->
1120 disassemble(thisPC.instAddr()));
1124 instruction->traceData =
1125 cpu->getTracer()->getInstRecord(curTick(), cpu->tcBase(tid),
1126 instruction->staticInst, thisPC, curMacroop);
1129 instruction->traceData = NULL;
1132 // Add instruction to the CPU's list of instructions.
1133 instruction->setInstListIt(cpu->addInst(instruction));
1135 // Write the instruction to the first slot in the queue
1136 // that heads to decode.
1137 assert(numInst < fetchWidth);
1138 fetchQueue[tid].push_back(instruction);
1139 assert(fetchQueue[tid].size() <= fetchQueueSize);
1140 DPRINTF(Fetch, "[tid:%i]: Fetch queue entry created (%i/%i).\n",
1141 tid, fetchQueue[tid].size(), fetchQueueSize);
1142 //toDecode->insts[toDecode->size++] = instruction;
1144 // Keep track of if we can take an interrupt at this boundary
1145 delayedCommit[tid] = instruction->isDelayedCommit();
1150 template<class Impl>
1152 DefaultFetch<Impl>::fetch(bool &status_change)
1154 //////////////////////////////////////////
1155 // Start actual fetch
1156 //////////////////////////////////////////
1157 ThreadID tid = getFetchingThread();
1159 assert(!cpu->switchedOut());
1161 if (tid == InvalidThreadID) {
1162 // Breaks looping condition in tick()
1163 threadFetched = numFetchingThreads;
1165 if (numThreads == 1) { // @todo Per-thread stats
1172 DPRINTF(Fetch, "Attempting to fetch from [tid:%i]\n", tid);
1175 TheISA::PCState thisPC = pc[tid];
1177 Addr pcOffset = fetchOffset[tid];
1178 Addr fetchAddr = (thisPC.instAddr() + pcOffset) & BaseCPU::PCMask;
1180 bool inRom = isRomMicroPC(thisPC.microPC());
1182 // If returning from the delay of a cache miss, then update the status
1183 // to running, otherwise do the cache access. Possibly move this up
1184 // to tick() function.
1185 if (fetchStatus[tid] == IcacheAccessComplete) {
1186 DPRINTF(Fetch, "[tid:%i]: Icache miss is complete.\n", tid);
1188 fetchStatus[tid] = Running;
1189 status_change = true;
1190 } else if (fetchStatus[tid] == Running) {
1191 // Align the fetch PC so its at the start of a fetch buffer segment.
1192 Addr fetchBufferBlockPC = fetchBufferAlignPC(fetchAddr);
1194 // If buffer is no longer valid or fetchAddr has moved to point
1195 // to the next cache block, AND we have no remaining ucode
1196 // from a macro-op, then start fetch from icache.
1197 if (!(fetchBufferValid[tid] && fetchBufferBlockPC == fetchBufferPC[tid])
1198 && !inRom && !macroop[tid]) {
1199 DPRINTF(Fetch, "[tid:%i]: Attempting to translate and read "
1200 "instruction, starting at PC %s.\n", tid, thisPC);
1202 fetchCacheLine(fetchAddr, tid, thisPC.instAddr());
1204 if (fetchStatus[tid] == IcacheWaitResponse)
1205 ++icacheStallCycles;
1206 else if (fetchStatus[tid] == ItlbWait)
1209 ++fetchMiscStallCycles;
1211 } else if ((checkInterrupt(thisPC.instAddr()) && !delayedCommit[tid])) {
1212 // Stall CPU if an interrupt is posted and we're not issuing
1213 // an delayed commit micro-op currently (delayed commit instructions
1214 // are not interruptable by interrupts, only faults)
1215 ++fetchMiscStallCycles;
1216 DPRINTF(Fetch, "[tid:%i]: Fetch is stalled!\n", tid);
1220 if (fetchStatus[tid] == Idle) {
1222 DPRINTF(Fetch, "[tid:%i]: Fetch is idle!\n", tid);
1225 // Status is Idle, so fetch should do nothing.
1231 TheISA::PCState nextPC = thisPC;
1233 StaticInstPtr staticInst = NULL;
1234 StaticInstPtr curMacroop = macroop[tid];
1236 // If the read of the first instruction was successful, then grab the
1237 // instructions from the rest of the cache line and put them into the
1238 // queue heading to decode.
1240 DPRINTF(Fetch, "[tid:%i]: Adding instructions to queue to "
1243 // Need to keep track of whether or not a predicted branch
1244 // ended this fetch block.
1245 bool predictedBranch = false;
1247 // Need to halt fetch if quiesce instruction detected
1248 bool quiesce = false;
1250 TheISA::MachInst *cacheInsts =
1251 reinterpret_cast<TheISA::MachInst *>(fetchBuffer[tid]);
1253 const unsigned numInsts = fetchBufferSize / instSize;
1254 unsigned blkOffset = (fetchAddr - fetchBufferPC[tid]) / instSize;
1256 // Loop through instruction memory from the cache.
1257 // Keep issuing while fetchWidth is available and branch is not
1259 while (numInst < fetchWidth && fetchQueue[tid].size() < fetchQueueSize
1260 && !predictedBranch && !quiesce) {
1261 // We need to process more memory if we aren't going to get a
1262 // StaticInst from the rom, the current macroop, or what's already
1264 bool needMem = !inRom && !curMacroop &&
1265 !decoder[tid]->instReady();
1266 fetchAddr = (thisPC.instAddr() + pcOffset) & BaseCPU::PCMask;
1267 Addr fetchBufferBlockPC = fetchBufferAlignPC(fetchAddr);
1270 // If buffer is no longer valid or fetchAddr has moved to point
1271 // to the next cache block then start fetch from icache.
1272 if (!fetchBufferValid[tid] ||
1273 fetchBufferBlockPC != fetchBufferPC[tid])
1276 if (blkOffset >= numInsts) {
1277 // We need to process more memory, but we've run out of the
1282 MachInst inst = TheISA::gtoh(cacheInsts[blkOffset]);
1283 decoder[tid]->moreBytes(thisPC, fetchAddr, inst);
1285 if (decoder[tid]->needMoreBytes()) {
1287 fetchAddr += instSize;
1288 pcOffset += instSize;
1292 // Extract as many instructions and/or microops as we can from
1293 // the memory we've processed so far.
1295 if (!(curMacroop || inRom)) {
1296 if (decoder[tid]->instReady()) {
1297 staticInst = decoder[tid]->decode(thisPC);
1299 // Increment stat of fetched instructions.
1302 if (staticInst->isMacroop()) {
1303 curMacroop = staticInst;
1308 // We need more bytes for this instruction so blkOffset and
1309 // pcOffset will be updated
1313 // Whether we're moving to a new macroop because we're at the
1314 // end of the current one, or the branch predictor incorrectly
1316 bool newMacro = false;
1317 if (curMacroop || inRom) {
1319 staticInst = cpu->microcodeRom.fetchMicroop(
1320 thisPC.microPC(), curMacroop);
1322 staticInst = curMacroop->fetchMicroop(thisPC.microPC());
1324 newMacro |= staticInst->isLastMicroop();
1327 DynInstPtr instruction =
1328 buildInst(tid, staticInst, curMacroop,
1329 thisPC, nextPC, true);
1331 ppFetch->notify(instruction);
1335 if (DTRACE(O3PipeView)) {
1336 instruction->fetchTick = curTick();
1342 // If we're branching after this instruction, quit fetching
1343 // from the same block.
1344 predictedBranch |= thisPC.branching();
1346 lookupAndUpdateNextPC(instruction, nextPC);
1347 if (predictedBranch) {
1348 DPRINTF(Fetch, "Branch detected with PC = %s\n", thisPC);
1351 newMacro |= thisPC.instAddr() != nextPC.instAddr();
1353 // Move to the next instruction, unless we have a branch.
1355 inRom = isRomMicroPC(thisPC.microPC());
1358 fetchAddr = thisPC.instAddr() & BaseCPU::PCMask;
1359 blkOffset = (fetchAddr - fetchBufferPC[tid]) / instSize;
1364 if (instruction->isQuiesce()) {
1366 "Quiesce instruction encountered, halting fetch!\n");
1367 fetchStatus[tid] = QuiescePending;
1368 status_change = true;
1372 } while ((curMacroop || decoder[tid]->instReady()) &&
1373 numInst < fetchWidth &&
1374 fetchQueue[tid].size() < fetchQueueSize);
1376 // Re-evaluate whether the next instruction to fetch is in micro-op ROM
1378 inRom = isRomMicroPC(thisPC.microPC());
1381 if (predictedBranch) {
1382 DPRINTF(Fetch, "[tid:%i]: Done fetching, predicted branch "
1383 "instruction encountered.\n", tid);
1384 } else if (numInst >= fetchWidth) {
1385 DPRINTF(Fetch, "[tid:%i]: Done fetching, reached fetch bandwidth "
1386 "for this cycle.\n", tid);
1387 } else if (blkOffset >= fetchBufferSize) {
1388 DPRINTF(Fetch, "[tid:%i]: Done fetching, reached the end of the"
1389 "fetch buffer.\n", tid);
1392 macroop[tid] = curMacroop;
1393 fetchOffset[tid] = pcOffset;
1396 wroteToTimeBuffer = true;
1401 // pipeline a fetch if we're crossing a fetch buffer boundary and not in
1402 // a state that would preclude fetching
1403 fetchAddr = (thisPC.instAddr() + pcOffset) & BaseCPU::PCMask;
1404 Addr fetchBufferBlockPC = fetchBufferAlignPC(fetchAddr);
1405 issuePipelinedIfetch[tid] = fetchBufferBlockPC != fetchBufferPC[tid] &&
1406 fetchStatus[tid] != IcacheWaitResponse &&
1407 fetchStatus[tid] != ItlbWait &&
1408 fetchStatus[tid] != IcacheWaitRetry &&
1409 fetchStatus[tid] != QuiescePending &&
1413 template<class Impl>
1415 DefaultFetch<Impl>::recvReqRetry()
1417 if (retryPkt != NULL) {
1418 assert(cacheBlocked);
1419 assert(retryTid != InvalidThreadID);
1420 assert(fetchStatus[retryTid] == IcacheWaitRetry);
1422 if (cpu->getInstPort().sendTimingReq(retryPkt)) {
1423 fetchStatus[retryTid] = IcacheWaitResponse;
1424 // Notify Fetch Request probe when a retryPkt is successfully sent.
1425 // Note that notify must be called before retryPkt is set to NULL.
1426 ppFetchRequestSent->notify(retryPkt->req);
1428 retryTid = InvalidThreadID;
1429 cacheBlocked = false;
1432 assert(retryTid == InvalidThreadID);
1433 // Access has been squashed since it was sent out. Just clear
1434 // the cache being blocked.
1435 cacheBlocked = false;
1439 ///////////////////////////////////////
1441 // SMT FETCH POLICY MAINTAINED HERE //
1443 ///////////////////////////////////////
1444 template<class Impl>
1446 DefaultFetch<Impl>::getFetchingThread()
1448 if (numThreads > 1) {
1449 switch (fetchPolicy) {
1450 case FetchPolicy::RoundRobin:
1451 return roundRobin();
1452 case FetchPolicy::IQCount:
1454 case FetchPolicy::LSQCount:
1456 case FetchPolicy::Branch:
1457 return branchCount();
1459 return InvalidThreadID;
1462 list<ThreadID>::iterator thread = activeThreads->begin();
1463 if (thread == activeThreads->end()) {
1464 return InvalidThreadID;
1467 ThreadID tid = *thread;
1469 if (fetchStatus[tid] == Running ||
1470 fetchStatus[tid] == IcacheAccessComplete ||
1471 fetchStatus[tid] == Idle) {
1474 return InvalidThreadID;
1480 template<class Impl>
1482 DefaultFetch<Impl>::roundRobin()
1484 list<ThreadID>::iterator pri_iter = priorityList.begin();
1485 list<ThreadID>::iterator end = priorityList.end();
1489 while (pri_iter != end) {
1490 high_pri = *pri_iter;
1492 assert(high_pri <= numThreads);
1494 if (fetchStatus[high_pri] == Running ||
1495 fetchStatus[high_pri] == IcacheAccessComplete ||
1496 fetchStatus[high_pri] == Idle) {
1498 priorityList.erase(pri_iter);
1499 priorityList.push_back(high_pri);
1507 return InvalidThreadID;
1510 template<class Impl>
1512 DefaultFetch<Impl>::iqCount()
1514 //sorted from lowest->highest
1515 std::priority_queue<unsigned,vector<unsigned>,
1516 std::greater<unsigned> > PQ;
1517 std::map<unsigned, ThreadID> threadMap;
1519 list<ThreadID>::iterator threads = activeThreads->begin();
1520 list<ThreadID>::iterator end = activeThreads->end();
1522 while (threads != end) {
1523 ThreadID tid = *threads++;
1524 unsigned iqCount = fromIEW->iewInfo[tid].iqCount;
1526 //we can potentially get tid collisions if two threads
1527 //have the same iqCount, but this should be rare.
1529 threadMap[iqCount] = tid;
1532 while (!PQ.empty()) {
1533 ThreadID high_pri = threadMap[PQ.top()];
1535 if (fetchStatus[high_pri] == Running ||
1536 fetchStatus[high_pri] == IcacheAccessComplete ||
1537 fetchStatus[high_pri] == Idle)
1544 return InvalidThreadID;
1547 template<class Impl>
1549 DefaultFetch<Impl>::lsqCount()
1551 //sorted from lowest->highest
1552 std::priority_queue<unsigned,vector<unsigned>,
1553 std::greater<unsigned> > PQ;
1554 std::map<unsigned, ThreadID> threadMap;
1556 list<ThreadID>::iterator threads = activeThreads->begin();
1557 list<ThreadID>::iterator end = activeThreads->end();
1559 while (threads != end) {
1560 ThreadID tid = *threads++;
1561 unsigned ldstqCount = fromIEW->iewInfo[tid].ldstqCount;
1563 //we can potentially get tid collisions if two threads
1564 //have the same iqCount, but this should be rare.
1565 PQ.push(ldstqCount);
1566 threadMap[ldstqCount] = tid;
1569 while (!PQ.empty()) {
1570 ThreadID high_pri = threadMap[PQ.top()];
1572 if (fetchStatus[high_pri] == Running ||
1573 fetchStatus[high_pri] == IcacheAccessComplete ||
1574 fetchStatus[high_pri] == Idle)
1580 return InvalidThreadID;
1583 template<class Impl>
1585 DefaultFetch<Impl>::branchCount()
1588 list<ThreadID>::iterator thread = activeThreads->begin();
1589 assert(thread != activeThreads->end());
1590 ThreadID tid = *thread;
1593 panic("Branch Count Fetch policy unimplemented\n");
1594 return InvalidThreadID;
1597 template<class Impl>
1599 DefaultFetch<Impl>::pipelineIcacheAccesses(ThreadID tid)
1601 if (!issuePipelinedIfetch[tid]) {
1605 // The next PC to access.
1606 TheISA::PCState thisPC = pc[tid];
1608 if (isRomMicroPC(thisPC.microPC())) {
1612 Addr pcOffset = fetchOffset[tid];
1613 Addr fetchAddr = (thisPC.instAddr() + pcOffset) & BaseCPU::PCMask;
1615 // Align the fetch PC so its at the start of a fetch buffer segment.
1616 Addr fetchBufferBlockPC = fetchBufferAlignPC(fetchAddr);
1618 // Unless buffer already got the block, fetch it from icache.
1619 if (!(fetchBufferValid[tid] && fetchBufferBlockPC == fetchBufferPC[tid])) {
1620 DPRINTF(Fetch, "[tid:%i]: Issuing a pipelined I-cache access, "
1621 "starting at PC %s.\n", tid, thisPC);
1623 fetchCacheLine(fetchAddr, tid, thisPC.instAddr());
1627 template<class Impl>
1629 DefaultFetch<Impl>::profileStall(ThreadID tid) {
1630 DPRINTF(Fetch,"There are no more threads available to fetch from.\n");
1632 // @todo Per-thread stats
1634 if (stalls[tid].drain) {
1635 ++fetchPendingDrainCycles;
1636 DPRINTF(Fetch, "Fetch is waiting for a drain!\n");
1637 } else if (activeThreads->empty()) {
1638 ++fetchNoActiveThreadStallCycles;
1639 DPRINTF(Fetch, "Fetch has no active thread!\n");
1640 } else if (fetchStatus[tid] == Blocked) {
1641 ++fetchBlockedCycles;
1642 DPRINTF(Fetch, "[tid:%i]: Fetch is blocked!\n", tid);
1643 } else if (fetchStatus[tid] == Squashing) {
1644 ++fetchSquashCycles;
1645 DPRINTF(Fetch, "[tid:%i]: Fetch is squashing!\n", tid);
1646 } else if (fetchStatus[tid] == IcacheWaitResponse) {
1647 ++icacheStallCycles;
1648 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting cache response!\n",
1650 } else if (fetchStatus[tid] == ItlbWait) {
1652 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting ITLB walk to "
1654 } else if (fetchStatus[tid] == TrapPending) {
1655 ++fetchPendingTrapStallCycles;
1656 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting for a pending trap!\n",
1658 } else if (fetchStatus[tid] == QuiescePending) {
1659 ++fetchPendingQuiesceStallCycles;
1660 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting for a pending quiesce "
1661 "instruction!\n", tid);
1662 } else if (fetchStatus[tid] == IcacheWaitRetry) {
1663 ++fetchIcacheWaitRetryStallCycles;
1664 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting for an I-cache retry!\n",
1666 } else if (fetchStatus[tid] == NoGoodAddr) {
1667 DPRINTF(Fetch, "[tid:%i]: Fetch predicted non-executable address\n",
1670 DPRINTF(Fetch, "[tid:%i]: Unexpected fetch stall reason (Status: %i).\n",
1671 tid, fetchStatus[tid]);
1675 #endif//__CPU_O3_FETCH_IMPL_HH__