rob.hh revision 9954
11689SN/A/* 29444SAndreas.Sandberg@ARM.com * Copyright (c) 2012 ARM Limited 39444SAndreas.Sandberg@ARM.com * All rights reserved 49444SAndreas.Sandberg@ARM.com * 59444SAndreas.Sandberg@ARM.com * The license below extends only to copyright in the software and shall 69444SAndreas.Sandberg@ARM.com * not be construed as granting a license to any other intellectual 79444SAndreas.Sandberg@ARM.com * property including but not limited to intellectual property relating 89444SAndreas.Sandberg@ARM.com * to a hardware implementation of the functionality of the software 99444SAndreas.Sandberg@ARM.com * licensed hereunder. You may use the software subject to the license 109444SAndreas.Sandberg@ARM.com * terms below provided that you ensure that this notice is replicated 119444SAndreas.Sandberg@ARM.com * unmodified and in its entirety in all distributions of the software, 129444SAndreas.Sandberg@ARM.com * modified or unmodified, in source code or in binary form. 139444SAndreas.Sandberg@ARM.com * 142329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 271689SN/A * 281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 412831Sksewell@umich.edu * Korey Sewell 421689SN/A */ 431689SN/A 442292SN/A#ifndef __CPU_O3_ROB_HH__ 452292SN/A#define __CPU_O3_ROB_HH__ 461060SN/A 472292SN/A#include <string> 481461SN/A#include <utility> 491461SN/A#include <vector> 501060SN/A 518230Snate@binkert.org#include "arch/registers.hh" 528230Snate@binkert.org#include "base/types.hh" 536658Snate@binkert.org#include "config/the_isa.hh" 546658Snate@binkert.org 559954SFaissal.Sleiman@arm.comstruct DerivO3CPUParams; 569954SFaissal.Sleiman@arm.com 571060SN/A/** 582292SN/A * ROB class. The ROB is largely what drives squashing. 591060SN/A */ 601061SN/Atemplate <class Impl> 611060SN/Aclass ROB 621060SN/A{ 632107SN/A protected: 642107SN/A typedef TheISA::RegIndex RegIndex; 651060SN/A public: 661060SN/A //Typedefs from the Impl. 672733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 681061SN/A typedef typename Impl::DynInstPtr DynInstPtr; 691060SN/A 702292SN/A typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo; 712292SN/A typedef typename std::list<DynInstPtr>::iterator InstIt; 722292SN/A 732292SN/A /** Possible ROB statuses. */ 742292SN/A enum Status { 752292SN/A Running, 762292SN/A Idle, 772329SN/A ROBSquashing 782292SN/A }; 792292SN/A 802292SN/A /** SMT ROB Sharing Policy */ 812292SN/A enum ROBPolicy{ 822292SN/A Dynamic, 832292SN/A Partitioned, 842292SN/A Threshold 852292SN/A }; 862292SN/A 872292SN/A private: 882292SN/A /** Per-thread ROB status. */ 892292SN/A Status robStatus[Impl::MaxThreads]; 902292SN/A 912292SN/A /** ROB resource sharing policy for SMT mode. */ 922292SN/A ROBPolicy robPolicy; 931060SN/A 941060SN/A public: 951060SN/A /** ROB constructor. 969954SFaissal.Sleiman@arm.com * @param _cpu The cpu object pointer. 979954SFaissal.Sleiman@arm.com * @param params The cpu params including several ROB-specific parameters. 981060SN/A */ 999954SFaissal.Sleiman@arm.com ROB(O3CPU *_cpu, DerivO3CPUParams *params); 1002292SN/A 1012292SN/A std::string name() const; 1021060SN/A 1032292SN/A /** Sets pointer to the list of active threads. 1042292SN/A * @param at_ptr Pointer to the list of active threads. 1052292SN/A */ 1066221Snate@binkert.org void setActiveThreads(std::list<ThreadID> *at_ptr); 1072292SN/A 1089444SAndreas.Sandberg@ARM.com /** Perform sanity checks after a drain. */ 1099444SAndreas.Sandberg@ARM.com void drainSanityCheck() const; 1102307SN/A 1112348SN/A /** Takes over another CPU's thread. */ 1122307SN/A void takeOverFrom(); 1132307SN/A 1142292SN/A /** Function to insert an instruction into the ROB. Note that whatever 1152292SN/A * calls this function must ensure that there is enough space within the 1162292SN/A * ROB for the new instruction. 1171763SN/A * @param inst The instruction being inserted into the ROB. 1181060SN/A */ 1191061SN/A void insertInst(DynInstPtr &inst); 1201060SN/A 1211060SN/A /** Returns pointer to the head instruction within the ROB. There is 1221060SN/A * no guarantee as to the return value if the ROB is empty. 1231060SN/A * @retval Pointer to the DynInst that is at the head of the ROB. 1241060SN/A */ 1252329SN/A// DynInstPtr readHeadInst(); 1261060SN/A 1272292SN/A /** Returns a pointer to the head instruction of a specific thread within 1282292SN/A * the ROB. 1292292SN/A * @return Pointer to the DynInst that is at the head of the ROB. 1302292SN/A */ 1316221Snate@binkert.org DynInstPtr readHeadInst(ThreadID tid); 1321060SN/A 1338822Snilay@cs.wisc.edu /** Returns a pointer to the instruction with the given sequence if it is 1348822Snilay@cs.wisc.edu * in the ROB. 1358822Snilay@cs.wisc.edu */ 1368822Snilay@cs.wisc.edu DynInstPtr findInst(ThreadID tid, InstSeqNum squash_inst); 1378822Snilay@cs.wisc.edu 1382292SN/A /** Returns pointer to the tail instruction within the ROB. There is 1392292SN/A * no guarantee as to the return value if the ROB is empty. 1402292SN/A * @retval Pointer to the DynInst that is at the tail of the ROB. 1412292SN/A */ 1422329SN/A// DynInstPtr readTailInst(); 1431060SN/A 1442292SN/A /** Returns a pointer to the tail instruction of a specific thread within 1452292SN/A * the ROB. 1462292SN/A * @return Pointer to the DynInst that is at the tail of the ROB. 1472292SN/A */ 1486221Snate@binkert.org DynInstPtr readTailInst(ThreadID tid); 1491060SN/A 1502292SN/A /** Retires the head instruction, removing it from the ROB. */ 1512329SN/A// void retireHead(); 1522107SN/A 1532292SN/A /** Retires the head instruction of a specific thread, removing it from the 1542292SN/A * ROB. 1552292SN/A */ 1566221Snate@binkert.org void retireHead(ThreadID tid); 1572292SN/A 1582292SN/A /** Is the oldest instruction across all threads ready. */ 1592329SN/A// bool isHeadReady(); 1602107SN/A 1612292SN/A /** Is the oldest instruction across a particular thread ready. */ 1626221Snate@binkert.org bool isHeadReady(ThreadID tid); 1632292SN/A 1642292SN/A /** Is there any commitable head instruction across all threads ready. */ 1652292SN/A bool canCommit(); 1662292SN/A 1672292SN/A /** Re-adjust ROB partitioning. */ 1682292SN/A void resetEntries(); 1692292SN/A 1702292SN/A /** Number of entries needed For 'num_threads' amount of threads. */ 1716221Snate@binkert.org int entryAmount(ThreadID num_threads); 1722292SN/A 1732292SN/A /** Returns the number of total free entries in the ROB. */ 1741060SN/A unsigned numFreeEntries(); 1751060SN/A 1762292SN/A /** Returns the number of free entries in a specific ROB paritition. */ 1776221Snate@binkert.org unsigned numFreeEntries(ThreadID tid); 1782292SN/A 1792292SN/A /** Returns the maximum number of entries for a specific thread. */ 1806221Snate@binkert.org unsigned getMaxEntries(ThreadID tid) 1812292SN/A { return maxEntries[tid]; } 1822292SN/A 1832292SN/A /** Returns the number of entries being used by a specific thread. */ 1846221Snate@binkert.org unsigned getThreadEntries(ThreadID tid) 1852292SN/A { return threadEntries[tid]; } 1862292SN/A 1872292SN/A /** Returns if the ROB is full. */ 1881060SN/A bool isFull() 1891060SN/A { return numInstsInROB == numEntries; } 1901060SN/A 1912292SN/A /** Returns if a specific thread's partition is full. */ 1926221Snate@binkert.org bool isFull(ThreadID tid) 1932292SN/A { return threadEntries[tid] == numEntries; } 1942292SN/A 1952292SN/A /** Returns if the ROB is empty. */ 1969444SAndreas.Sandberg@ARM.com bool isEmpty() const 1971060SN/A { return numInstsInROB == 0; } 1981060SN/A 1992292SN/A /** Returns if a specific thread's partition is empty. */ 2009444SAndreas.Sandberg@ARM.com bool isEmpty(ThreadID tid) const 2012292SN/A { return threadEntries[tid] == 0; } 2021060SN/A 2032292SN/A /** Executes the squash, marking squashed instructions. */ 2046221Snate@binkert.org void doSquash(ThreadID tid); 2051060SN/A 2062292SN/A /** Squashes all instructions younger than the given sequence number for 2072292SN/A * the specific thread. 2082292SN/A */ 2096221Snate@binkert.org void squash(InstSeqNum squash_num, ThreadID tid); 2101060SN/A 2112292SN/A /** Updates the head instruction with the new oldest instruction. */ 2122292SN/A void updateHead(); 2131060SN/A 2142292SN/A /** Updates the tail instruction with the new youngest instruction. */ 2152292SN/A void updateTail(); 2161060SN/A 2172292SN/A /** Reads the PC of the oldest head instruction. */ 2182329SN/A// uint64_t readHeadPC(); 2191060SN/A 2202292SN/A /** Reads the PC of the head instruction of a specific thread. */ 2216221Snate@binkert.org// uint64_t readHeadPC(ThreadID tid); 2222292SN/A 2232292SN/A /** Reads the next PC of the oldest head instruction. */ 2242329SN/A// uint64_t readHeadNextPC(); 2252107SN/A 2262292SN/A /** Reads the next PC of the head instruction of a specific thread. */ 2276221Snate@binkert.org// uint64_t readHeadNextPC(ThreadID tid); 2282292SN/A 2292292SN/A /** Reads the sequence number of the oldest head instruction. */ 2302329SN/A// InstSeqNum readHeadSeqNum(); 2312107SN/A 2322292SN/A /** Reads the sequence number of the head instruction of a specific thread. 2332292SN/A */ 2346221Snate@binkert.org// InstSeqNum readHeadSeqNum(ThreadID tid); 2352292SN/A 2362292SN/A /** Reads the PC of the youngest tail instruction. */ 2372329SN/A// uint64_t readTailPC(); 2382107SN/A 2392292SN/A /** Reads the PC of the tail instruction of a specific thread. */ 2406221Snate@binkert.org// uint64_t readTailPC(ThreadID tid); 2412292SN/A 2422292SN/A /** Reads the sequence number of the youngest tail instruction. */ 2432329SN/A// InstSeqNum readTailSeqNum(); 2442107SN/A 2452292SN/A /** Reads the sequence number of tail instruction of a specific thread. */ 2466221Snate@binkert.org// InstSeqNum readTailSeqNum(ThreadID tid); 2471060SN/A 2481060SN/A /** Checks if the ROB is still in the process of squashing instructions. 2491060SN/A * @retval Whether or not the ROB is done squashing. 2501060SN/A */ 2516221Snate@binkert.org bool isDoneSquashing(ThreadID tid) const 2522292SN/A { return doneSquashing[tid]; } 2532292SN/A 2542292SN/A /** Checks if the ROB is still in the process of squashing instructions for 2552292SN/A * any thread. 2562292SN/A */ 2572292SN/A bool isDoneSquashing(); 2581060SN/A 2591060SN/A /** This is more of a debugging function than anything. Use 2601060SN/A * numInstsInROB to get the instructions in the ROB unless you are 2611060SN/A * double checking that variable. 2621060SN/A */ 2631060SN/A int countInsts(); 2641060SN/A 2652292SN/A /** This is more of a debugging function than anything. Use 2662292SN/A * threadEntries to get the instructions in the ROB unless you are 2672292SN/A * double checking that variable. 2682292SN/A */ 2696221Snate@binkert.org int countInsts(ThreadID tid); 2702292SN/A 2717897Shestness@cs.utexas.edu /** Registers statistics. */ 2727897Shestness@cs.utexas.edu void regStats(); 2737897Shestness@cs.utexas.edu 2741060SN/A private: 2759444SAndreas.Sandberg@ARM.com /** Reset the ROB state */ 2769444SAndreas.Sandberg@ARM.com void resetState(); 2779444SAndreas.Sandberg@ARM.com 2781060SN/A /** Pointer to the CPU. */ 2792733Sktlim@umich.edu O3CPU *cpu; 2801060SN/A 2812292SN/A /** Active Threads in CPU */ 2826221Snate@binkert.org std::list<ThreadID> *activeThreads; 2832292SN/A 2841061SN/A /** Number of instructions in the ROB. */ 2851060SN/A unsigned numEntries; 2861060SN/A 2872292SN/A /** Entries Per Thread */ 2882292SN/A unsigned threadEntries[Impl::MaxThreads]; 2892292SN/A 2902292SN/A /** Max Insts a Thread Can Have in the ROB */ 2912292SN/A unsigned maxEntries[Impl::MaxThreads]; 2922292SN/A 2932292SN/A /** ROB List of Instructions */ 2942292SN/A std::list<DynInstPtr> instList[Impl::MaxThreads]; 2952292SN/A 2961060SN/A /** Number of instructions that can be squashed in a single cycle. */ 2971060SN/A unsigned squashWidth; 2981060SN/A 2992292SN/A public: 3001061SN/A /** Iterator pointing to the instruction which is the last instruction 3011061SN/A * in the ROB. This may at times be invalid (ie when the ROB is empty), 3021061SN/A * however it should never be incorrect. 3031061SN/A */ 3042292SN/A InstIt tail; 3051060SN/A 3062292SN/A /** Iterator pointing to the instruction which is the first instruction in 3072292SN/A * in the ROB*/ 3082292SN/A InstIt head; 3092292SN/A 3102292SN/A private: 3111061SN/A /** Iterator used for walking through the list of instructions when 3121061SN/A * squashing. Used so that there is persistent state between cycles; 3131061SN/A * when squashing, the instructions are marked as squashed but not 3141061SN/A * immediately removed, meaning the tail iterator remains the same before 3151061SN/A * and after a squash. 3161061SN/A * This will always be set to cpu->instList.end() if it is invalid. 3171061SN/A */ 3182292SN/A InstIt squashIt[Impl::MaxThreads]; 3191060SN/A 3202292SN/A public: 3211061SN/A /** Number of instructions in the ROB. */ 3221060SN/A int numInstsInROB; 3231060SN/A 3242348SN/A /** Dummy instruction returned if there are no insts left. */ 3252292SN/A DynInstPtr dummyInst; 3262292SN/A 3272292SN/A private: 3281060SN/A /** The sequence number of the squashed instruction. */ 3292877Sksewell@umich.edu InstSeqNum squashedSeqNum[Impl::MaxThreads]; 3301060SN/A 3311060SN/A /** Is the ROB done squashing. */ 3322292SN/A bool doneSquashing[Impl::MaxThreads]; 3332292SN/A 3342292SN/A /** Number of active threads. */ 3356221Snate@binkert.org ThreadID numThreads; 3367897Shestness@cs.utexas.edu 3377897Shestness@cs.utexas.edu // The number of rob_reads 3387897Shestness@cs.utexas.edu Stats::Scalar robReads; 3397897Shestness@cs.utexas.edu // The number of rob_writes 3407897Shestness@cs.utexas.edu Stats::Scalar robWrites; 3411060SN/A}; 3421060SN/A 3432292SN/A#endif //__CPU_O3_ROB_HH__ 344