gem5 v24.0.0.0
Loading...
Searching...
No Matches
fetch.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010-2012, 2014 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __CPU_O3_FETCH_HH__
42#define __CPU_O3_FETCH_HH__
43
45#include "arch/generic/mmu.hh"
46#include "base/statistics.hh"
47#include "cpu/o3/comm.hh"
49#include "cpu/o3/limits.hh"
50#include "cpu/pc_event.hh"
52#include "cpu/timebuf.hh"
53#include "cpu/translation.hh"
54#include "enums/SMTFetchPolicy.hh"
55#include "mem/packet.hh"
56#include "mem/port.hh"
57#include "sim/eventq.hh"
58#include "sim/probe/probe.hh"
59
60namespace gem5
61{
62
63struct BaseO3CPUParams;
64
65namespace o3
66{
67
68class CPU;
69
78class Fetch
79{
80 public:
84 class IcachePort : public RequestPort
85 {
86 protected:
89
90 public:
92 IcachePort(Fetch *_fetch, CPU *_cpu);
93
94 protected:
95
98 virtual bool recvTimingResp(PacketPtr pkt);
99
101 virtual void recvReqRetry();
102 };
103
105 {
106 protected:
108
109 public:
110 FetchTranslation(Fetch *_fetch) : fetch(_fetch) {}
111
112 void markDelayed() {}
113
114 void
115 finish(const Fault &fault, const RequestPtr &req,
117 {
118 assert(mode == BaseMMU::Execute);
119 fetch->finishTranslation(fault, req);
120 delete this;
121 }
122 };
123
124 private:
125 /* Event to delay delivery of a fetch translation result in case of
126 * a fault and the nop to carry the fault cannot be generated
127 * immediately */
129 {
130 private:
134
135 public:
137 : fetch(_fetch), req(nullptr)
138 {}
139
140 void setFault(Fault _fault) { fault = _fault; }
141 void setReq(const RequestPtr &_req) { req = _req; }
142
144 void
146 {
147 assert(fetch->numInst < fetch->fetchWidth);
149 }
150
151 const char *
153 {
154 return "CPU FetchFinishTranslation";
155 }
156 };
157
158 public:
167
184
185 private:
188
191
193 SMTFetchPolicy fetchPolicy;
194
197
202
203 public:
205 Fetch(CPU *_cpu, const BaseO3CPUParams &params);
206
208 std::string name() const;
209
210
212 void regProbePoints();
213
215 void setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer);
216
219
222
224 void startupStage();
225
227 void clearStates(ThreadID tid);
228
230 void recvReqRetry();
231
234
236 void drainResume();
237
239 void drainSanityCheck() const;
240
242 bool isDrained() const;
243
245 void takeOverFrom();
246
256 void drainStall(ThreadID tid);
257
259 void wakeFromQuiesce();
260
262 void deactivateThread(ThreadID tid);
263 private:
265 void resetStage();
266
270 void switchToActive();
271
275 void switchToInactive();
276
287
300 void finishTranslation(const Fault &fault, const RequestPtr &mem_req);
301
302
306
308 void doSquash(const PCStateBase &new_pc, const DynInstPtr squashInst,
309 ThreadID tid);
310
315 void squashFromDecode(const PCStateBase &new_pc,
316 const DynInstPtr squashInst,
317 const InstSeqNum seq_num, ThreadID tid);
318
320 bool checkStall(ThreadID tid) const;
321
325
326 public:
331 void squash(const PCStateBase &new_pc, const InstSeqNum seq_num,
332 DynInstPtr squashInst, ThreadID tid);
333
337 void tick();
338
343
349 void fetch(bool &status_change);
350
353 {
354 return (addr & ~(fetchBufferMask));
355 }
356
359
361
362 private:
364 StaticInstPtr curMacroop, const PCStateBase &this_pc,
365 const PCStateBase &next_pc, bool trace);
366
369
372
375
378
382
385
387 void profileStall(ThreadID tid);
388
389 private:
392
395
398
401
404
407
408 //Might be annoying how this name is different than the queue.
411
414
415 std::unique_ptr<PCStateBase> pc[MaxThreads];
416
418
420
423
426
431
434
436 struct Stalls
437 {
438 bool decode;
439 bool drain;
440 };
441
444
447
450
453
456
458 unsigned fetchWidth;
459
461 unsigned decodeWidth;
462
465
468
471
474
479
482
485
488
491
494
497
500
503
506
509
512
515
520
523
526
529
530 protected:
579};
580
581} // namespace o3
582} // namespace gem5
583
584#endif //__CPU_O3_FETCH_HH__
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:264
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition bpred_unit.hh:71
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:94
void finish(const Fault &fault, const RequestPtr &req, gem5::ThreadContext *tc, BaseMMU::Mode mode)
Definition fetch.hh:115
void markDelayed()
Signal that the translation has been delayed due to a hw page table walk.
Definition fetch.hh:112
FetchTranslation(Fetch *_fetch)
Definition fetch.hh:110
const char * description() const
Return a C string describing the event.
Definition fetch.hh:152
void setReq(const RequestPtr &_req)
Definition fetch.hh:141
void process()
Process the delayed finish translation.
Definition fetch.hh:145
IcachePort class for instruction fetch.
Definition fetch.hh:85
Fetch * fetch
Pointer to fetch.
Definition fetch.hh:88
virtual bool recvTimingResp(PacketPtr pkt)
Timing version of receive.
Definition fetch.cc:1584
IcachePort(Fetch *_fetch, CPU *_cpu)
Default constructor.
Definition fetch.cc:78
virtual void recvReqRetry()
Handles doing a retry of a failed fetch.
Definition fetch.cc:1596
Fetch class handles both single threaded and SMT fetch.
Definition fetch.hh:79
gem5::o3::Fetch::FetchStatGroup fetchStats
bool wroteToTimeBuffer
Variable that tracks if fetch has written to the time buffer this cycle.
Definition fetch.hh:430
void deactivateThread(ThreadID tid)
For priority-based fetch policies, need to keep update priorityList.
Definition fetch.cc:476
FetchStatus
Overall fetch status.
Definition fetch.hh:163
std::list< ThreadID > * activeThreads
List of Active Threads.
Definition fetch.hh:505
TimeBuffer< TimeStruct >::wire fromCommit
Wire to get commit's information from backwards time buffer.
Definition fetch.hh:406
Cycles renameToFetchDelay
Rename to fetch delay.
Definition fetch.hh:449
StaticInstPtr macroop[MaxThreads]
Definition fetch.hh:419
void fetch(bool &status_change)
Does the actual fetching of instructions and passing them on to the next stage.
Definition fetch.cc:1073
void takeOverFrom()
Takes over from another CPU's thread.
Definition fetch.cc:426
uint8_t * fetchBuffer[MaxThreads]
The fetch data that is being fetched and buffered.
Definition fetch.hh:484
void doSquash(const PCStateBase &new_pc, const DynInstPtr squashInst, ThreadID tid)
Squashes a specific thread and resets the PC.
Definition fetch.cc:686
TimeBuffer< FetchStruct >::wire toDecode
Wire used to write any information heading to decode.
Definition fetch.hh:410
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
Definition fetch.cc:250
bool lookupAndUpdateNextPC(const DynInstPtr &inst, PCStateBase &pc)
Looks up in the branch predictor to see if the next PC should be either next PC+=MachInst or a branch...
Definition fetch.cc:486
ThreadStatus fetchStatus[MaxThreads]
Per-thread status.
Definition fetch.hh:190
ThreadID numThreads
Number of threads.
Definition fetch.hh:508
TimeBuffer< TimeStruct >::wire fromDecode
Wire to get decode's information from backwards time buffer.
Definition fetch.hh:397
ProbePointArg< DynInstPtr > * ppFetch
Probe points.
Definition fetch.hh:199
TimeBuffer< TimeStruct >::wire fromRename
Wire to get rename's information from backwards time buffer.
Definition fetch.hh:400
void squash(const PCStateBase &new_pc, const InstSeqNum seq_num, DynInstPtr squashInst, ThreadID tid)
Squashes a specific thread and resets the PC.
Definition fetch.cc:804
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:738
FetchStatus updateFetchStatus()
Updates overall fetch stage status; to be called at the end of each cycle.
Definition fetch.cc:765
ThreadID getFetchingThread()
Returns the appropriate thread to fetch, given the fetch policy.
Definition fetch.cc:1364
bool fetchBufferValid[MaxThreads]
Whether or not the fetch buffer data is valid.
Definition fetch.hh:496
void startupStage()
Initialize stage.
Definition fetch.cc:263
void pipelineIcacheAccesses(ThreadID tid)
Pipeline the next I-cache access to the current one.
Definition fetch.cc:1506
std::string name() const
Returns the name of fetch.
Definition fetch.cc:148
void wakeFromQuiesce()
Tells fetch to wake up from a quiesce instruction.
Definition fetch.cc:443
void switchToActive()
Changes the status of this stage to active, and indicates this to the CPU.
Definition fetch.cc:452
void switchToInactive()
Changes the status of this stage to inactive, and indicates this to the CPU.
Definition fetch.cc:464
int numInst
Tracks how many instructions has been fetched this cycle.
Definition fetch.hh:433
bool fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc)
Fetches the cache line that contains the fetch PC.
Definition fetch.cc:530
Cycles decodeToFetchDelay
Decode to fetch delay.
Definition fetch.hh:446
bool issuePipelinedIfetch[MaxThreads]
Set to true if a pipelined I-cache request should be issued.
Definition fetch.hh:525
Addr fetchBufferAlignPC(Addr addr)
Align a PC to the start of a fetch buffer block.
Definition fetch.hh:352
FetchStatus _status
Fetch status.
Definition fetch.hh:187
bool delayedCommit[MaxThreads]
Can the fetch stage redirect from an interrupt on this instruction?
Definition fetch.hh:422
ThreadID threadFetched
Thread ID being fetched.
Definition fetch.hh:514
SMTFetchPolicy fetchPolicy
Fetch policy.
Definition fetch.hh:193
Addr cacheBlkSize
Cache block size.
Definition fetch.hh:473
branch_prediction::BPredUnit * branchPred
BPredUnit.
Definition fetch.hh:413
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition fetch.cc:379
unsigned fetchWidth
The width of fetch in instructions.
Definition fetch.hh:458
unsigned fetchQueueSize
The size of the fetch queue in micro-ops.
Definition fetch.hh:490
InstDecoder * decoder[MaxThreads]
The decoder.
Definition fetch.hh:358
TimeBuffer< TimeStruct >::wire fromIEW
Wire to get iew's information from backwards time buffer.
Definition fetch.hh:403
void regProbePoints()
Registers probes.
Definition fetch.cc:151
bool checkSignalsAndUpdate(ThreadID tid)
Checks all input signals and updates the status as necessary.
Definition fetch.cc:918
bool checkStall(ThreadID tid) const
Checks if a thread is stalled.
Definition fetch.cc:751
IcachePort icachePort
Instruction port.
Definition fetch.hh:522
ThreadStatus
Individual thread status.
Definition fetch.hh:170
@ IcacheAccessComplete
Definition fetch.hh:181
void setTimeBuffer(TimeBuffer< TimeStruct > *time_buffer)
Sets the main backwards communication time buffer pointer.
Definition fetch.cc:238
void processCacheCompletion(PacketPtr pkt)
Processes cache completion event.
Definition fetch.cc:327
ThreadID iqCount()
Returns the appropriate thread to fetch using the IQ count policy.
Definition fetch.cc:1428
RequestPort & getInstPort()
Definition fetch.hh:360
Addr fetchBufferMask
Mask to align a fetch address to a fetch buffer boundary.
Definition fetch.hh:481
void recvReqRetry()
Handles retrying the fetch access.
Definition fetch.cc:1334
bool checkInterrupt(Addr pc)
Check if an interrupt is pending and that we need to handle.
Definition fetch.hh:305
Cycles iewToFetchDelay
IEW to fetch delay.
Definition fetch.hh:452
void resetStage()
Reset this pipeline stage.
Definition fetch.cc:293
Fetch(CPU *_cpu, const BaseO3CPUParams &params)
Fetch constructor.
Definition fetch.cc:83
void drainStall(ThreadID tid)
Stall the fetch stage after reaching a safe drain point.
Definition fetch.cc:434
Counter lastIcacheStall[MaxThreads]
Icache stall statistics.
Definition fetch.hh:502
int instSize
Size of instructions.
Definition fetch.hh:499
ProbePointArg< RequestPtr > * ppFetchRequestSent
To probe when a fetch request is successfully sent.
Definition fetch.hh:201
Cycles commitToFetchDelay
Commit to fetch delay.
Definition fetch.hh:455
RequestPtr memReq[MaxThreads]
Memory request used to access cache.
Definition fetch.hh:425
TimeBuffer< TimeStruct > * timeBuffer
Time buffer interface.
Definition fetch.hh:394
void profileStall(ThreadID tid)
Profile the reasons of fetch stall.
Definition fetch.cc:1535
ThreadID roundRobin()
Returns the appropriate thread to fetch using a round robin policy.
Definition fetch.cc:1399
Addr fetchBufferPC[MaxThreads]
The PC of the first instruction loaded into the fetch buffer.
Definition fetch.hh:487
void drainResume()
Resume after a drain.
Definition fetch.cc:370
void clearStates(ThreadID tid)
Clear all thread-specific states.
Definition fetch.cc:274
void finishTranslation(const Fault &fault, const RequestPtr &mem_req)
Definition fetch.cc:579
bool interruptPending
Checks if there is an interrupt pending.
Definition fetch.hh:519
std::unique_ptr< PCStateBase > pc[MaxThreads]
Definition fetch.hh:415
ThreadID lsqCount()
Returns the appropriate thread to fetch using the LSQ count policy.
Definition fetch.cc:1464
Stalls stalls[MaxThreads]
Tracks which stages are telling fetch to stall.
Definition fetch.hh:443
DynInstPtr buildInst(ThreadID tid, StaticInstPtr staticInst, StaticInstPtr curMacroop, const PCStateBase &this_pc, const PCStateBase &next_pc, bool trace)
Definition fetch.cc:1020
bool isDrained() const
Has the stage drained?
Definition fetch.cc:396
Addr fetchOffset[MaxThreads]
Definition fetch.hh:417
std::deque< DynInstPtr > fetchQueue[MaxThreads]
Queue of fetched instructions.
Definition fetch.hh:493
PacketPtr retryPkt
The packet that is waiting to be retried.
Definition fetch.hh:467
std::list< ThreadID > priorityList
List that has the threads organized by priority.
Definition fetch.hh:196
FinishTranslationEvent finishTranslationEvent
Event used to delay fault generation of translation faults.
Definition fetch.hh:528
ThreadID retryTid
The thread that is waiting on the cache to tell fetch to retry.
Definition fetch.hh:470
void tick()
Ticks the fetch stage, processing all inputs signals and fetching as many instructions as possible.
Definition fetch.cc:816
ThreadID numFetchingThreads
Number of threads that are actively fetching.
Definition fetch.hh:511
unsigned fetchBufferSize
The size of the fetch buffer in bytes.
Definition fetch.hh:478
void setFetchQueue(TimeBuffer< FetchStruct > *fq_ptr)
Sets pointer to time buffer used to communicate to the next stage.
Definition fetch.cc:256
CPU * cpu
Pointer to the O3CPU.
Definition fetch.hh:391
unsigned decodeWidth
The width of decode in instructions.
Definition fetch.hh:461
bool cacheBlocked
Is the cache blocked? If so no threads can access it.
Definition fetch.hh:464
ThreadID branchCount()
Returns the appropriate thread to fetch using the branch count policy.
Definition fetch.cc:1499
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
double Counter
All counters are of 64-bit values.
Definition types.hh:46
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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
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:569
statistics::Scalar pendingDrainCycles
Total number of cycles spent in waiting for drains.
Definition fetch.hh:554
statistics::Scalar cacheLines
Stat for total number of fetched cache lines.
Definition fetch.hh:565
statistics::Scalar blockedCycles
Total number of cycles spent blocked.
Definition fetch.hh:550
statistics::Scalar idleCycles
Stat for total number of cycles spent blocked due to other stages in the pipeline.
Definition fetch.hh:548
statistics::Scalar predictedBranches
Stat for total number of predicted branches.
Definition fetch.hh:537
statistics::Scalar noActiveThreadStallCycles
Total number of stall cycles caused by no active threads to run.
Definition fetch.hh:556
statistics::Scalar pendingQuiesceStallCycles
Total number of stall cycles caused by pending quiesce instructions.
Definition fetch.hh:561
statistics::Scalar icacheWaitRetryStallCycles
Total number of stall cycles caused by I-cache wait retrys.
Definition fetch.hh:563
statistics::Scalar pendingTrapStallCycles
Total number of stall cycles caused by pending traps.
Definition fetch.hh:558
statistics::Scalar cycles
Stat for total number of cycles spent fetching.
Definition fetch.hh:539
statistics::Scalar miscStallCycles
Total number of cycles spent in any other state.
Definition fetch.hh:552
statistics::Scalar tlbCycles
Stat for total number of cycles spent waiting for translation.
Definition fetch.hh:543
statistics::Scalar squashCycles
Stat for total number of cycles spent squashing.
Definition fetch.hh:541
FetchStatGroup(CPU *cpu, Fetch *fetch)
Definition fetch.cc:159
statistics::Formula idleRate
Rate of how often fetch was idle.
Definition fetch.hh:577
statistics::Scalar tlbSquashes
Total number of outstanding tlb accesses that were dropped due to a squash.
Definition fetch.hh:573
statistics::Distribution nisnDist
Distribution of number of instructions fetched each cycle.
Definition fetch.hh:575
Source of possible stalls.
Definition fetch.hh:437

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0