gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
fetch.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2012, 2014 ARM Limited
3 * Copyright (c) 2022-2023 The University of Edinburgh
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#ifndef __CPU_O3_FETCH_HH__
43#define __CPU_O3_FETCH_HH__
44
46#include "arch/generic/mmu.hh"
47#include "base/random.hh"
48#include "base/statistics.hh"
49#include "cpu/o3/bac.hh"
50#include "cpu/o3/comm.hh"
52#include "cpu/o3/ftq.hh"
53#include "cpu/o3/limits.hh"
54#include "cpu/pc_event.hh"
56#include "cpu/timebuf.hh"
57#include "cpu/translation.hh"
58#include "enums/SMTFetchPolicy.hh"
59#include "mem/packet.hh"
60#include "mem/port.hh"
61#include "sim/eventq.hh"
62#include "sim/probe/probe.hh"
63
64namespace gem5
65{
66
67struct BaseO3CPUParams;
68
69namespace o3
70{
71
72class CPU;
73
82class Fetch
83{
84 public:
88 class IcachePort : public RequestPort
89 {
90 protected:
93
94 public:
96 IcachePort(Fetch *_fetch, CPU *_cpu);
97
98 protected:
99
102 virtual bool recvTimingResp(PacketPtr pkt);
103
105 virtual void recvReqRetry();
106 };
107
109 {
110 protected:
112
113 public:
114 FetchTranslation(Fetch *_fetch) : fetch(_fetch) {}
115
116 void markDelayed() {}
117
118 void
119 finish(const Fault &fault, const RequestPtr &req,
121 {
122 assert(mode == BaseMMU::Execute);
123 fetch->finishTranslation(fault, req);
124 delete this;
125 }
126 };
127
128 private:
129 /* Event to delay delivery of a fetch translation result in case of
130 * a fault and the nop to carry the fault cannot be generated
131 * immediately */
133 {
134 private:
138
139 public:
141 : fetch(_fetch), req(nullptr)
142 {}
143
144 void setFault(Fault _fault) { fault = _fault; }
145 void setReq(const RequestPtr &_req) { req = _req; }
146
148 void
150 {
151 assert(fetch->numInst < fetch->fetchWidth);
152 fetch->finishTranslation(fault, req);
153 }
154
155 const char *
157 {
158 return "CPU FetchFinishTranslation";
159 }
160 };
161
162 public:
171
189
190 private:
193
196
198 SMTFetchPolicy fetchPolicy;
199
202
207
209
210 public:
212 Fetch(CPU *_cpu, const BaseO3CPUParams &params);
213
215 std::string name() const;
216
217
219 void regProbePoints();
220
222 void setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer);
223
226
229
231 void setBACandFTQPtr(BAC *bac_ptr, FTQ *ftq_ptr);
232
234 void startupStage();
235
237 void clearStates(ThreadID tid);
238
240 void recvReqRetry();
241
244
246 void drainResume();
247
249 void drainSanityCheck() const;
250
252 bool isDrained() const;
253
255 void takeOverFrom();
256
266 void drainStall(ThreadID tid);
267
269 void wakeFromQuiesce();
270
272 void deactivateThread(ThreadID tid);
273 private:
275 void resetStage();
276
280 void switchToActive();
281
285 void switchToInactive();
286
299 void finishTranslation(const Fault &fault, const RequestPtr &mem_req);
300
301
305
307 void doSquash(const PCStateBase &new_pc, const DynInstPtr squashInst,
308 ThreadID tid);
309
314 void squashFromDecode(const PCStateBase &new_pc,
315 const DynInstPtr squashInst,
316 const InstSeqNum seq_num, ThreadID tid);
317
319 void bacResteer(const PCStateBase &new_pc, ThreadID tid);
320
322 bool checkStall(ThreadID tid) const;
323
325 bool ftqReady(ThreadID tid, bool &status_change);
326
330
331 public:
336 void squashFromCommit(const PCStateBase &new_pc, const InstSeqNum seq_num,
337 DynInstPtr squashInst, ThreadID tid);
338
342 void tick();
343
348
354 void fetch(bool &status_change);
355
358 {
359 return (addr & ~(fetchBufferMask));
360 }
361
364
366
367 private:
369 StaticInstPtr curMacroop, const PCStateBase &this_pc,
370 const PCStateBase &next_pc, bool trace);
371
374
377
380
383
387
390
392 void profileStall(ThreadID tid);
393
394 private:
397
400
403
406
409
412
415
416 //Might be annoying how this name is different than the queue.
419
422
425
426 std::unique_ptr<PCStateBase> pc[MaxThreads];
427
429
431
434
437
442
445
447 struct Stalls
448 {
449 bool decode;
450 bool drain;
451 };
452
455
458
461
464
467
470
472 const unsigned fetchWidth;
473
475 const unsigned decodeWidth;
476
479
482
485
488
493
496
499
502
505
508
511
514
517
520
523
526
529
534
537
540
543
544 /*Max number of FT added to the FTQ per Cycle*/
545 const unsigned maxFTPerCycle;
546 const unsigned maxTakenPredPerCycle;
547
548 protected:
601};
602
603} // namespace o3
604} // namespace gem5
605
606#endif //__CPU_O3_FETCH_HH__
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
Event(Priority p=Default_Pri, Flags f=0)
Definition eventq.hh:407
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:273
static RandomPtr genRandom(Random *r=nullptr)
Definition random.hh:68
std::shared_ptr< Random > RandomPtr
Definition random.hh:65
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
RequestPort(const std::string &name, SimObject *_owner, PortID id=InvalidPortID)
Request port.
Definition port.cc:125
ThreadContext is the external interface to all thread state for anything outside of the CPU.
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:97
FTQ class.
Definition ftq.hh:227
void finish(const Fault &fault, const RequestPtr &req, gem5::ThreadContext *tc, BaseMMU::Mode mode)
Definition fetch.hh:119
void markDelayed()
Signal that the translation has been delayed due to a hw page table walk.
Definition fetch.hh:116
FetchTranslation(Fetch *_fetch)
Definition fetch.hh:114
const char * description() const
Return a C string describing the event.
Definition fetch.hh:156
void setReq(const RequestPtr &_req)
Definition fetch.hh:145
void process()
Process the delayed finish translation.
Definition fetch.hh:149
IcachePort class for instruction fetch.
Definition fetch.hh:89
Fetch * fetch
Pointer to fetch.
Definition fetch.hh:92
virtual bool recvTimingResp(PacketPtr pkt)
Timing version of receive.
Definition fetch.cc:1659
IcachePort(Fetch *_fetch, CPU *_cpu)
Default constructor.
Definition fetch.cc:77
virtual void recvReqRetry()
Handles doing a retry of a failed fetch.
Definition fetch.cc:1671
gem5::o3::Fetch::FetchStatGroup fetchStats
bool wroteToTimeBuffer
Variable that tracks if fetch has written to the time buffer this cycle.
Definition fetch.hh:441
void deactivateThread(ThreadID tid)
For priority-based fetch policies, need to keep update priorityList.
Definition fetch.cc:507
FetchStatus
Overall fetch status.
Definition fetch.hh:167
std::list< ThreadID > * activeThreads
List of Active Threads.
Definition fetch.hh:519
TimeBuffer< TimeStruct >::wire fromCommit
Wire to get commit's information from backwards time buffer.
Definition fetch.hh:411
StaticInstPtr macroop[MaxThreads]
Definition fetch.hh:430
void fetch(bool &status_change)
Does the actual fetching of instructions and passing them on to the next stage.
Definition fetch.cc:1062
const Cycles renameToFetchDelay
Rename to fetch delay.
Definition fetch.hh:463
void takeOverFrom()
Takes over from another CPU's thread.
Definition fetch.cc:457
uint8_t * fetchBuffer[MaxThreads]
The fetch data that is being fetched and buffered.
Definition fetch.hh:498
void doSquash(const PCStateBase &new_pc, const DynInstPtr squashInst, ThreadID tid)
Squashes a specific thread and resets the PC.
Definition fetch.cc:714
Random::RandomPtr rng
Definition fetch.hh:208
TimeBuffer< FetchStruct >::wire toDecode
Wire used to write any information heading to decode.
Definition fetch.hh:418
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
Definition fetch.cc:266
bool ftqReady(ThreadID tid, bool &status_change)
Checks if the FTQ is ready.
Definition fetch.cc:517
ThreadStatus fetchStatus[MaxThreads]
Per-thread status.
Definition fetch.hh:195
void squashFromCommit(const PCStateBase &new_pc, const InstSeqNum seq_num, DynInstPtr squashInst, ThreadID tid)
Squashes a specific thread and resets the PC.
Definition fetch.cc:702
ThreadID numThreads
Number of threads.
Definition fetch.hh:522
TimeBuffer< TimeStruct >::wire fromDecode
Wire to get decode's information from backwards time buffer.
Definition fetch.hh:402
ProbePointArg< DynInstPtr > * ppFetch
Probe points.
Definition fetch.hh:204
const unsigned maxFTPerCycle
Definition fetch.hh:545
const unsigned decodeWidth
The width of decode in instructions.
Definition fetch.hh:475
TimeBuffer< TimeStruct >::wire fromRename
Wire to get rename's information from backwards time buffer.
Definition fetch.hh:405
const Cycles commitToFetchDelay
Commit to fetch delay.
Definition fetch.hh:469
void squashFromDecode(const PCStateBase &new_pc, const DynInstPtr squashInst, const InstSeqNum seq_num, ThreadID tid)
Squashes a specific thread and resets the PC.
Definition fetch.cc:689
const bool decoupledFrontEnd
Enables the decoupled front-end.
Definition fetch.hh:457
FetchStatus updateFetchStatus()
Updates overall fetch stage status; to be called at the end of each cycle.
Definition fetch.cc:791
ThreadID getFetchingThread()
Returns the appropriate thread to fetch, given the fetch policy.
Definition fetch.cc:1443
bool fetchBufferValid[MaxThreads]
Whether or not the fetch buffer data is valid.
Definition fetch.hh:510
void startupStage()
Initialize stage.
Definition fetch.cc:287
void pipelineIcacheAccesses(ThreadID tid)
Pipeline the next I-cache access to the current one.
Definition fetch.cc:1577
std::string name() const
Returns the name of fetch.
Definition fetch.cc:152
void wakeFromQuiesce()
Tells fetch to wake up from a quiesce instruction.
Definition fetch.cc:474
void switchToActive()
Changes the status of this stage to active, and indicates this to the CPU.
Definition fetch.cc:483
void switchToInactive()
Changes the status of this stage to inactive, and indicates this to the CPU.
Definition fetch.cc:495
int numInst
Tracks how many instructions has been fetched this cycle.
Definition fetch.hh:444
const unsigned fetchWidth
The width of fetch in instructions.
Definition fetch.hh:472
bool fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc)
Fetches the cache line that contains the fetch PC.
Definition fetch.cc:533
bool issuePipelinedIfetch[MaxThreads]
Set to true if a pipelined I-cache request should be issued.
Definition fetch.hh:539
BAC * bac
BPredict.
Definition fetch.hh:421
Addr fetchBufferAlignPC(Addr addr)
Align a PC to the start of a fetch buffer block.
Definition fetch.hh:357
FetchStatus _status
Fetch status.
Definition fetch.hh:192
const unsigned maxTakenPredPerCycle
Definition fetch.hh:546
bool delayedCommit[MaxThreads]
Can the fetch stage redirect from an interrupt on this instruction?
Definition fetch.hh:433
ThreadID threadFetched
Thread ID being fetched.
Definition fetch.hh:528
SMTFetchPolicy fetchPolicy
Fetch policy.
Definition fetch.hh:198
Addr cacheBlkSize
Cache block size.
Definition fetch.hh:487
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition fetch.cc:412
unsigned fetchQueueSize
The size of the fetch queue in micro-ops.
Definition fetch.hh:504
InstDecoder * decoder[MaxThreads]
The decoder.
Definition fetch.hh:363
TimeBuffer< TimeStruct >::wire fromIEW
Wire to get iew's information from backwards time buffer.
Definition fetch.hh:408
const Cycles decodeToFetchDelay
Decode to fetch delay.
Definition fetch.hh:460
void regProbePoints()
Registers probes.
Definition fetch.cc:155
bool checkSignalsAndUpdate(ThreadID tid)
Checks all input signals and updates the status as necessary.
Definition fetch.cc:923
const Cycles iewToFetchDelay
IEW to fetch delay.
Definition fetch.hh:466
bool checkStall(ThreadID tid) const
Checks if a thread is stalled.
Definition fetch.cc:777
void bacResteer(const PCStateBase &new_pc, ThreadID tid)
Signal BAC to redirect.
Definition fetch.cc:766
IcachePort icachePort
Instruction port.
Definition fetch.hh:536
ThreadStatus
Individual thread status.
Definition fetch.hh:174
@ IcacheAccessComplete
Definition fetch.hh:185
FTQ * ftq
Fetch Target Queue.
Definition fetch.hh:424
void setTimeBuffer(TimeBuffer< TimeStruct > *time_buffer)
Sets the main backwards communication time buffer pointer.
Definition fetch.cc:249
void processCacheCompletion(PacketPtr pkt)
Processes cache completion event.
Definition fetch.cc:360
ThreadID iqCount()
Returns the appropriate thread to fetch using the IQ count policy.
Definition fetch.cc:1507
RequestPort & getInstPort()
Definition fetch.hh:365
Addr fetchBufferMask
Mask to align a fetch address to a fetch buffer boundary.
Definition fetch.hh:495
void recvReqRetry()
Handles retrying the fetch access.
Definition fetch.cc:1406
bool checkInterrupt(Addr pc)
Check if an interrupt is pending and that we need to handle.
Definition fetch.hh:304
void resetStage()
Reset this pipeline stage.
Definition fetch.cc:326
Fetch(CPU *_cpu, const BaseO3CPUParams &params)
Fetch constructor.
Definition fetch.cc:81
void drainStall(ThreadID tid)
Stall the fetch stage after reaching a safe drain point.
Definition fetch.cc:465
Counter lastIcacheStall[MaxThreads]
Icache stall statistics.
Definition fetch.hh:516
int instSize
Size of instructions.
Definition fetch.hh:513
ProbePointArg< RequestPtr > * ppFetchRequestSent
To probe when a fetch request is successfully sent.
Definition fetch.hh:206
RequestPtr memReq[MaxThreads]
Memory request used to access cache.
Definition fetch.hh:436
TimeBuffer< TimeStruct > * timeBuffer
Time buffer interface.
Definition fetch.hh:399
void profileStall(ThreadID tid)
Profile the reasons of fetch stall.
Definition fetch.cc:1606
ThreadID roundRobin()
Returns the appropriate thread to fetch using a round robin policy.
Definition fetch.cc:1478
Addr fetchBufferPC[MaxThreads]
The PC of the first instruction loaded into the fetch buffer.
Definition fetch.hh:501
void drainResume()
Resume after a drain.
Definition fetch.cc:403
void clearStates(ThreadID tid)
Clear all thread-specific states.
Definition fetch.cc:300
void finishTranslation(const Fault &fault, const RequestPtr &mem_req)
Definition fetch.cc:582
bool interruptPending
Checks if there is an interrupt pending.
Definition fetch.hh:533
std::unique_ptr< PCStateBase > pc[MaxThreads]
Definition fetch.hh:426
ThreadID lsqCount()
Returns the appropriate thread to fetch using the LSQ count policy.
Definition fetch.cc:1539
TimeBuffer< TimeStruct >::wire toBAC
Wire used to write any information backward to BAC.
Definition fetch.hh:414
Stalls stalls[MaxThreads]
Tracks which stages are telling fetch to stall.
Definition fetch.hh:454
DynInstPtr buildInst(ThreadID tid, StaticInstPtr staticInst, StaticInstPtr curMacroop, const PCStateBase &this_pc, const PCStateBase &next_pc, bool trace)
Definition fetch.cc:1009
bool isDrained() const
Has the stage drained?
Definition fetch.cc:427
Addr fetchOffset[MaxThreads]
Definition fetch.hh:428
std::deque< DynInstPtr > fetchQueue[MaxThreads]
Queue of fetched instructions.
Definition fetch.hh:507
PacketPtr retryPkt
The packet that is waiting to be retried.
Definition fetch.hh:481
std::list< ThreadID > priorityList
List that has the threads organized by priority.
Definition fetch.hh:201
FinishTranslationEvent finishTranslationEvent
Event used to delay fault generation of translation faults.
Definition fetch.hh:542
ThreadID retryTid
The thread that is waiting on the cache to tell fetch to retry.
Definition fetch.hh:484
void tick()
Ticks the fetch stage, processing all inputs signals and fetching as many instructions as possible.
Definition fetch.cc:825
ThreadID numFetchingThreads
Number of threads that are actively fetching.
Definition fetch.hh:525
unsigned fetchBufferSize
The size of the fetch buffer in bytes.
Definition fetch.hh:492
void setFetchQueue(TimeBuffer< FetchStruct > *fq_ptr)
Sets pointer to time buffer used to communicate to the next stage.
Definition fetch.cc:280
CPU * cpu
Pointer to the O3CPU.
Definition fetch.hh:396
void setBACandFTQPtr(BAC *bac_ptr, FTQ *ftq_ptr)
Sets pointer to branch address calculation stage and FTQ.
Definition fetch.cc:272
bool cacheBlocked
Is the cache blocked?
Definition fetch.hh:478
ThreadID branchCount()
Returns the appropriate thread to fetch using the branch count policy.
Definition fetch.cc:1570
A simple distribution stat.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
STL deque class.
Definition stl.hh:44
STL list class.
Definition stl.hh:51
Port Object Declaration.
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 3 > addr
Definition types.hh:84
static constexpr int MaxThreads
Definition limits.hh:38
RefCountingPtr< DynInst > DynInstPtr
double Counter
All counters are of 64-bit values.
Definition types.hh:46
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Packet * PacketPtr
RefCountingPtr< StaticInst > StaticInstPtr
uint64_t InstSeqNum
Definition inst_seq.hh:40
Declaration of the Packet class.
Declaration of Statistics objects.
statistics::Scalar icacheSquashes
Total number of outstanding icache accesses that were dropped due to a squash.
Definition fetch.hh:589
statistics::Distribution ftNumber
Definition fetch.hh:599
statistics::Scalar pendingDrainCycles
Total number of cycles spent in waiting for drains.
Definition fetch.hh:574
statistics::Scalar cacheLines
Stat for total number of fetched cache lines.
Definition fetch.hh:585
statistics::Scalar blockedCycles
Total number of cycles spent blocked.
Definition fetch.hh:570
statistics::Scalar idleCycles
Stat for total number of cycles spent blocked due to other stages in the pipeline.
Definition fetch.hh:568
statistics::Scalar predictedBranches
Stat for total number of predicted branches.
Definition fetch.hh:555
statistics::Scalar noActiveThreadStallCycles
Total number of stall cycles caused by no active threads to run.
Definition fetch.hh:576
statistics::Scalar pendingQuiesceStallCycles
Total number of stall cycles caused by pending quiesce instructions.
Definition fetch.hh:581
statistics::Scalar icacheWaitRetryStallCycles
Total number of stall cycles caused by I-cache wait retrys.
Definition fetch.hh:583
statistics::Scalar pendingTrapStallCycles
Total number of stall cycles caused by pending traps.
Definition fetch.hh:578
statistics::Scalar cycles
Stat for total number of cycles spent fetching.
Definition fetch.hh:557
statistics::Scalar miscStallCycles
Total number of cycles spent in any other state.
Definition fetch.hh:572
statistics::Scalar tlbCycles
Stat for total number of cycles spent waiting for translation.
Definition fetch.hh:561
statistics::Scalar ftqStallCycles
Stat for total number of cycles spent waiting for FTQ to fill.
Definition fetch.hh:563
statistics::Scalar squashCycles
Stat for total number of cycles spent squashing.
Definition fetch.hh:559
FetchStatGroup(CPU *cpu, Fetch *fetch)
Definition fetch.cc:163
statistics::Formula idleRate
Rate of how often fetch was idle.
Definition fetch.hh:597
statistics::Scalar tlbSquashes
Total number of outstanding tlb accesses that were dropped due to a squash.
Definition fetch.hh:593
statistics::Distribution nisnDist
Distribution of number of instructions fetched each cycle.
Definition fetch.hh:595
Source of possible stalls.
Definition fetch.hh:448

Generated on Mon Oct 27 2025 04:13:00 for gem5 by doxygen 1.14.0