48 #include "debug/Drain.hh"
49 #include "debug/Fetch.hh"
50 #include "debug/MinorTrace.hh"
57 MinorCPUParams ¶ms,
66 prediction(prediction_),
67 nextStageReserve(next_stage_input_buffer),
68 icachePort(name_ +
".icache_port", *this, cpu_),
69 lineSnap(params.fetch1LineSnapWidth),
70 maxLineWidth(params.fetch1LineWidth),
71 fetchLimit(params.fetch1FetchLimit),
72 fetchInfo(params.numThreads),
74 requests(name_ +
".requests",
"lines", params.fetch1FetchLimit),
75 transfers(name_ +
".transfers",
"lines", params.fetch1FetchLimit),
76 icacheState(IcacheRunning),
77 lineSeqNum(
InstId::firstLineSeqNum),
78 numFetchesInMemorySystem(0),
83 DPRINTF(Fetch,
"lineSnap set to cache line size of: %d\n",
89 DPRINTF(Fetch,
"maxLineWidth set to cache line size of: %d\n",
95 fatal(
"%s: fetch1LineSnapWidth must be a multiple "
96 "of sizeof(TheISA::MachInst) (%d)\n", name_,
103 fatal(
"%s: fetch1LineWidth must be a multiple of"
104 " sizeof(TheISA::MachInst)"
105 " (%d), and >= fetch1LineSnapWidth (%d)\n",
110 fatal(
"%s: fetch1FetchLimit must be >= 1 (%d)\n", name_,
122 case Enums::SingleThreaded:
123 priority_list.push_back(0);
125 case Enums::RoundRobin:
132 panic(
"Unknown fetch policy");
135 for (
auto tid : priority_list) {
157 unsigned int line_offset = aligned_pc %
lineSnap;
167 DPRINTF(Fetch,
"Inserting fetch into the fetch queue "
168 "%s addr: 0x%x pc: %s line_offset: %d request_size: %d\n",
169 request_id, aligned_pc, thread.
pc, line_offset, request_size);
175 thread.
pc.instAddr());
177 DPRINTF(Fetch,
"Submitting ITLB request\n");
199 #if THE_ISA == ALPHA_ISA
201 Addr pc_low_bits = thread.
pc.instAddr() &
204 thread.
pc.set(aligned_pc + request_size + pc_low_bits);
206 thread.
pc.set(aligned_pc + request_size);
215 os <<
"IcacheRunning";
218 os <<
"IcacheNeedsRetry";
221 os <<
"IcacheState-" <<
static_cast<int>(state);
246 fetch.handleTLBResponse(
this);
258 DPRINTF(Fetch,
"Fault in address ITLB translation: %s, "
259 "paddr: 0x%x, vaddr: 0x%x\n",
260 response->
fault->name(),
267 DPRINTF(Fetch,
"Got ITLB response\n");
285 DPRINTF(Fetch,
"Fetch not at front of requests queue, can't"
286 " issue to memory\n");
291 DPRINTF(Fetch,
"Fetch still in translation, not issuing to"
316 DPRINTF(Fetch,
"Not advancing line fetch\n");
344 DPRINTF(Fetch,
"Issued fetch request to memory: %s\n",
350 DPRINTF(Fetch,
"Line fetch needs to retry: %s\n",
374 DPRINTF(Fetch,
"Step in state %s moving to state %s\n",
382 if (!queue.
empty()) {
383 delete queue.
front();
403 MINORLINE(
this,
"id=F;%s vaddr=0x%x fault=\"error packet\"\n",
404 response->
id, request.getVaddr());
406 MINORLINE(
this,
"id=F;%s vaddr=0x%x fault=\"%s\"\n",
407 response->
id, request.getVaddr(), response->
fault->name());
409 MINORLINE(
this,
"id=%s size=%d vaddr=0x%x paddr=0x%x\n",
410 response->
id, request.getSize(),
411 request.getVaddr(), request.getPaddr());
427 assert(!fetch_request->
packet);
428 fetch_request->
packet = response;
437 DPRINTF(Fetch,
"Received error response packet: %s\n",
475 os <<
"FetchWaitingForPC";
478 os <<
"FetchRunning";
481 os <<
"FetchState-" <<
static_cast<int>(state);
499 DPRINTF(Fetch,
"Not suspending fetch due to guard: %s\n",
502 DPRINTF(Fetch,
"Suspending fetch: %s\n", branch);
508 DPRINTF(Fetch,
"Halting fetch\n");
512 DPRINTF(Fetch,
"Changing stream on branch: %s\n", branch);
524 DPRINTF(Fetch,
"Updating streamSeqNum from: %d to %d,"
525 " predictionSeqNum from: %d to %d\n",
548 line.
id = response->
id;
550 line.
pc = response->
pc;
560 DPRINTF(Fetch,
"Stopping line fetch because of fault: %s\n",
561 response->
fault->name());
580 for (
ThreadID tid = 0; tid <
cpu.numThreads; tid++)
593 DPRINTF(Fetch,
"Halted, ignoring branch: %s\n", execute_branch);
599 DPRINTF(Fetch,
"Ignoring simultaneous prediction: %s\n",
611 DPRINTF(Fetch,
"Not changing stream on prediction: %s,"
612 " streamSeqNum mismatch\n",
624 DPRINTF(Fetch,
"Halted, ignoring branch: %s\n", execute_branch);
634 DPRINTF(Fetch,
"Halted, ignoring branch: %s\n", fetch2_branch);
636 DPRINTF(Fetch,
"Not changing stream on prediction: %s,"
637 " streamSeqNum mismatch\n", fetch2_branch);
648 DPRINTF(Fetch,
"Fetching from thread %d\n", fetch_tid);
655 DPRINTF(Fetch,
"No active threads available to fetch from\n");
674 DPRINTF(Fetch,
"Discarding translated fetch as it's for"
681 DPRINTF(Fetch,
"Processing fetched line: %s\n",
708 thread.wakeupGuard =
false;
720 DPRINTF(Fetch,
"[tid:%d]: Changing stream wakeup %s\n",
730 for (
ThreadID tid = 0; tid <
cpu.numThreads; tid++) {
732 DPRINTF(Drain,
"isDrained[tid:%d]: %s %s%s\n",
736 ((*
out.inputWire).isBubble() ?
"" :
"outputtingLine"));
755 return state != InTranslation && state != RequestIssuing &&
767 std::ostringstream
data;
772 (*
out.inputWire).reportData(data);
774 MINORTRACE(
"state=%s icacheState=%s in_tlb_mem=%s/%s"
void processResponse(FetchRequestPtr response, ForwardLineData &line)
Convert a response to a ForwardLineData.
std::ostream & operator<<(std::ostream &os, const InstId &id)
Print this id in the usual slash-separated format expected by MinorTrace.
std::vector< Fetch1ThreadInfo > fetchInfo
IcacheState
State of memory access for head instruction fetch.
InstSeqNum predictionSeqNum
Prediction sequence number.
const std::string & name() const
decltype(nullptr) constexpr NoFault
void pop()
Pop the head item.
void fetchLine(ThreadID tid)
Insert a line fetch into the requests.
void stepQueues()
Step requests along between requests and transfers queues.
bool tryToSend(FetchRequestPtr request)
Try to send (or resend) a memory request's next/only packet to the memory system. ...
Addr lineBaseAddr
First byte address in the line.
static bool isStreamChange(const BranchData::Reason reason)
Is a request with this reason actually a request to change the PC rather than a bubble or branch pred...
std::vector< InputBuffer< ForwardLineData > > & nextStageReserve
Interface to reserve space in the next stage.
ThreadID threadId
ThreadID associated with branch.
unsigned int lineSnap
Line snap size in bytes.
unsigned int numFetchesInMemorySystem
Count of the number fetches which have left the transfers queue and are in the 'wild' in the memory s...
InstId id
Identity of the line that this request will generate.
void wakeupOnEvent(unsigned int stage_id)
Interface for stages to signal that they have become active after a callback or eventq event where th...
void popAndDiscard(FetchQueue &queue)
Pop a request from the given queue and correctly deallocate and discard it.
void changeStream(const BranchData &branch)
Start fetching from a new address.
void updateExpectedSeqNums(const BranchData &branch)
Update streamSeqNum and predictionSeqNum from the given branch (and assume these have changed and dis...
Line fetch data in the forward direction.
Reason reason
Explanation for this branch.
Stage cycle-by-cycle state.
void activity()
Records that there is activity this cycle.
bool isDiscardable() const
Is this line out of date with the current stream/prediction sequence and can it be discarded without ...
IcacheState icacheState
Retry state of icache_port.
TheISA::PCState pc
PC to fixup with line address.
Id for lines and instructions.
void setContext(ContextID context_id)
Set up Context numbers.
InstSeqNum newStreamSeqNum
Sequence number of new stream/prediction to be adopted.
TheISA::PCState pc
PC of the first requested inst within this line.
bool sendTimingReq(PacketPtr pkt)
Attempt to send a timing request to the slave port by calling its corresponding receive function...
virtual TheISA::PCState pcState()=0
Fetch1(const std::string &name_, MinorCPU &cpu_, MinorCPUParams ¶ms, Latch< BranchData >::Output inp_, Latch< ForwardLineData >::Input out_, Latch< BranchData >::Output prediction_, std::vector< InputBuffer< ForwardLineData >> &next_stage_input_buffer)
Latch< BranchData >::Output inp
Input port carrying branch requests from Execute.
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void reserve()
Reserve space in the queue for future pushes.
void handleTLBResponse(FetchRequestPtr response)
Handle pushing a TLB response onto the right queue.
MinorCPU & cpu
Construction-assigned data members.
bool blocked
Blocked indication for report.
bool empty() const
Is the queue empty?
ElemType & front()
Head value.
void reportData(std::ostream &os) const
Report interface.
bool wakeupGuard
Signal to guard against sleeping first cycle of wakeup.
std::vector< ThreadID > randomPriority()
Latch< BranchData >::Output prediction
Input port carrying branch predictions from Fetch2.
bool isComplete() const
Is this a complete read line or fault.
FetchQueue requests
Queue of address translated requests from Fetch1.
void moveFromRequestsToTransfers(FetchRequestPtr request)
Move a request between queues.
Minor::MinorActivityRecorder * activityRecorder
Activity recording for pipeline.
bool needsResponse() const
Request request
The underlying request that this fetch represents.
InstId id
Thread, stream, prediction ...
Latch< ForwardLineData >::Input out
Output port carrying read lines to Fetch2.
unsigned int numFetchesInITLB
Number of requests inside the ITLB rather than in the queues.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
unsigned int numInFlightFetches()
Returns the total number of queue occupancy, in-ITLB and in-memory system fetches.
void makePacket()
Make a packet to use with the memory transaction.
InstSeqNum streamSeqNum
Stream sequence number.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
FetchState
Cycle-by-cycle state.
std::vector< ThreadID > roundRobinPriority(ThreadID priority)
Thread scheduling utility functions.
Fault fault
Fill in a fault if one happens during fetch, check this by picking apart the response packet...
const ThreadID InvalidThreadID
Fetch1 is responsible for fetching "lines" from memory and passing them to Fetch2.
static const int NumArgumentRegs M5_VAR_USED
unsigned int maxLineWidth
Maximum fetch width in bytes.
friend std::ostream & operator<<(std::ostream &os, Fetch1::FetchState state)
int16_t ThreadID
Thread index/ID type.
Forward data betwen Execute and Fetch1 carrying change-of-address/stream information.
void finish(const Fault &fault_, RequestPtr request_, ThreadContext *tc, BaseTLB::Mode mode)
Interface for ITLB responses.
Enums::ThreadPolicy threadPolicy
Thread Scheduling Policy (RoundRobin, Random, etc)
TheISA::PCState pc
Fetch PC value.
virtual bool recvTimingResp(PacketPtr pkt)
Memory interface.
The request was an instruction fetch.
void setVirt(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid, Addr pc)
Set up a virtual (e.g., CPU) request in a previously allocated Request object.
std::vector< Minor::MinorThread * > threads
These are thread state-representing objects for this CPU.
InstSeqNum newPredictionSeqNum
void push(ElemType &data)
Push an element into the buffer if it isn't a bubble.
#define MINORTRACE(...)
DPRINTFN for MinorTrace reporting.
The constructed pipeline.
void wakeupFetch(ThreadID tid)
Initiate fetch1 fetching.
void tryToSendToTransfers(FetchRequestPtr request)
Try and issue a fetch for a translated request at the head of the requests queue. ...
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
bool isDrained()
Is this stage drained? For Fetch1, draining is initiated by Execute signalling a branch with the reas...
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
#define MINORLINE(sim_object,...)
DPRINTFN for MinorTrace MinorLine line reporting.
InstSeqNum lineSeqNum
Sequence number for line fetch used for ordering lines to flush.
PacketPtr packet
FetchRequests carry packets while they're in the requests and transfers responses queues...
void setFault(Fault fault_)
Set fault and possible clear the bubble flag.
MinorCPU is an in-order CPU model with four fixed pipeline stages:
void evaluate()
Pass on input/buffer data to the output if you can.
TheISA::PCState target
Starting PC of that stream.
void adoptPacketData(Packet *packet)
Use the data from a packet as line instead of allocating new space.
FetchQueue transfers
Queue of in-memory system requests and responses.
unsigned int occupiedSpace() const
Number of slots already occupied in this buffer.
IcachePort icachePort
IcachePort to pass to the CPU.
std::shared_ptr< FaultBase > Fault
unsigned int fetchLimit
Maximum number of fetches allowed in flight (in queues or memory)
ThreadID threadId
The thread to which this line/instruction belongs.
void minorTraceResponseLine(const std::string &name, FetchRequestPtr response) const
Print the appropriate MinorLine line for a fetch response.
void allocate()
Allocate memory for the packet.
bool hasPaddr() const
Accessor for paddr.
ProbePointArg< PacketInfo > Packet
Packet probe point.
ThreadID getScheduledThread()
Use the current threading policy to determine the next thread to fetch from.
virtual void recvReqRetry()