2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __CPU_OZONE_LW_BACK_END_HH__
30 #define __CPU_OZONE_LW_BACK_END_HH__
37 #include "arch/faults.hh"
38 #include "base/timebuf.hh"
39 #include "cpu/inst_seq.hh"
40 #include "cpu/ozone/rename_table.hh"
41 #include "cpu/ozone/thread_state.hh"
42 #include "mem/request.hh"
43 #include "sim/eventq.hh"
50 class OzoneThreadState;
56 typedef OzoneThreadState<Impl> Thread;
58 typedef typename Impl::Params Params;
59 typedef typename Impl::DynInst DynInst;
60 typedef typename Impl::DynInstPtr DynInstPtr;
61 typedef typename Impl::FullCPU FullCPU;
62 typedef typename Impl::FrontEnd FrontEnd;
63 typedef typename Impl::FullCPU::CommStruct CommStruct;
69 typedef SizeStruct DispatchToIssue;
70 typedef SizeStruct IssueToExec;
71 typedef SizeStruct ExecToCommit;
72 typedef SizeStruct Writeback;
74 TimeBuffer<DispatchToIssue> d2i;
75 typename TimeBuffer<DispatchToIssue>::wire instsToDispatch;
76 TimeBuffer<IssueToExec> i2e;
77 typename TimeBuffer<IssueToExec>::wire instsToExecute;
78 TimeBuffer<ExecToCommit> e2c;
79 TimeBuffer<Writeback> numInstsToWB;
81 TimeBuffer<CommStruct> *comm;
82 typename TimeBuffer<CommStruct>::wire toIEW;
83 typename TimeBuffer<CommStruct>::wire fromCommit;
85 class TrapEvent : public Event {
90 TrapEvent(LWBackEnd<Impl> *_be);
93 const char *description();
96 /** LdWriteback event for a load completion. */
97 class LdWritebackEvent : public Event {
99 /** Instruction that is writing back data to the register file. */
101 /** Pointer to IEW stage. */
107 /** Constructs a load writeback event. */
108 LdWritebackEvent(DynInstPtr &_inst, LWBackEnd *be);
110 /** Processes writeback event. */
111 virtual void process();
112 /** Returns the description of the writeback event. */
113 virtual const char *description();
115 void setDcacheMiss() { dcacheMiss = true; be->addDcacheMiss(inst); }
118 LWBackEnd(Params *params);
120 std::string name() const;
124 void setCPU(FullCPU *cpu_ptr);
126 void setFrontEnd(FrontEnd *front_end_ptr)
127 { frontEnd = front_end_ptr; }
129 void setTC(ThreadContext *tc_ptr)
132 void setThreadState(Thread *thread_ptr)
133 { thread = thread_ptr; }
135 void setCommBuffer(TimeBuffer<CommStruct> *_comm);
139 void generateTCEvent() { tcSquash = true; }
141 void squashFromTrap();
142 void checkInterrupts();
147 Fault read(RequestPtr req, T &data, int load_idx);
150 Fault write(RequestPtr req, T &data, int store_idx);
152 Addr readCommitPC() { return commitPC; }
156 Tick lastCommitCycle;
158 bool robEmpty() { return instList.empty(); }
160 bool isFull() { return numInsts >= numROBEntries; }
161 bool isBlocked() { return status == Blocked || dispatchStatus == Blocked; }
163 void fetchFault(Fault &fault);
165 int wakeDependents(DynInstPtr &inst, bool memory_deps = false);
167 /** Tells memory dependence unit that a memory instruction needs to be
168 * rescheduled. It will re-execute once replayMemInst() is called.
170 void rescheduleMemInst(DynInstPtr &inst);
172 /** Re-executes all rescheduled memory instructions. */
173 void replayMemInst(DynInstPtr &inst);
175 /** Completes memory instruction. */
176 void completeMemInst(DynInstPtr &inst) { }
178 void addDcacheMiss(DynInstPtr &inst)
180 waitingMemOps.insert(inst->seqNum);
182 DPRINTF(BE, "Adding a Dcache miss mem op [sn:%lli], total %i\n",
183 inst->seqNum, numWaitingMemOps);
186 void removeDcacheMiss(DynInstPtr &inst)
188 assert(waitingMemOps.find(inst->seqNum) != waitingMemOps.end());
189 waitingMemOps.erase(inst->seqNum);
191 DPRINTF(BE, "Removing a Dcache miss mem op [sn:%lli], total %i\n",
192 inst->seqNum, numWaitingMemOps);
195 void addWaitingMemOp(DynInstPtr &inst)
197 waitingMemOps.insert(inst->seqNum);
199 DPRINTF(BE, "Adding a waiting mem op [sn:%lli], total %i\n",
200 inst->seqNum, numWaitingMemOps);
203 void removeWaitingMemOp(DynInstPtr &inst)
205 assert(waitingMemOps.find(inst->seqNum) != waitingMemOps.end());
206 waitingMemOps.erase(inst->seqNum);
208 DPRINTF(BE, "Removing a waiting mem op [sn:%lli], total %i\n",
209 inst->seqNum, numWaitingMemOps);
212 void instToCommit(DynInstPtr &inst);
216 void takeOverFrom(ThreadContext *old_tc = NULL);
218 bool isSwitchedOut() { return switchedOut; }
221 void generateTrapEvent(Tick latency = 0);
222 void handleFault(Fault &fault, Tick latency = 0);
223 void updateStructures();
224 void dispatchInsts();
225 void dispatchStall();
226 void checkDispatchStatus();
229 void addToLSQ(DynInstPtr &inst);
230 void writebackInsts();
231 bool commitInst(int inst_num);
232 void squash(const InstSeqNum &sn);
233 void squashDueToBranch(DynInstPtr &inst);
234 void squashDueToMemViolation(DynInstPtr &inst);
235 void squashDueToMemBlocked(DynInstPtr &inst);
236 void updateExeInstStats(DynInstPtr &inst);
237 void updateComInstStats(DynInstPtr &inst);
259 Status dispatchStatus;
266 typedef typename Impl::LdstQueue LdstQueue;
270 RenameTable<Impl> commitRenameTable;
272 RenameTable<Impl> renameTable;
274 class DCacheCompletionEvent : public Event
280 DCacheCompletionEvent(LWBackEnd *_be);
282 virtual void process();
283 virtual const char *description();
286 friend class DCacheCompletionEvent;
288 DCacheCompletionEvent cacheCompletionEvent;
290 MemInterface *dcacheInterface;
292 // General back end width. Used if the more specific isn't given.
297 int numDispatchEntries;
310 /** Index into queue of instructions being written back. */
313 /** Cycle number within the queue of instructions being written
314 * back. Used in case there are too many instructions writing
315 * back at the current cycle and writesbacks need to be scheduled
316 * for the future. See comments in instToCommit().
323 std::set<InstSeqNum> waitingMemOps;
324 typedef std::set<InstSeqNum>::iterator MemIt;
325 int numWaitingMemOps;
326 unsigned maxOutstandingMemOps;
329 InstSeqNum squashSeqNum;
332 Fault faultFromFetch;
338 DynInstPtr memBarrier;
342 bool operator() (const DynInstPtr &lhs, const DynInstPtr &rhs) const
344 return lhs->seqNum > rhs->seqNum;
348 typedef typename std::priority_queue<DynInstPtr, std::vector<DynInstPtr>, pqCompare> ReadyInstQueue;
349 ReadyInstQueue exeList;
351 typedef typename std::list<DynInstPtr>::iterator InstListIt;
353 std::list<DynInstPtr> instList;
354 std::list<DynInstPtr> waitingList;
355 std::list<DynInstPtr> replayList;
356 std::list<DynInstPtr> writeback;
364 // number of cycles stalled for D-cache misses
365 /* Stats::Scalar<> dcacheStallCycles;
366 Counter lastDcacheStall;
368 Stats::Vector<> rob_cap_events;
369 Stats::Vector<> rob_cap_inst_count;
370 Stats::Vector<> iq_cap_events;
371 Stats::Vector<> iq_cap_inst_count;
372 // total number of instructions executed
373 Stats::Vector<> exe_inst;
374 Stats::Vector<> exe_swp;
375 Stats::Vector<> exe_nop;
376 Stats::Vector<> exe_refs;
377 Stats::Vector<> exe_loads;
378 Stats::Vector<> exe_branches;
380 Stats::Vector<> issued_ops;
382 // total number of loads forwaded from LSQ stores
383 Stats::Vector<> lsq_forw_loads;
385 // total number of loads ignored due to invalid addresses
386 Stats::Vector<> inv_addr_loads;
388 // total number of software prefetches ignored due to invalid addresses
389 Stats::Vector<> inv_addr_swpfs;
390 // ready loads blocked due to memory disambiguation
391 Stats::Vector<> lsq_blocked_loads;
393 Stats::Scalar<> lsqInversion;
395 Stats::Vector<> n_issued_dist;
396 Stats::VectorDistribution<> issue_delay_dist;
398 Stats::VectorDistribution<> queue_res_dist;
400 Stats::Vector<> stat_fu_busy;
401 Stats::Vector2d<> stat_fuBusy;
402 Stats::Vector<> dist_unissued;
403 Stats::Vector2d<> stat_issued_inst_type;
405 Stats::Formula misspec_cnt;
406 Stats::Formula misspec_ipc;
407 Stats::Formula issue_rate;
408 Stats::Formula issue_stores;
409 Stats::Formula issue_op_rate;
410 Stats::Formula fu_busy_rate;
411 Stats::Formula commit_stores;
412 Stats::Formula commit_ipc;
413 Stats::Formula commit_ipb;
414 Stats::Formula lsq_inv_rate;
416 Stats::Vector<> writeback_count;
417 Stats::Vector<> producer_inst;
418 Stats::Vector<> consumer_inst;
419 Stats::Vector<> wb_penalized;
421 Stats::Formula wb_rate;
422 Stats::Formula wb_fanout;
423 Stats::Formula wb_penalized_rate;
425 // total number of instructions committed
426 Stats::Vector<> stat_com_inst;
427 Stats::Vector<> stat_com_swp;
428 Stats::Vector<> stat_com_refs;
429 Stats::Vector<> stat_com_loads;
430 Stats::Vector<> stat_com_membars;
431 Stats::Vector<> stat_com_branches;
433 Stats::Distribution<> n_committed_dist;
435 Stats::Scalar<> commit_eligible_samples;
436 Stats::Vector<> commit_eligible;
438 Stats::Vector<> squashedInsts;
439 Stats::Vector<> ROBSquashedInsts;
441 Stats::Scalar<> ROB_fcount;
442 Stats::Formula ROB_full_rate;
444 Stats::Vector<> ROB_count; // cumulative ROB occupancy
445 Stats::Formula ROB_occ_rate;
446 Stats::VectorDistribution<> ROB_occ_dist;
450 Checker<DynInstPtr> *checker;
453 template <class Impl>
456 LWBackEnd<Impl>::read(RequestPtr req, T &data, int load_idx)
458 return LSQ.read(req, data, load_idx);
461 template <class Impl>
464 LWBackEnd<Impl>::write(RequestPtr req, T &data, int store_idx)
466 return LSQ.write(req, data, store_idx);
469 #endif // __CPU_OZONE_LW_BACK_END_HH__