2 * Copyright (c) 2004-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.
32 #ifndef __CPU_O3_ROB_HH__
33 #define __CPU_O3_ROB_HH__
40 * ROB class. The ROB is largely what drives squashing.
46 typedef TheISA::RegIndex RegIndex;
48 //Typedefs from the Impl.
49 typedef typename Impl::O3CPU O3CPU;
50 typedef typename Impl::DynInstPtr DynInstPtr;
52 typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo;
53 typedef typename std::list<DynInstPtr>::iterator InstIt;
55 /** Possible ROB statuses. */
62 /** SMT ROB Sharing Policy */
70 /** Per-thread ROB status. */
71 Status robStatus[Impl::MaxThreads];
73 /** ROB resource sharing policy for SMT mode. */
78 * @param _numEntries Number of entries in ROB.
79 * @param _squashWidth Number of instructions that can be squashed in a
81 * @param _smtROBPolicy ROB Partitioning Scheme for SMT.
82 * @param _smtROBThreshold Max Resources(by %) a thread can have in the ROB.
83 * @param _numThreads The number of active threads.
85 ROB(O3CPU *_cpu, unsigned _numEntries, unsigned _squashWidth,
86 std::string smtROBPolicy, unsigned _smtROBThreshold,
87 unsigned _numThreads);
89 std::string name() const;
91 /** Sets pointer to the list of active threads.
92 * @param at_ptr Pointer to the list of active threads.
94 void setActiveThreads(std::list<unsigned>* at_ptr);
96 /** Switches out the ROB. */
99 /** Takes over another CPU's thread. */
102 /** Function to insert an instruction into the ROB. Note that whatever
103 * calls this function must ensure that there is enough space within the
104 * ROB for the new instruction.
105 * @param inst The instruction being inserted into the ROB.
107 void insertInst(DynInstPtr &inst);
109 /** Returns pointer to the head instruction within the ROB. There is
110 * no guarantee as to the return value if the ROB is empty.
111 * @retval Pointer to the DynInst that is at the head of the ROB.
113 // DynInstPtr readHeadInst();
115 /** Returns a pointer to the head instruction of a specific thread within
117 * @return Pointer to the DynInst that is at the head of the ROB.
119 DynInstPtr readHeadInst(unsigned tid);
121 /** Returns pointer to the tail instruction within the ROB. There is
122 * no guarantee as to the return value if the ROB is empty.
123 * @retval Pointer to the DynInst that is at the tail of the ROB.
125 // DynInstPtr readTailInst();
127 /** Returns a pointer to the tail instruction of a specific thread within
129 * @return Pointer to the DynInst that is at the tail of the ROB.
131 DynInstPtr readTailInst(unsigned tid);
133 /** Retires the head instruction, removing it from the ROB. */
134 // void retireHead();
136 /** Retires the head instruction of a specific thread, removing it from the
139 void retireHead(unsigned tid);
141 /** Is the oldest instruction across all threads ready. */
142 // bool isHeadReady();
144 /** Is the oldest instruction across a particular thread ready. */
145 bool isHeadReady(unsigned tid);
147 /** Is there any commitable head instruction across all threads ready. */
150 /** Re-adjust ROB partitioning. */
153 /** Number of entries needed For 'num_threads' amount of threads. */
154 int entryAmount(int num_threads);
156 /** Returns the number of total free entries in the ROB. */
157 unsigned numFreeEntries();
159 /** Returns the number of free entries in a specific ROB paritition. */
160 unsigned numFreeEntries(unsigned tid);
162 /** Returns the maximum number of entries for a specific thread. */
163 unsigned getMaxEntries(unsigned tid)
164 { return maxEntries[tid]; }
166 /** Returns the number of entries being used by a specific thread. */
167 unsigned getThreadEntries(unsigned tid)
168 { return threadEntries[tid]; }
170 /** Returns if the ROB is full. */
172 { return numInstsInROB == numEntries; }
174 /** Returns if a specific thread's partition is full. */
175 bool isFull(unsigned tid)
176 { return threadEntries[tid] == numEntries; }
178 /** Returns if the ROB is empty. */
180 { return numInstsInROB == 0; }
182 /** Returns if a specific thread's partition is empty. */
183 bool isEmpty(unsigned tid)
184 { return threadEntries[tid] == 0; }
186 /** Executes the squash, marking squashed instructions. */
187 void doSquash(unsigned tid);
189 /** Squashes all instructions younger than the given sequence number for
190 * the specific thread.
192 void squash(InstSeqNum squash_num, unsigned tid);
194 /** Updates the head instruction with the new oldest instruction. */
197 /** Updates the tail instruction with the new youngest instruction. */
200 /** Reads the PC of the oldest head instruction. */
201 // uint64_t readHeadPC();
203 /** Reads the PC of the head instruction of a specific thread. */
204 // uint64_t readHeadPC(unsigned tid);
206 /** Reads the next PC of the oldest head instruction. */
207 // uint64_t readHeadNextPC();
209 /** Reads the next PC of the head instruction of a specific thread. */
210 // uint64_t readHeadNextPC(unsigned tid);
212 /** Reads the sequence number of the oldest head instruction. */
213 // InstSeqNum readHeadSeqNum();
215 /** Reads the sequence number of the head instruction of a specific thread.
217 // InstSeqNum readHeadSeqNum(unsigned tid);
219 /** Reads the PC of the youngest tail instruction. */
220 // uint64_t readTailPC();
222 /** Reads the PC of the tail instruction of a specific thread. */
223 // uint64_t readTailPC(unsigned tid);
225 /** Reads the sequence number of the youngest tail instruction. */
226 // InstSeqNum readTailSeqNum();
228 /** Reads the sequence number of tail instruction of a specific thread. */
229 // InstSeqNum readTailSeqNum(unsigned tid);
231 /** Checks if the ROB is still in the process of squashing instructions.
232 * @retval Whether or not the ROB is done squashing.
234 bool isDoneSquashing(unsigned tid) const
235 { return doneSquashing[tid]; }
237 /** Checks if the ROB is still in the process of squashing instructions for
240 bool isDoneSquashing();
242 /** This is more of a debugging function than anything. Use
243 * numInstsInROB to get the instructions in the ROB unless you are
244 * double checking that variable.
248 /** This is more of a debugging function than anything. Use
249 * threadEntries to get the instructions in the ROB unless you are
250 * double checking that variable.
252 int countInsts(unsigned tid);
255 /** Pointer to the CPU. */
258 /** Active Threads in CPU */
259 std::list<unsigned>* activeThreads;
261 /** Number of instructions in the ROB. */
264 /** Entries Per Thread */
265 unsigned threadEntries[Impl::MaxThreads];
267 /** Max Insts a Thread Can Have in the ROB */
268 unsigned maxEntries[Impl::MaxThreads];
270 /** ROB List of Instructions */
271 std::list<DynInstPtr> instList[Impl::MaxThreads];
273 /** Number of instructions that can be squashed in a single cycle. */
274 unsigned squashWidth;
277 /** Iterator pointing to the instruction which is the last instruction
278 * in the ROB. This may at times be invalid (ie when the ROB is empty),
279 * however it should never be incorrect.
283 /** Iterator pointing to the instruction which is the first instruction in
288 /** Iterator used for walking through the list of instructions when
289 * squashing. Used so that there is persistent state between cycles;
290 * when squashing, the instructions are marked as squashed but not
291 * immediately removed, meaning the tail iterator remains the same before
292 * and after a squash.
293 * This will always be set to cpu->instList.end() if it is invalid.
295 InstIt squashIt[Impl::MaxThreads];
298 /** Number of instructions in the ROB. */
301 /** Dummy instruction returned if there are no insts left. */
302 DynInstPtr dummyInst;
305 /** The sequence number of the squashed instruction. */
306 InstSeqNum squashedSeqNum[Impl::MaxThreads];
308 /** Is the ROB done squashing. */
309 bool doneSquashing[Impl::MaxThreads];
311 /** Number of active threads. */
315 #endif //__CPU_O3_ROB_HH__