2 * Copyright (c) 2012 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2004-2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #ifndef __CPU_O3_ROB_HH__
42 #define __CPU_O3_ROB_HH__
48 #include "arch/registers.hh"
49 #include "base/types.hh"
50 #include "config/the_isa.hh"
51 #include "enums/SMTQueuePolicy.hh"
53 struct DerivO3CPUParams;
56 * ROB class. The ROB is largely what drives squashing.
62 //Typedefs from the Impl.
63 typedef typename Impl::O3CPU O3CPU;
64 typedef typename Impl::DynInstPtr DynInstPtr;
66 typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo;
67 typedef typename std::list<DynInstPtr>::iterator InstIt;
69 /** Possible ROB statuses. */
77 /** Per-thread ROB status. */
78 Status robStatus[Impl::MaxThreads];
80 /** ROB resource sharing policy for SMT mode. */
81 SMTQueuePolicy robPolicy;
85 * @param _cpu The cpu object pointer.
86 * @param params The cpu params including several ROB-specific parameters.
88 ROB(O3CPU *_cpu, DerivO3CPUParams *params);
90 std::string name() const;
92 /** Sets pointer to the list of active threads.
93 * @param at_ptr Pointer to the list of active threads.
95 void setActiveThreads(std::list<ThreadID> *at_ptr);
97 /** Perform sanity checks after a drain. */
98 void drainSanityCheck() const;
100 /** Takes over another CPU's thread. */
103 /** Function to insert an instruction into the ROB. Note that whatever
104 * calls this function must ensure that there is enough space within the
105 * ROB for the new instruction.
106 * @param inst The instruction being inserted into the ROB.
108 void insertInst(const DynInstPtr &inst);
110 /** Returns pointer to the head instruction within the ROB. There is
111 * no guarantee as to the return value if the ROB is empty.
112 * @retval Pointer to the DynInst that is at the head of the ROB.
114 // DynInstPtr readHeadInst();
116 /** Returns a pointer to the head instruction of a specific thread within
118 * @return Pointer to the DynInst that is at the head of the ROB.
120 const DynInstPtr &readHeadInst(ThreadID tid);
122 /** Returns a pointer to the instruction with the given sequence if it is
125 DynInstPtr findInst(ThreadID tid, InstSeqNum squash_inst);
127 /** Returns pointer to the tail instruction within the ROB. There is
128 * no guarantee as to the return value if the ROB is empty.
129 * @retval Pointer to the DynInst that is at the tail of the ROB.
131 // DynInstPtr readTailInst();
133 /** Returns a pointer to the tail instruction of a specific thread within
135 * @return Pointer to the DynInst that is at the tail of the ROB.
137 DynInstPtr readTailInst(ThreadID tid);
139 /** Retires the head instruction, removing it from the ROB. */
140 // void retireHead();
142 /** Retires the head instruction of a specific thread, removing it from the
145 void retireHead(ThreadID tid);
147 /** Is the oldest instruction across all threads ready. */
148 // bool isHeadReady();
150 /** Is the oldest instruction across a particular thread ready. */
151 bool isHeadReady(ThreadID tid);
153 /** Is there any commitable head instruction across all threads ready. */
156 /** Re-adjust ROB partitioning. */
159 /** Number of entries needed For 'num_threads' amount of threads. */
160 int entryAmount(ThreadID num_threads);
162 /** Returns the number of total free entries in the ROB. */
163 unsigned numFreeEntries();
165 /** Returns the number of free entries in a specific ROB paritition. */
166 unsigned numFreeEntries(ThreadID tid);
168 /** Returns the maximum number of entries for a specific thread. */
169 unsigned getMaxEntries(ThreadID tid)
170 { return maxEntries[tid]; }
172 /** Returns the number of entries being used by a specific thread. */
173 unsigned getThreadEntries(ThreadID tid)
174 { return threadEntries[tid]; }
176 /** Returns if the ROB is full. */
178 { return numInstsInROB == numEntries; }
180 /** Returns if a specific thread's partition is full. */
181 bool isFull(ThreadID tid)
182 { return threadEntries[tid] == numEntries; }
184 /** Returns if the ROB is empty. */
186 { return numInstsInROB == 0; }
188 /** Returns if a specific thread's partition is empty. */
189 bool isEmpty(ThreadID tid) const
190 { return threadEntries[tid] == 0; }
192 /** Executes the squash, marking squashed instructions. */
193 void doSquash(ThreadID tid);
195 /** Squashes all instructions younger than the given sequence number for
196 * the specific thread.
198 void squash(InstSeqNum squash_num, ThreadID tid);
200 /** Updates the head instruction with the new oldest instruction. */
203 /** Updates the tail instruction with the new youngest instruction. */
206 /** Reads the PC of the oldest head instruction. */
207 // uint64_t readHeadPC();
209 /** Reads the PC of the head instruction of a specific thread. */
210 // uint64_t readHeadPC(ThreadID tid);
212 /** Reads the next PC of the oldest head instruction. */
213 // uint64_t readHeadNextPC();
215 /** Reads the next PC of the head instruction of a specific thread. */
216 // uint64_t readHeadNextPC(ThreadID tid);
218 /** Reads the sequence number of the oldest head instruction. */
219 // InstSeqNum readHeadSeqNum();
221 /** Reads the sequence number of the head instruction of a specific thread.
223 // InstSeqNum readHeadSeqNum(ThreadID tid);
225 /** Reads the PC of the youngest tail instruction. */
226 // uint64_t readTailPC();
228 /** Reads the PC of the tail instruction of a specific thread. */
229 // uint64_t readTailPC(ThreadID tid);
231 /** Reads the sequence number of the youngest tail instruction. */
232 // InstSeqNum readTailSeqNum();
234 /** Reads the sequence number of tail instruction of a specific thread. */
235 // InstSeqNum readTailSeqNum(ThreadID tid);
237 /** Checks if the ROB is still in the process of squashing instructions.
238 * @retval Whether or not the ROB is done squashing.
240 bool isDoneSquashing(ThreadID tid) const
241 { return doneSquashing[tid]; }
243 /** Checks if the ROB is still in the process of squashing instructions for
246 bool isDoneSquashing();
248 /** This is more of a debugging function than anything. Use
249 * numInstsInROB to get the instructions in the ROB unless you are
250 * double checking that variable.
254 /** This is more of a debugging function than anything. Use
255 * threadEntries to get the instructions in the ROB unless you are
256 * double checking that variable.
258 size_t countInsts(ThreadID tid);
261 /** Reset the ROB state */
264 /** Pointer to the CPU. */
267 /** Active Threads in CPU */
268 std::list<ThreadID> *activeThreads;
270 /** Number of instructions in the ROB. */
273 /** Entries Per Thread */
274 unsigned threadEntries[Impl::MaxThreads];
276 /** Max Insts a Thread Can Have in the ROB */
277 unsigned maxEntries[Impl::MaxThreads];
279 /** ROB List of Instructions */
280 std::list<DynInstPtr> instList[Impl::MaxThreads];
282 /** Number of instructions that can be squashed in a single cycle. */
283 unsigned squashWidth;
286 /** Iterator pointing to the instruction which is the last instruction
287 * in the ROB. This may at times be invalid (ie when the ROB is empty),
288 * however it should never be incorrect.
292 /** Iterator pointing to the instruction which is the first instruction in
297 /** Iterator used for walking through the list of instructions when
298 * squashing. Used so that there is persistent state between cycles;
299 * when squashing, the instructions are marked as squashed but not
300 * immediately removed, meaning the tail iterator remains the same before
301 * and after a squash.
302 * This will always be set to cpu->instList.end() if it is invalid.
304 InstIt squashIt[Impl::MaxThreads];
307 /** Number of instructions in the ROB. */
310 /** Dummy instruction returned if there are no insts left. */
311 DynInstPtr dummyInst;
314 /** The sequence number of the squashed instruction. */
315 InstSeqNum squashedSeqNum[Impl::MaxThreads];
317 /** Is the ROB done squashing. */
318 bool doneSquashing[Impl::MaxThreads];
320 /** Number of active threads. */
324 struct ROBStats : public Stats::Group {
325 ROBStats(Stats::Group *parent);
327 // The number of rob_reads
329 // The number of rob_writes
330 Stats::Scalar writes;
334 #endif //__CPU_O3_ROB_HH__