rob.hh revision 2733
11689SN/A/* 22329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 291689SN/A */ 301689SN/A 312292SN/A#ifndef __CPU_O3_ROB_HH__ 322292SN/A#define __CPU_O3_ROB_HH__ 331060SN/A 342292SN/A#include <string> 351461SN/A#include <utility> 361461SN/A#include <vector> 371060SN/A 381060SN/A/** 392292SN/A * ROB class. The ROB is largely what drives squashing. 401060SN/A */ 411061SN/Atemplate <class Impl> 421060SN/Aclass ROB 431060SN/A{ 442107SN/A protected: 452107SN/A typedef TheISA::RegIndex RegIndex; 461060SN/A public: 471060SN/A //Typedefs from the Impl. 482733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 491061SN/A typedef typename Impl::DynInstPtr DynInstPtr; 501060SN/A 512292SN/A typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo; 522292SN/A typedef typename std::list<DynInstPtr>::iterator InstIt; 532292SN/A 542292SN/A /** Possible ROB statuses. */ 552292SN/A enum Status { 562292SN/A Running, 572292SN/A Idle, 582329SN/A ROBSquashing 592292SN/A }; 602292SN/A 612292SN/A /** SMT ROB Sharing Policy */ 622292SN/A enum ROBPolicy{ 632292SN/A Dynamic, 642292SN/A Partitioned, 652292SN/A Threshold 662292SN/A }; 672292SN/A 682292SN/A private: 692292SN/A /** Per-thread ROB status. */ 702292SN/A Status robStatus[Impl::MaxThreads]; 712292SN/A 722292SN/A /** ROB resource sharing policy for SMT mode. */ 732292SN/A ROBPolicy robPolicy; 741060SN/A 751060SN/A public: 761060SN/A /** ROB constructor. 772292SN/A * @param _numEntries Number of entries in ROB. 782292SN/A * @param _squashWidth Number of instructions that can be squashed in a 792292SN/A * single cycle. 802292SN/A * @param _smtROBPolicy ROB Partitioning Scheme for SMT. 812292SN/A * @param _smtROBThreshold Max Resources(by %) a thread can have in the ROB. 822292SN/A * @param _numThreads The number of active threads. 831060SN/A */ 842292SN/A ROB(unsigned _numEntries, unsigned _squashWidth, std::string smtROBPolicy, 852292SN/A unsigned _smtROBThreshold, unsigned _numThreads); 862292SN/A 872292SN/A std::string name() const; 881060SN/A 891060SN/A /** Function to set the CPU pointer, necessary due to which object the ROB 901060SN/A * is created within. 911763SN/A * @param cpu_ptr Pointer to the implementation specific full CPU object. 921060SN/A */ 932733Sktlim@umich.edu void setCPU(O3CPU *cpu_ptr); 941060SN/A 952292SN/A /** Sets pointer to the list of active threads. 962292SN/A * @param at_ptr Pointer to the list of active threads. 972292SN/A */ 982292SN/A void setActiveThreads(std::list<unsigned>* at_ptr); 992292SN/A 1002348SN/A /** Switches out the ROB. */ 1012307SN/A void switchOut(); 1022307SN/A 1032348SN/A /** Takes over another CPU's thread. */ 1042307SN/A void takeOverFrom(); 1052307SN/A 1062292SN/A /** Function to insert an instruction into the ROB. Note that whatever 1072292SN/A * calls this function must ensure that there is enough space within the 1082292SN/A * ROB for the new instruction. 1091763SN/A * @param inst The instruction being inserted into the ROB. 1101060SN/A */ 1111061SN/A void insertInst(DynInstPtr &inst); 1121060SN/A 1131060SN/A /** Returns pointer to the head instruction within the ROB. There is 1141060SN/A * no guarantee as to the return value if the ROB is empty. 1151060SN/A * @retval Pointer to the DynInst that is at the head of the ROB. 1161060SN/A */ 1172329SN/A// DynInstPtr readHeadInst(); 1181060SN/A 1192292SN/A /** Returns a pointer to the head instruction of a specific thread within 1202292SN/A * the ROB. 1212292SN/A * @return Pointer to the DynInst that is at the head of the ROB. 1222292SN/A */ 1232292SN/A DynInstPtr readHeadInst(unsigned tid); 1241060SN/A 1252292SN/A /** Returns pointer to the tail instruction within the ROB. There is 1262292SN/A * no guarantee as to the return value if the ROB is empty. 1272292SN/A * @retval Pointer to the DynInst that is at the tail of the ROB. 1282292SN/A */ 1292329SN/A// DynInstPtr readTailInst(); 1301060SN/A 1312292SN/A /** Returns a pointer to the tail instruction of a specific thread within 1322292SN/A * the ROB. 1332292SN/A * @return Pointer to the DynInst that is at the tail of the ROB. 1342292SN/A */ 1352292SN/A DynInstPtr readTailInst(unsigned tid); 1361060SN/A 1372292SN/A /** Retires the head instruction, removing it from the ROB. */ 1382329SN/A// void retireHead(); 1392107SN/A 1402292SN/A /** Retires the head instruction of a specific thread, removing it from the 1412292SN/A * ROB. 1422292SN/A */ 1432292SN/A void retireHead(unsigned tid); 1442292SN/A 1452292SN/A /** Is the oldest instruction across all threads ready. */ 1462329SN/A// bool isHeadReady(); 1472107SN/A 1482292SN/A /** Is the oldest instruction across a particular thread ready. */ 1492292SN/A bool isHeadReady(unsigned tid); 1502292SN/A 1512292SN/A /** Is there any commitable head instruction across all threads ready. */ 1522292SN/A bool canCommit(); 1532292SN/A 1542292SN/A /** Re-adjust ROB partitioning. */ 1552292SN/A void resetEntries(); 1562292SN/A 1572292SN/A /** Number of entries needed For 'num_threads' amount of threads. */ 1582292SN/A int entryAmount(int num_threads); 1592292SN/A 1602292SN/A /** Returns the number of total free entries in the ROB. */ 1611060SN/A unsigned numFreeEntries(); 1621060SN/A 1632292SN/A /** Returns the number of free entries in a specific ROB paritition. */ 1642292SN/A unsigned numFreeEntries(unsigned tid); 1652292SN/A 1662292SN/A /** Returns the maximum number of entries for a specific thread. */ 1672292SN/A unsigned getMaxEntries(unsigned tid) 1682292SN/A { return maxEntries[tid]; } 1692292SN/A 1702292SN/A /** Returns the number of entries being used by a specific thread. */ 1712292SN/A unsigned getThreadEntries(unsigned tid) 1722292SN/A { return threadEntries[tid]; } 1732292SN/A 1742292SN/A /** Returns if the ROB is full. */ 1751060SN/A bool isFull() 1761060SN/A { return numInstsInROB == numEntries; } 1771060SN/A 1782292SN/A /** Returns if a specific thread's partition is full. */ 1792292SN/A bool isFull(unsigned tid) 1802292SN/A { return threadEntries[tid] == numEntries; } 1812292SN/A 1822292SN/A /** Returns if the ROB is empty. */ 1831060SN/A bool isEmpty() 1841060SN/A { return numInstsInROB == 0; } 1851060SN/A 1862292SN/A /** Returns if a specific thread's partition is empty. */ 1872292SN/A bool isEmpty(unsigned tid) 1882292SN/A { return threadEntries[tid] == 0; } 1891060SN/A 1902292SN/A /** Executes the squash, marking squashed instructions. */ 1912292SN/A void doSquash(unsigned tid); 1921060SN/A 1932292SN/A /** Squashes all instructions younger than the given sequence number for 1942292SN/A * the specific thread. 1952292SN/A */ 1962292SN/A void squash(InstSeqNum squash_num, unsigned tid); 1971060SN/A 1982292SN/A /** Updates the head instruction with the new oldest instruction. */ 1992292SN/A void updateHead(); 2001060SN/A 2012292SN/A /** Updates the tail instruction with the new youngest instruction. */ 2022292SN/A void updateTail(); 2031060SN/A 2042292SN/A /** Reads the PC of the oldest head instruction. */ 2052329SN/A// uint64_t readHeadPC(); 2061060SN/A 2072292SN/A /** Reads the PC of the head instruction of a specific thread. */ 2082329SN/A// uint64_t readHeadPC(unsigned tid); 2092292SN/A 2102292SN/A /** Reads the next PC of the oldest head instruction. */ 2112329SN/A// uint64_t readHeadNextPC(); 2122107SN/A 2132292SN/A /** Reads the next PC of the head instruction of a specific thread. */ 2142329SN/A// uint64_t readHeadNextPC(unsigned tid); 2152292SN/A 2162292SN/A /** Reads the sequence number of the oldest head instruction. */ 2172329SN/A// InstSeqNum readHeadSeqNum(); 2182107SN/A 2192292SN/A /** Reads the sequence number of the head instruction of a specific thread. 2202292SN/A */ 2212329SN/A// InstSeqNum readHeadSeqNum(unsigned tid); 2222292SN/A 2232292SN/A /** Reads the PC of the youngest tail instruction. */ 2242329SN/A// uint64_t readTailPC(); 2252107SN/A 2262292SN/A /** Reads the PC of the tail instruction of a specific thread. */ 2272329SN/A// uint64_t readTailPC(unsigned tid); 2282292SN/A 2292292SN/A /** Reads the sequence number of the youngest tail instruction. */ 2302329SN/A// InstSeqNum readTailSeqNum(); 2312107SN/A 2322292SN/A /** Reads the sequence number of tail instruction of a specific thread. */ 2332329SN/A// InstSeqNum readTailSeqNum(unsigned tid); 2341060SN/A 2351060SN/A /** Checks if the ROB is still in the process of squashing instructions. 2361060SN/A * @retval Whether or not the ROB is done squashing. 2371060SN/A */ 2382292SN/A bool isDoneSquashing(unsigned tid) const 2392292SN/A { return doneSquashing[tid]; } 2402292SN/A 2412292SN/A /** Checks if the ROB is still in the process of squashing instructions for 2422292SN/A * any thread. 2432292SN/A */ 2442292SN/A bool isDoneSquashing(); 2451060SN/A 2461060SN/A /** This is more of a debugging function than anything. Use 2471060SN/A * numInstsInROB to get the instructions in the ROB unless you are 2481060SN/A * double checking that variable. 2491060SN/A */ 2501060SN/A int countInsts(); 2511060SN/A 2522292SN/A /** This is more of a debugging function than anything. Use 2532292SN/A * threadEntries to get the instructions in the ROB unless you are 2542292SN/A * double checking that variable. 2552292SN/A */ 2562292SN/A int countInsts(unsigned tid); 2572292SN/A 2581060SN/A private: 2591060SN/A /** Pointer to the CPU. */ 2602733Sktlim@umich.edu O3CPU *cpu; 2611060SN/A 2622292SN/A /** Active Threads in CPU */ 2632292SN/A std::list<unsigned>* activeThreads; 2642292SN/A 2651061SN/A /** Number of instructions in the ROB. */ 2661060SN/A unsigned numEntries; 2671060SN/A 2682292SN/A /** Entries Per Thread */ 2692292SN/A unsigned threadEntries[Impl::MaxThreads]; 2702292SN/A 2712292SN/A /** Max Insts a Thread Can Have in the ROB */ 2722292SN/A unsigned maxEntries[Impl::MaxThreads]; 2732292SN/A 2742292SN/A /** ROB List of Instructions */ 2752292SN/A std::list<DynInstPtr> instList[Impl::MaxThreads]; 2762292SN/A 2771060SN/A /** Number of instructions that can be squashed in a single cycle. */ 2781060SN/A unsigned squashWidth; 2791060SN/A 2802292SN/A public: 2811061SN/A /** Iterator pointing to the instruction which is the last instruction 2821061SN/A * in the ROB. This may at times be invalid (ie when the ROB is empty), 2831061SN/A * however it should never be incorrect. 2841061SN/A */ 2852292SN/A InstIt tail; 2861060SN/A 2872292SN/A /** Iterator pointing to the instruction which is the first instruction in 2882292SN/A * in the ROB*/ 2892292SN/A InstIt head; 2902292SN/A 2912292SN/A private: 2921061SN/A /** Iterator used for walking through the list of instructions when 2931061SN/A * squashing. Used so that there is persistent state between cycles; 2941061SN/A * when squashing, the instructions are marked as squashed but not 2951061SN/A * immediately removed, meaning the tail iterator remains the same before 2961061SN/A * and after a squash. 2971061SN/A * This will always be set to cpu->instList.end() if it is invalid. 2981061SN/A */ 2992292SN/A InstIt squashIt[Impl::MaxThreads]; 3001060SN/A 3012292SN/A public: 3021061SN/A /** Number of instructions in the ROB. */ 3031060SN/A int numInstsInROB; 3041060SN/A 3052348SN/A /** Dummy instruction returned if there are no insts left. */ 3062292SN/A DynInstPtr dummyInst; 3072292SN/A 3082292SN/A private: 3091060SN/A /** The sequence number of the squashed instruction. */ 3101060SN/A InstSeqNum squashedSeqNum; 3111060SN/A 3121060SN/A /** Is the ROB done squashing. */ 3132292SN/A bool doneSquashing[Impl::MaxThreads]; 3142292SN/A 3152292SN/A /** Number of active threads. */ 3162292SN/A unsigned numThreads; 3171060SN/A}; 3181060SN/A 3192292SN/A#endif //__CPU_O3_ROB_HH__ 320