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.
31 #ifndef __CPU_OZONE_LW_BACK_END_HH__
32 #define __CPU_OZONE_LW_BACK_END_HH__
39 #include "arch/faults.hh"
40 #include "base/timebuf.hh"
41 #include "cpu/inst_seq.hh"
42 #include "cpu/ozone/rename_table.hh"
43 #include "cpu/ozone/thread_state.hh"
44 #include "mem/request.hh"
45 #include "sim/eventq.hh"
52 class OzoneThreadState;
58 typedef OzoneThreadState<Impl> Thread;
60 typedef typename Impl::Params Params;
61 typedef typename Impl::DynInst DynInst;
62 typedef typename Impl::DynInstPtr DynInstPtr;
63 typedef typename Impl::OzoneCPU OzoneCPU;
64 typedef typename Impl::FrontEnd FrontEnd;
65 typedef typename Impl::OzoneCPU::CommStruct CommStruct;
71 typedef SizeStruct DispatchToIssue;
72 typedef SizeStruct IssueToExec;
73 typedef SizeStruct ExecToCommit;
74 typedef SizeStruct Writeback;
76 TimeBuffer<DispatchToIssue> d2i;
77 typename TimeBuffer<DispatchToIssue>::wire instsToDispatch;
78 TimeBuffer<IssueToExec> i2e;
79 typename TimeBuffer<IssueToExec>::wire instsToExecute;
80 TimeBuffer<ExecToCommit> e2c;
81 TimeBuffer<Writeback> numInstsToWB;
83 TimeBuffer<CommStruct> *comm;
84 typename TimeBuffer<CommStruct>::wire toIEW;
85 typename TimeBuffer<CommStruct>::wire fromCommit;
87 class TrapEvent : public Event {
92 TrapEvent(LWBackEnd<Impl> *_be);
95 const char *description();
98 LWBackEnd(Params *params);
100 std::string name() const;
104 void setCPU(OzoneCPU *cpu_ptr);
106 void setFrontEnd(FrontEnd *front_end_ptr)
107 { frontEnd = front_end_ptr; }
109 void setTC(ThreadContext *tc_ptr)
112 void setThreadState(Thread *thread_ptr)
113 { thread = thread_ptr; }
115 void setCommBuffer(TimeBuffer<CommStruct> *_comm);
119 void generateTCEvent() { tcSquash = true; }
121 void squashFromTrap();
122 void checkInterrupts();
127 Fault read(RequestPtr req, T &data, int load_idx);
130 Fault write(RequestPtr req, T &data, int store_idx);
132 Addr readCommitPC() { return commitPC; }
136 Tick lastCommitCycle;
138 bool robEmpty() { return instList.empty(); }
140 bool isFull() { return numInsts >= numROBEntries; }
141 bool isBlocked() { return status == Blocked || dispatchStatus == Blocked; }
143 void fetchFault(Fault &fault);
145 int wakeDependents(DynInstPtr &inst, bool memory_deps = false);
147 /** Tells memory dependence unit that a memory instruction needs to be
148 * rescheduled. It will re-execute once replayMemInst() is called.
150 void rescheduleMemInst(DynInstPtr &inst);
152 /** Re-executes all rescheduled memory instructions. */
153 void replayMemInst(DynInstPtr &inst);
155 /** Completes memory instruction. */
156 void completeMemInst(DynInstPtr &inst) { }
158 void addDcacheMiss(DynInstPtr &inst)
160 waitingMemOps.insert(inst->seqNum);
162 DPRINTF(BE, "Adding a Dcache miss mem op [sn:%lli], total %i\n",
163 inst->seqNum, numWaitingMemOps);
166 void removeDcacheMiss(DynInstPtr &inst)
168 assert(waitingMemOps.find(inst->seqNum) != waitingMemOps.end());
169 waitingMemOps.erase(inst->seqNum);
171 DPRINTF(BE, "Removing a Dcache miss mem op [sn:%lli], total %i\n",
172 inst->seqNum, numWaitingMemOps);
175 void addWaitingMemOp(DynInstPtr &inst)
177 waitingMemOps.insert(inst->seqNum);
179 DPRINTF(BE, "Adding a waiting mem op [sn:%lli], total %i\n",
180 inst->seqNum, numWaitingMemOps);
183 void removeWaitingMemOp(DynInstPtr &inst)
185 assert(waitingMemOps.find(inst->seqNum) != waitingMemOps.end());
186 waitingMemOps.erase(inst->seqNum);
188 DPRINTF(BE, "Removing a waiting mem op [sn:%lli], total %i\n",
189 inst->seqNum, numWaitingMemOps);
192 void instToCommit(DynInstPtr &inst);
196 void takeOverFrom(ThreadContext *old_tc = NULL);
198 bool isSwitchedOut() { return switchedOut; }
201 void generateTrapEvent(Tick latency = 0);
202 void handleFault(Fault &fault, Tick latency = 0);
203 void updateStructures();
204 void dispatchInsts();
205 void dispatchStall();
206 void checkDispatchStatus();
209 void addToLSQ(DynInstPtr &inst);
210 void writebackInsts();
211 bool commitInst(int inst_num);
212 void squash(const InstSeqNum &sn);
213 void squashDueToBranch(DynInstPtr &inst);
214 void squashDueToMemViolation(DynInstPtr &inst);
215 void squashDueToMemBlocked(DynInstPtr &inst);
216 void updateExeInstStats(DynInstPtr &inst);
217 void updateComInstStats(DynInstPtr &inst);
239 Status dispatchStatus;
246 typedef typename Impl::LdstQueue LdstQueue;
250 RenameTable<Impl> commitRenameTable;
252 RenameTable<Impl> renameTable;
254 // General back end width. Used if the more specific isn't given.
259 int numDispatchEntries;
272 /** Index into queue of instructions being written back. */
275 /** Cycle number within the queue of instructions being written
276 * back. Used in case there are too many instructions writing
277 * back at the current cycle and writesbacks need to be scheduled
278 * for the future. See comments in instToCommit().
285 std::set<InstSeqNum> waitingMemOps;
286 typedef std::set<InstSeqNum>::iterator MemIt;
287 int numWaitingMemOps;
288 unsigned maxOutstandingMemOps;
291 InstSeqNum squashSeqNum;
294 Fault faultFromFetch;
300 DynInstPtr memBarrier;
304 bool operator() (const DynInstPtr &lhs, const DynInstPtr &rhs) const
306 return lhs->seqNum > rhs->seqNum;
310 typedef typename std::priority_queue<DynInstPtr, std::vector<DynInstPtr>, pqCompare> ReadyInstQueue;
311 ReadyInstQueue exeList;
313 typedef typename std::list<DynInstPtr>::iterator InstListIt;
315 std::list<DynInstPtr> instList;
316 std::list<DynInstPtr> waitingList;
317 std::list<DynInstPtr> replayList;
318 std::list<DynInstPtr> writeback;
326 // number of cycles stalled for D-cache misses
327 /* Stats::Scalar<> dcacheStallCycles;
328 Counter lastDcacheStall;
330 Stats::Vector<> rob_cap_events;
331 Stats::Vector<> rob_cap_inst_count;
332 Stats::Vector<> iq_cap_events;
333 Stats::Vector<> iq_cap_inst_count;
334 // total number of instructions executed
335 Stats::Vector<> exe_inst;
336 Stats::Vector<> exe_swp;
337 Stats::Vector<> exe_nop;
338 Stats::Vector<> exe_refs;
339 Stats::Vector<> exe_loads;
340 Stats::Vector<> exe_branches;
342 Stats::Vector<> issued_ops;
344 // total number of loads forwaded from LSQ stores
345 Stats::Vector<> lsq_forw_loads;
347 // total number of loads ignored due to invalid addresses
348 Stats::Vector<> inv_addr_loads;
350 // total number of software prefetches ignored due to invalid addresses
351 Stats::Vector<> inv_addr_swpfs;
352 // ready loads blocked due to memory disambiguation
353 Stats::Vector<> lsq_blocked_loads;
355 Stats::Scalar<> lsqInversion;
357 Stats::Vector<> n_issued_dist;
358 Stats::VectorDistribution<> issue_delay_dist;
360 Stats::VectorDistribution<> queue_res_dist;
362 Stats::Vector<> stat_fu_busy;
363 Stats::Vector2d<> stat_fuBusy;
364 Stats::Vector<> dist_unissued;
365 Stats::Vector2d<> stat_issued_inst_type;
367 Stats::Formula misspec_cnt;
368 Stats::Formula misspec_ipc;
369 Stats::Formula issue_rate;
370 Stats::Formula issue_stores;
371 Stats::Formula issue_op_rate;
372 Stats::Formula fu_busy_rate;
373 Stats::Formula commit_stores;
374 Stats::Formula commit_ipc;
375 Stats::Formula commit_ipb;
376 Stats::Formula lsq_inv_rate;
378 Stats::Vector<> writeback_count;
379 Stats::Vector<> producer_inst;
380 Stats::Vector<> consumer_inst;
381 Stats::Vector<> wb_penalized;
383 Stats::Formula wb_rate;
384 Stats::Formula wb_fanout;
385 Stats::Formula wb_penalized_rate;
387 // total number of instructions committed
388 Stats::Vector<> stat_com_inst;
389 Stats::Vector<> stat_com_swp;
390 Stats::Vector<> stat_com_refs;
391 Stats::Vector<> stat_com_loads;
392 Stats::Vector<> stat_com_membars;
393 Stats::Vector<> stat_com_branches;
395 Stats::Distribution<> n_committed_dist;
397 Stats::Scalar<> commit_eligible_samples;
398 Stats::Vector<> commit_eligible;
400 Stats::Vector<> squashedInsts;
401 Stats::Vector<> ROBSquashedInsts;
403 Stats::Scalar<> ROB_fcount;
404 Stats::Formula ROB_full_rate;
406 Stats::Vector<> ROB_count; // cumulative ROB occupancy
407 Stats::Formula ROB_occ_rate;
408 Stats::VectorDistribution<> ROB_occ_dist;
412 Checker<DynInstPtr> *checker;
415 template <class Impl>
418 LWBackEnd<Impl>::read(RequestPtr req, T &data, int load_idx)
420 return LSQ.read(req, data, load_idx);
423 template <class Impl>
426 LWBackEnd<Impl>::write(RequestPtr req, T &data, int store_idx)
428 return LSQ.write(req, data, store_idx);
431 #endif // __CPU_OZONE_LW_BACK_END_HH__