iew.hh (2674:6d4afef73a20) iew.hh (2698:d5f35d41e017)
1/*
2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Kevin Lim
29 */
30
31#ifndef __CPU_O3_IEW_HH__
32#define __CPU_O3_IEW_HH__
33
34#include <queue>
35
36#include "base/statistics.hh"
37#include "base/timebuf.hh"
38#include "config/full_system.hh"
39#include "cpu/o3/comm.hh"
40#include "cpu/o3/scoreboard.hh"
41#include "cpu/o3/lsq.hh"
42
43class FUPool;
44
45/**
46 * DefaultIEW handles both single threaded and SMT IEW
47 * (issue/execute/writeback). It handles the dispatching of
48 * instructions to the LSQ/IQ as part of the issue stage, and has the
49 * IQ try to issue instructions each cycle. The execute latency is
50 * actually tied into the issue latency to allow the IQ to be able to
51 * do back-to-back scheduling without having to speculatively schedule
52 * instructions. This happens by having the IQ have access to the
53 * functional units, and the IQ gets the execution latencies from the
54 * FUs when it issues instructions. Instructions reach the execute
55 * stage on the last cycle of their execution, which is when the IQ
56 * knows to wake up any dependent instructions, allowing back to back
57 * scheduling. The execute portion of IEW separates memory
58 * instructions from non-memory instructions, either telling the LSQ
59 * to execute the instruction, or executing the instruction directly.
60 * The writeback portion of IEW completes the instructions by waking
61 * up any dependents, and marking the register ready on the
62 * scoreboard.
63 */
64template<class Impl>
65class DefaultIEW
66{
67 private:
68 //Typedefs from Impl
69 typedef typename Impl::CPUPol CPUPol;
70 typedef typename Impl::DynInstPtr DynInstPtr;
71 typedef typename Impl::FullCPU FullCPU;
72 typedef typename Impl::Params Params;
73
74 typedef typename CPUPol::IQ IQ;
75 typedef typename CPUPol::RenameMap RenameMap;
76 typedef typename CPUPol::LSQ LSQ;
77
78 typedef typename CPUPol::TimeStruct TimeStruct;
79 typedef typename CPUPol::IEWStruct IEWStruct;
80 typedef typename CPUPol::RenameStruct RenameStruct;
81 typedef typename CPUPol::IssueStruct IssueStruct;
82
83 friend class Impl::FullCPU;
84 friend class CPUPol::IQ;
85
86 public:
87 /** Overall IEW stage status. Used to determine if the CPU can
88 * deschedule itself due to a lack of activity.
89 */
90 enum Status {
91 Active,
92 Inactive
93 };
94
95 /** Status for Issue, Execute, and Writeback stages. */
96 enum StageStatus {
97 Running,
98 Blocked,
99 Idle,
100 StartSquash,
101 Squashing,
102 Unblocking
103 };
104
105 private:
106 /** Overall stage status. */
107 Status _status;
108 /** Dispatch status. */
109 StageStatus dispatchStatus[Impl::MaxThreads];
110 /** Execute status. */
111 StageStatus exeStatus;
112 /** Writeback status. */
113 StageStatus wbStatus;
114
115 public:
116 /** Constructs a DefaultIEW with the given parameters. */
117 DefaultIEW(Params *params);
118
119 /** Returns the name of the DefaultIEW stage. */
120 std::string name() const;
121
122 /** Registers statistics. */
123 void regStats();
124
125 /** Initializes stage; sends back the number of free IQ and LSQ entries. */
126 void initStage();
127
128 /** Sets CPU pointer for IEW, IQ, and LSQ. */
129 void setCPU(FullCPU *cpu_ptr);
130
131 /** Sets main time buffer used for backwards communication. */
132 void setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr);
133
134 /** Sets time buffer for getting instructions coming from rename. */
135 void setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr);
136
137 /** Sets time buffer to pass on instructions to commit. */
138 void setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr);
139
140 /** Sets pointer to list of active threads. */
141 void setActiveThreads(std::list<unsigned> *at_ptr);
142
143 /** Sets pointer to the scoreboard. */
144 void setScoreboard(Scoreboard *sb_ptr);
145
146 /** Starts switch out of IEW stage. */
147 void switchOut();
148
149 /** Completes switch out of IEW stage. */
150 void doSwitchOut();
151
152 /** Takes over from another CPU's thread. */
153 void takeOverFrom();
154
155 /** Returns if IEW is switched out. */
156 bool isSwitchedOut() { return switchedOut; }
157
1/*
2 * Copyright (c) 2004-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Kevin Lim
29 */
30
31#ifndef __CPU_O3_IEW_HH__
32#define __CPU_O3_IEW_HH__
33
34#include <queue>
35
36#include "base/statistics.hh"
37#include "base/timebuf.hh"
38#include "config/full_system.hh"
39#include "cpu/o3/comm.hh"
40#include "cpu/o3/scoreboard.hh"
41#include "cpu/o3/lsq.hh"
42
43class FUPool;
44
45/**
46 * DefaultIEW handles both single threaded and SMT IEW
47 * (issue/execute/writeback). It handles the dispatching of
48 * instructions to the LSQ/IQ as part of the issue stage, and has the
49 * IQ try to issue instructions each cycle. The execute latency is
50 * actually tied into the issue latency to allow the IQ to be able to
51 * do back-to-back scheduling without having to speculatively schedule
52 * instructions. This happens by having the IQ have access to the
53 * functional units, and the IQ gets the execution latencies from the
54 * FUs when it issues instructions. Instructions reach the execute
55 * stage on the last cycle of their execution, which is when the IQ
56 * knows to wake up any dependent instructions, allowing back to back
57 * scheduling. The execute portion of IEW separates memory
58 * instructions from non-memory instructions, either telling the LSQ
59 * to execute the instruction, or executing the instruction directly.
60 * The writeback portion of IEW completes the instructions by waking
61 * up any dependents, and marking the register ready on the
62 * scoreboard.
63 */
64template<class Impl>
65class DefaultIEW
66{
67 private:
68 //Typedefs from Impl
69 typedef typename Impl::CPUPol CPUPol;
70 typedef typename Impl::DynInstPtr DynInstPtr;
71 typedef typename Impl::FullCPU FullCPU;
72 typedef typename Impl::Params Params;
73
74 typedef typename CPUPol::IQ IQ;
75 typedef typename CPUPol::RenameMap RenameMap;
76 typedef typename CPUPol::LSQ LSQ;
77
78 typedef typename CPUPol::TimeStruct TimeStruct;
79 typedef typename CPUPol::IEWStruct IEWStruct;
80 typedef typename CPUPol::RenameStruct RenameStruct;
81 typedef typename CPUPol::IssueStruct IssueStruct;
82
83 friend class Impl::FullCPU;
84 friend class CPUPol::IQ;
85
86 public:
87 /** Overall IEW stage status. Used to determine if the CPU can
88 * deschedule itself due to a lack of activity.
89 */
90 enum Status {
91 Active,
92 Inactive
93 };
94
95 /** Status for Issue, Execute, and Writeback stages. */
96 enum StageStatus {
97 Running,
98 Blocked,
99 Idle,
100 StartSquash,
101 Squashing,
102 Unblocking
103 };
104
105 private:
106 /** Overall stage status. */
107 Status _status;
108 /** Dispatch status. */
109 StageStatus dispatchStatus[Impl::MaxThreads];
110 /** Execute status. */
111 StageStatus exeStatus;
112 /** Writeback status. */
113 StageStatus wbStatus;
114
115 public:
116 /** Constructs a DefaultIEW with the given parameters. */
117 DefaultIEW(Params *params);
118
119 /** Returns the name of the DefaultIEW stage. */
120 std::string name() const;
121
122 /** Registers statistics. */
123 void regStats();
124
125 /** Initializes stage; sends back the number of free IQ and LSQ entries. */
126 void initStage();
127
128 /** Sets CPU pointer for IEW, IQ, and LSQ. */
129 void setCPU(FullCPU *cpu_ptr);
130
131 /** Sets main time buffer used for backwards communication. */
132 void setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr);
133
134 /** Sets time buffer for getting instructions coming from rename. */
135 void setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr);
136
137 /** Sets time buffer to pass on instructions to commit. */
138 void setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr);
139
140 /** Sets pointer to list of active threads. */
141 void setActiveThreads(std::list<unsigned> *at_ptr);
142
143 /** Sets pointer to the scoreboard. */
144 void setScoreboard(Scoreboard *sb_ptr);
145
146 /** Starts switch out of IEW stage. */
147 void switchOut();
148
149 /** Completes switch out of IEW stage. */
150 void doSwitchOut();
151
152 /** Takes over from another CPU's thread. */
153 void takeOverFrom();
154
155 /** Returns if IEW is switched out. */
156 bool isSwitchedOut() { return switchedOut; }
157
158 /** Sets page table pointer within LSQ. */
159// void setPageTable(PageTable *pt_ptr);
160
161 /** Squashes instructions in IEW for a specific thread. */
162 void squash(unsigned tid);
163
164 /** Wakes all dependents of a completed instruction. */
165 void wakeDependents(DynInstPtr &inst);
166
167 /** Tells memory dependence unit that a memory instruction needs to be
168 * rescheduled. It will re-execute once replayMemInst() is called.
169 */
170 void rescheduleMemInst(DynInstPtr &inst);
171
172 /** Re-executes all rescheduled memory instructions. */
173 void replayMemInst(DynInstPtr &inst);
174
175 /** Sends an instruction to commit through the time buffer. */
176 void instToCommit(DynInstPtr &inst);
177
178 /** Inserts unused instructions of a thread into the skid buffer. */
179 void skidInsert(unsigned tid);
180
181 /** Returns the max of the number of entries in all of the skid buffers. */
182 int skidCount();
183
184 /** Returns if all of the skid buffers are empty. */
185 bool skidsEmpty();
186
187 /** Updates overall IEW status based on all of the stages' statuses. */
188 void updateStatus();
189
190 /** Resets entries of the IQ and the LSQ. */
191 void resetEntries();
192
193 /** Tells the CPU to wakeup if it has descheduled itself due to no
194 * activity. Used mainly by the LdWritebackEvent.
195 */
196 void wakeCPU();
197
198 /** Reports to the CPU that there is activity this cycle. */
199 void activityThisCycle();
200
201 /** Tells CPU that the IEW stage is active and running. */
202 inline void activateStage();
203
204 /** Tells CPU that the IEW stage is inactive and idle. */
205 inline void deactivateStage();
206
207 /** Returns if the LSQ has any stores to writeback. */
208 bool hasStoresToWB() { return ldstQueue.hasStoresToWB(); }
209
210 private:
211 /** Sends commit proper information for a squash due to a branch
212 * mispredict.
213 */
214 void squashDueToBranch(DynInstPtr &inst, unsigned thread_id);
215
216 /** Sends commit proper information for a squash due to a memory order
217 * violation.
218 */
219 void squashDueToMemOrder(DynInstPtr &inst, unsigned thread_id);
220
221 /** Sends commit proper information for a squash due to memory becoming
222 * blocked (younger issued instructions must be retried).
223 */
224 void squashDueToMemBlocked(DynInstPtr &inst, unsigned thread_id);
225
226 /** Sets Dispatch to blocked, and signals back to other stages to block. */
227 void block(unsigned thread_id);
228
229 /** Unblocks Dispatch if the skid buffer is empty, and signals back to
230 * other stages to unblock.
231 */
232 void unblock(unsigned thread_id);
233
234 /** Determines proper actions to take given Dispatch's status. */
235 void dispatch(unsigned tid);
236
237 /** Dispatches instructions to IQ and LSQ. */
238 void dispatchInsts(unsigned tid);
239
240 /** Executes instructions. In the case of memory operations, it informs the
241 * LSQ to execute the instructions. Also handles any redirects that occur
242 * due to the executed instructions.
243 */
244 void executeInsts();
245
246 /** Writebacks instructions. In our model, the instruction's execute()
247 * function atomically reads registers, executes, and writes registers.
248 * Thus this writeback only wakes up dependent instructions, and informs
249 * the scoreboard of registers becoming ready.
250 */
251 void writebackInsts();
252
253 /** Returns the number of valid, non-squashed instructions coming from
254 * rename to dispatch.
255 */
256 unsigned validInstsFromRename();
257
258 /** Reads the stall signals. */
259 void readStallSignals(unsigned tid);
260
261 /** Checks if any of the stall conditions are currently true. */
262 bool checkStall(unsigned tid);
263
264 /** Processes inputs and changes state accordingly. */
265 void checkSignalsAndUpdate(unsigned tid);
266
267 /** Sorts instructions coming from rename into lists separated by thread. */
268 void sortInsts();
269
270 public:
271 /** Ticks IEW stage, causing Dispatch, the IQ, the LSQ, Execute, and
272 * Writeback to run for one cycle.
273 */
274 void tick();
275
276 private:
277 /** Updates execution stats based on the instruction. */
278 void updateExeInstStats(DynInstPtr &inst);
279
280 /** Pointer to main time buffer used for backwards communication. */
281 TimeBuffer<TimeStruct> *timeBuffer;
282
283 /** Wire to write information heading to previous stages. */
284 typename TimeBuffer<TimeStruct>::wire toFetch;
285
286 /** Wire to get commit's output from backwards time buffer. */
287 typename TimeBuffer<TimeStruct>::wire fromCommit;
288
289 /** Wire to write information heading to previous stages. */
290 typename TimeBuffer<TimeStruct>::wire toRename;
291
292 /** Rename instruction queue interface. */
293 TimeBuffer<RenameStruct> *renameQueue;
294
295 /** Wire to get rename's output from rename queue. */
296 typename TimeBuffer<RenameStruct>::wire fromRename;
297
298 /** Issue stage queue. */
299 TimeBuffer<IssueStruct> issueToExecQueue;
300
301 /** Wire to read information from the issue stage time queue. */
302 typename TimeBuffer<IssueStruct>::wire fromIssue;
303
304 /**
305 * IEW stage time buffer. Holds ROB indices of instructions that
306 * can be marked as completed.
307 */
308 TimeBuffer<IEWStruct> *iewQueue;
309
310 /** Wire to write infromation heading to commit. */
311 typename TimeBuffer<IEWStruct>::wire toCommit;
312
313 /** Queue of all instructions coming from rename this cycle. */
314 std::queue<DynInstPtr> insts[Impl::MaxThreads];
315
316 /** Skid buffer between rename and IEW. */
317 std::queue<DynInstPtr> skidBuffer[Impl::MaxThreads];
318
319 /** Scoreboard pointer. */
320 Scoreboard* scoreboard;
321
322 public:
323 /** Instruction queue. */
324 IQ instQueue;
325
326 /** Load / store queue. */
327 LSQ ldstQueue;
328
329 /** Pointer to the functional unit pool. */
330 FUPool *fuPool;
331
332 private:
333 /** CPU pointer. */
334 FullCPU *cpu;
335
336 /** Records if IEW has written to the time buffer this cycle, so that the
337 * CPU can deschedule itself if there is no activity.
338 */
339 bool wroteToTimeBuffer;
340
341 /** Source of possible stalls. */
342 struct Stalls {
343 bool commit;
344 };
345
346 /** Stages that are telling IEW to stall. */
347 Stalls stalls[Impl::MaxThreads];
348
349 /** Debug function to print instructions that are issued this cycle. */
350 void printAvailableInsts();
351
352 public:
353 /** Records if the LSQ needs to be updated on the next cycle, so that
354 * IEW knows if there will be activity on the next cycle.
355 */
356 bool updateLSQNextCycle;
357
358 private:
359 /** Records if there is a fetch redirect on this cycle for each thread. */
360 bool fetchRedirect[Impl::MaxThreads];
361
362 /** Used to track if all instructions have been dispatched this cycle.
363 * If they have not, then blocking must have occurred, and the instructions
364 * would already be added to the skid buffer.
365 * @todo: Fix this hack.
366 */
367 bool dispatchedAllInsts;
368
369 /** Records if the queues have been changed (inserted or issued insts),
370 * so that IEW knows to broadcast the updated amount of free entries.
371 */
372 bool updatedQueues;
373
374 /** Commit to IEW delay, in ticks. */
375 unsigned commitToIEWDelay;
376
377 /** Rename to IEW delay, in ticks. */
378 unsigned renameToIEWDelay;
379
380 /**
381 * Issue to execute delay, in ticks. What this actually represents is
382 * the amount of time it takes for an instruction to wake up, be
383 * scheduled, and sent to a FU for execution.
384 */
385 unsigned issueToExecuteDelay;
386
387 /** Width of issue's read path, in instructions. The read path is both
388 * the skid buffer and the rename instruction queue.
389 * Note to self: is this really different than issueWidth?
390 */
391 unsigned issueReadWidth;
392
393 /** Width of issue, in instructions. */
394 unsigned issueWidth;
395
396 /** Width of execute, in instructions. Might make more sense to break
397 * down into FP vs int.
398 */
399 unsigned executeWidth;
400
401 /** Index into queue of instructions being written back. */
402 unsigned wbNumInst;
403
404 /** Cycle number within the queue of instructions being written back.
405 * Used in case there are too many instructions writing back at the current
406 * cycle and writesbacks need to be scheduled for the future. See comments
407 * in instToCommit().
408 */
409 unsigned wbCycle;
410
411 /** Number of active threads. */
412 unsigned numThreads;
413
414 /** Pointer to list of active threads. */
415 std::list<unsigned> *activeThreads;
416
417 /** Maximum size of the skid buffer. */
418 unsigned skidBufferMax;
419
420 /** Is this stage switched out. */
421 bool switchedOut;
422
423 /** Stat for total number of idle cycles. */
424 Stats::Scalar<> iewIdleCycles;
425 /** Stat for total number of squashing cycles. */
426 Stats::Scalar<> iewSquashCycles;
427 /** Stat for total number of blocking cycles. */
428 Stats::Scalar<> iewBlockCycles;
429 /** Stat for total number of unblocking cycles. */
430 Stats::Scalar<> iewUnblockCycles;
431 /** Stat for total number of instructions dispatched. */
432 Stats::Scalar<> iewDispatchedInsts;
433 /** Stat for total number of squashed instructions dispatch skips. */
434 Stats::Scalar<> iewDispSquashedInsts;
435 /** Stat for total number of dispatched load instructions. */
436 Stats::Scalar<> iewDispLoadInsts;
437 /** Stat for total number of dispatched store instructions. */
438 Stats::Scalar<> iewDispStoreInsts;
439 /** Stat for total number of dispatched non speculative instructions. */
440 Stats::Scalar<> iewDispNonSpecInsts;
441 /** Stat for number of times the IQ becomes full. */
442 Stats::Scalar<> iewIQFullEvents;
443 /** Stat for number of times the LSQ becomes full. */
444 Stats::Scalar<> iewLSQFullEvents;
445 /** Stat for total number of executed instructions. */
446 Stats::Scalar<> iewExecutedInsts;
447 /** Stat for total number of executed load instructions. */
448 Stats::Vector<> iewExecLoadInsts;
449 /** Stat for total number of executed store instructions. */
450// Stats::Scalar<> iewExecStoreInsts;
451 /** Stat for total number of squashed instructions skipped at execute. */
452 Stats::Scalar<> iewExecSquashedInsts;
453 /** Stat for total number of memory ordering violation events. */
454 Stats::Scalar<> memOrderViolationEvents;
455 /** Stat for total number of incorrect predicted taken branches. */
456 Stats::Scalar<> predictedTakenIncorrect;
457 /** Stat for total number of incorrect predicted not taken branches. */
458 Stats::Scalar<> predictedNotTakenIncorrect;
459 /** Stat for total number of mispredicted branches detected at execute. */
460 Stats::Formula branchMispredicts;
461
462 /** Number of executed software prefetches. */
463 Stats::Vector<> exeSwp;
464 /** Number of executed nops. */
465 Stats::Vector<> exeNop;
466 /** Number of executed meomory references. */
467 Stats::Vector<> exeRefs;
468 /** Number of executed branches. */
469 Stats::Vector<> exeBranches;
470
471// Stats::Vector<> issued_ops;
472/*
473 Stats::Vector<> stat_fu_busy;
474 Stats::Vector2d<> stat_fuBusy;
475 Stats::Vector<> dist_unissued;
476 Stats::Vector2d<> stat_issued_inst_type;
477*/
478 /** Number of instructions issued per cycle. */
479 Stats::Formula issueRate;
480 /** Number of executed store instructions. */
481 Stats::Formula iewExecStoreInsts;
482// Stats::Formula issue_op_rate;
483// Stats::Formula fu_busy_rate;
484 /** Number of instructions sent to commit. */
485 Stats::Vector<> iewInstsToCommit;
486 /** Number of instructions that writeback. */
487 Stats::Vector<> writebackCount;
488 /** Number of instructions that wake consumers. */
489 Stats::Vector<> producerInst;
490 /** Number of instructions that wake up from producers. */
491 Stats::Vector<> consumerInst;
492 /** Number of instructions that were delayed in writing back due
493 * to resource contention.
494 */
495 Stats::Vector<> wbPenalized;
496
497 /** Number of instructions per cycle written back. */
498 Stats::Formula wbRate;
499 /** Average number of woken instructions per writeback. */
500 Stats::Formula wbFanout;
501 /** Number of instructions per cycle delayed in writing back . */
502 Stats::Formula wbPenalizedRate;
503};
504
505#endif // __CPU_O3_IEW_HH__
158 /** Squashes instructions in IEW for a specific thread. */
159 void squash(unsigned tid);
160
161 /** Wakes all dependents of a completed instruction. */
162 void wakeDependents(DynInstPtr &inst);
163
164 /** Tells memory dependence unit that a memory instruction needs to be
165 * rescheduled. It will re-execute once replayMemInst() is called.
166 */
167 void rescheduleMemInst(DynInstPtr &inst);
168
169 /** Re-executes all rescheduled memory instructions. */
170 void replayMemInst(DynInstPtr &inst);
171
172 /** Sends an instruction to commit through the time buffer. */
173 void instToCommit(DynInstPtr &inst);
174
175 /** Inserts unused instructions of a thread into the skid buffer. */
176 void skidInsert(unsigned tid);
177
178 /** Returns the max of the number of entries in all of the skid buffers. */
179 int skidCount();
180
181 /** Returns if all of the skid buffers are empty. */
182 bool skidsEmpty();
183
184 /** Updates overall IEW status based on all of the stages' statuses. */
185 void updateStatus();
186
187 /** Resets entries of the IQ and the LSQ. */
188 void resetEntries();
189
190 /** Tells the CPU to wakeup if it has descheduled itself due to no
191 * activity. Used mainly by the LdWritebackEvent.
192 */
193 void wakeCPU();
194
195 /** Reports to the CPU that there is activity this cycle. */
196 void activityThisCycle();
197
198 /** Tells CPU that the IEW stage is active and running. */
199 inline void activateStage();
200
201 /** Tells CPU that the IEW stage is inactive and idle. */
202 inline void deactivateStage();
203
204 /** Returns if the LSQ has any stores to writeback. */
205 bool hasStoresToWB() { return ldstQueue.hasStoresToWB(); }
206
207 private:
208 /** Sends commit proper information for a squash due to a branch
209 * mispredict.
210 */
211 void squashDueToBranch(DynInstPtr &inst, unsigned thread_id);
212
213 /** Sends commit proper information for a squash due to a memory order
214 * violation.
215 */
216 void squashDueToMemOrder(DynInstPtr &inst, unsigned thread_id);
217
218 /** Sends commit proper information for a squash due to memory becoming
219 * blocked (younger issued instructions must be retried).
220 */
221 void squashDueToMemBlocked(DynInstPtr &inst, unsigned thread_id);
222
223 /** Sets Dispatch to blocked, and signals back to other stages to block. */
224 void block(unsigned thread_id);
225
226 /** Unblocks Dispatch if the skid buffer is empty, and signals back to
227 * other stages to unblock.
228 */
229 void unblock(unsigned thread_id);
230
231 /** Determines proper actions to take given Dispatch's status. */
232 void dispatch(unsigned tid);
233
234 /** Dispatches instructions to IQ and LSQ. */
235 void dispatchInsts(unsigned tid);
236
237 /** Executes instructions. In the case of memory operations, it informs the
238 * LSQ to execute the instructions. Also handles any redirects that occur
239 * due to the executed instructions.
240 */
241 void executeInsts();
242
243 /** Writebacks instructions. In our model, the instruction's execute()
244 * function atomically reads registers, executes, and writes registers.
245 * Thus this writeback only wakes up dependent instructions, and informs
246 * the scoreboard of registers becoming ready.
247 */
248 void writebackInsts();
249
250 /** Returns the number of valid, non-squashed instructions coming from
251 * rename to dispatch.
252 */
253 unsigned validInstsFromRename();
254
255 /** Reads the stall signals. */
256 void readStallSignals(unsigned tid);
257
258 /** Checks if any of the stall conditions are currently true. */
259 bool checkStall(unsigned tid);
260
261 /** Processes inputs and changes state accordingly. */
262 void checkSignalsAndUpdate(unsigned tid);
263
264 /** Sorts instructions coming from rename into lists separated by thread. */
265 void sortInsts();
266
267 public:
268 /** Ticks IEW stage, causing Dispatch, the IQ, the LSQ, Execute, and
269 * Writeback to run for one cycle.
270 */
271 void tick();
272
273 private:
274 /** Updates execution stats based on the instruction. */
275 void updateExeInstStats(DynInstPtr &inst);
276
277 /** Pointer to main time buffer used for backwards communication. */
278 TimeBuffer<TimeStruct> *timeBuffer;
279
280 /** Wire to write information heading to previous stages. */
281 typename TimeBuffer<TimeStruct>::wire toFetch;
282
283 /** Wire to get commit's output from backwards time buffer. */
284 typename TimeBuffer<TimeStruct>::wire fromCommit;
285
286 /** Wire to write information heading to previous stages. */
287 typename TimeBuffer<TimeStruct>::wire toRename;
288
289 /** Rename instruction queue interface. */
290 TimeBuffer<RenameStruct> *renameQueue;
291
292 /** Wire to get rename's output from rename queue. */
293 typename TimeBuffer<RenameStruct>::wire fromRename;
294
295 /** Issue stage queue. */
296 TimeBuffer<IssueStruct> issueToExecQueue;
297
298 /** Wire to read information from the issue stage time queue. */
299 typename TimeBuffer<IssueStruct>::wire fromIssue;
300
301 /**
302 * IEW stage time buffer. Holds ROB indices of instructions that
303 * can be marked as completed.
304 */
305 TimeBuffer<IEWStruct> *iewQueue;
306
307 /** Wire to write infromation heading to commit. */
308 typename TimeBuffer<IEWStruct>::wire toCommit;
309
310 /** Queue of all instructions coming from rename this cycle. */
311 std::queue<DynInstPtr> insts[Impl::MaxThreads];
312
313 /** Skid buffer between rename and IEW. */
314 std::queue<DynInstPtr> skidBuffer[Impl::MaxThreads];
315
316 /** Scoreboard pointer. */
317 Scoreboard* scoreboard;
318
319 public:
320 /** Instruction queue. */
321 IQ instQueue;
322
323 /** Load / store queue. */
324 LSQ ldstQueue;
325
326 /** Pointer to the functional unit pool. */
327 FUPool *fuPool;
328
329 private:
330 /** CPU pointer. */
331 FullCPU *cpu;
332
333 /** Records if IEW has written to the time buffer this cycle, so that the
334 * CPU can deschedule itself if there is no activity.
335 */
336 bool wroteToTimeBuffer;
337
338 /** Source of possible stalls. */
339 struct Stalls {
340 bool commit;
341 };
342
343 /** Stages that are telling IEW to stall. */
344 Stalls stalls[Impl::MaxThreads];
345
346 /** Debug function to print instructions that are issued this cycle. */
347 void printAvailableInsts();
348
349 public:
350 /** Records if the LSQ needs to be updated on the next cycle, so that
351 * IEW knows if there will be activity on the next cycle.
352 */
353 bool updateLSQNextCycle;
354
355 private:
356 /** Records if there is a fetch redirect on this cycle for each thread. */
357 bool fetchRedirect[Impl::MaxThreads];
358
359 /** Used to track if all instructions have been dispatched this cycle.
360 * If they have not, then blocking must have occurred, and the instructions
361 * would already be added to the skid buffer.
362 * @todo: Fix this hack.
363 */
364 bool dispatchedAllInsts;
365
366 /** Records if the queues have been changed (inserted or issued insts),
367 * so that IEW knows to broadcast the updated amount of free entries.
368 */
369 bool updatedQueues;
370
371 /** Commit to IEW delay, in ticks. */
372 unsigned commitToIEWDelay;
373
374 /** Rename to IEW delay, in ticks. */
375 unsigned renameToIEWDelay;
376
377 /**
378 * Issue to execute delay, in ticks. What this actually represents is
379 * the amount of time it takes for an instruction to wake up, be
380 * scheduled, and sent to a FU for execution.
381 */
382 unsigned issueToExecuteDelay;
383
384 /** Width of issue's read path, in instructions. The read path is both
385 * the skid buffer and the rename instruction queue.
386 * Note to self: is this really different than issueWidth?
387 */
388 unsigned issueReadWidth;
389
390 /** Width of issue, in instructions. */
391 unsigned issueWidth;
392
393 /** Width of execute, in instructions. Might make more sense to break
394 * down into FP vs int.
395 */
396 unsigned executeWidth;
397
398 /** Index into queue of instructions being written back. */
399 unsigned wbNumInst;
400
401 /** Cycle number within the queue of instructions being written back.
402 * Used in case there are too many instructions writing back at the current
403 * cycle and writesbacks need to be scheduled for the future. See comments
404 * in instToCommit().
405 */
406 unsigned wbCycle;
407
408 /** Number of active threads. */
409 unsigned numThreads;
410
411 /** Pointer to list of active threads. */
412 std::list<unsigned> *activeThreads;
413
414 /** Maximum size of the skid buffer. */
415 unsigned skidBufferMax;
416
417 /** Is this stage switched out. */
418 bool switchedOut;
419
420 /** Stat for total number of idle cycles. */
421 Stats::Scalar<> iewIdleCycles;
422 /** Stat for total number of squashing cycles. */
423 Stats::Scalar<> iewSquashCycles;
424 /** Stat for total number of blocking cycles. */
425 Stats::Scalar<> iewBlockCycles;
426 /** Stat for total number of unblocking cycles. */
427 Stats::Scalar<> iewUnblockCycles;
428 /** Stat for total number of instructions dispatched. */
429 Stats::Scalar<> iewDispatchedInsts;
430 /** Stat for total number of squashed instructions dispatch skips. */
431 Stats::Scalar<> iewDispSquashedInsts;
432 /** Stat for total number of dispatched load instructions. */
433 Stats::Scalar<> iewDispLoadInsts;
434 /** Stat for total number of dispatched store instructions. */
435 Stats::Scalar<> iewDispStoreInsts;
436 /** Stat for total number of dispatched non speculative instructions. */
437 Stats::Scalar<> iewDispNonSpecInsts;
438 /** Stat for number of times the IQ becomes full. */
439 Stats::Scalar<> iewIQFullEvents;
440 /** Stat for number of times the LSQ becomes full. */
441 Stats::Scalar<> iewLSQFullEvents;
442 /** Stat for total number of executed instructions. */
443 Stats::Scalar<> iewExecutedInsts;
444 /** Stat for total number of executed load instructions. */
445 Stats::Vector<> iewExecLoadInsts;
446 /** Stat for total number of executed store instructions. */
447// Stats::Scalar<> iewExecStoreInsts;
448 /** Stat for total number of squashed instructions skipped at execute. */
449 Stats::Scalar<> iewExecSquashedInsts;
450 /** Stat for total number of memory ordering violation events. */
451 Stats::Scalar<> memOrderViolationEvents;
452 /** Stat for total number of incorrect predicted taken branches. */
453 Stats::Scalar<> predictedTakenIncorrect;
454 /** Stat for total number of incorrect predicted not taken branches. */
455 Stats::Scalar<> predictedNotTakenIncorrect;
456 /** Stat for total number of mispredicted branches detected at execute. */
457 Stats::Formula branchMispredicts;
458
459 /** Number of executed software prefetches. */
460 Stats::Vector<> exeSwp;
461 /** Number of executed nops. */
462 Stats::Vector<> exeNop;
463 /** Number of executed meomory references. */
464 Stats::Vector<> exeRefs;
465 /** Number of executed branches. */
466 Stats::Vector<> exeBranches;
467
468// Stats::Vector<> issued_ops;
469/*
470 Stats::Vector<> stat_fu_busy;
471 Stats::Vector2d<> stat_fuBusy;
472 Stats::Vector<> dist_unissued;
473 Stats::Vector2d<> stat_issued_inst_type;
474*/
475 /** Number of instructions issued per cycle. */
476 Stats::Formula issueRate;
477 /** Number of executed store instructions. */
478 Stats::Formula iewExecStoreInsts;
479// Stats::Formula issue_op_rate;
480// Stats::Formula fu_busy_rate;
481 /** Number of instructions sent to commit. */
482 Stats::Vector<> iewInstsToCommit;
483 /** Number of instructions that writeback. */
484 Stats::Vector<> writebackCount;
485 /** Number of instructions that wake consumers. */
486 Stats::Vector<> producerInst;
487 /** Number of instructions that wake up from producers. */
488 Stats::Vector<> consumerInst;
489 /** Number of instructions that were delayed in writing back due
490 * to resource contention.
491 */
492 Stats::Vector<> wbPenalized;
493
494 /** Number of instructions per cycle written back. */
495 Stats::Formula wbRate;
496 /** Average number of woken instructions per writeback. */
497 Stats::Formula wbFanout;
498 /** Number of instructions per cycle delayed in writing back . */
499 Stats::Formula wbPenalizedRate;
500};
501
502#endif // __CPU_O3_IEW_HH__