rob.hh revision 9444
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
551060SN/A/**
562292SN/A * ROB class.  The ROB is largely what drives squashing.
571060SN/A */
581061SN/Atemplate <class Impl>
591060SN/Aclass ROB
601060SN/A{
612107SN/A  protected:
622107SN/A    typedef TheISA::RegIndex RegIndex;
631060SN/A  public:
641060SN/A    //Typedefs from the Impl.
652733Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
661061SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
671060SN/A
682292SN/A    typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo;
692292SN/A    typedef typename std::list<DynInstPtr>::iterator InstIt;
702292SN/A
712292SN/A    /** Possible ROB statuses. */
722292SN/A    enum Status {
732292SN/A        Running,
742292SN/A        Idle,
752329SN/A        ROBSquashing
762292SN/A    };
772292SN/A
782292SN/A    /** SMT ROB Sharing Policy */
792292SN/A    enum ROBPolicy{
802292SN/A        Dynamic,
812292SN/A        Partitioned,
822292SN/A        Threshold
832292SN/A    };
842292SN/A
852292SN/A  private:
862292SN/A    /** Per-thread ROB status. */
872292SN/A    Status robStatus[Impl::MaxThreads];
882292SN/A
892292SN/A    /** ROB resource sharing policy for SMT mode. */
902292SN/A    ROBPolicy robPolicy;
911060SN/A
921060SN/A  public:
931060SN/A    /** ROB constructor.
942292SN/A     *  @param _numEntries      Number of entries in ROB.
952292SN/A     *  @param _squashWidth     Number of instructions that can be squashed in a
962292SN/A     *                          single cycle.
972292SN/A     *  @param _smtROBPolicy    ROB Partitioning Scheme for SMT.
982292SN/A     *  @param _smtROBThreshold Max Resources(by %) a thread can have in the ROB.
992292SN/A     *  @param _numThreads      The number of active threads.
1001060SN/A     */
1014329Sktlim@umich.edu    ROB(O3CPU *_cpu, unsigned _numEntries, unsigned _squashWidth,
1024329Sktlim@umich.edu        std::string smtROBPolicy, unsigned _smtROBThreshold,
1036221Snate@binkert.org        ThreadID _numThreads);
1042292SN/A
1052292SN/A    std::string name() const;
1061060SN/A
1072292SN/A    /** Sets pointer to the list of active threads.
1082292SN/A     *  @param at_ptr Pointer to the list of active threads.
1092292SN/A     */
1106221Snate@binkert.org    void setActiveThreads(std::list<ThreadID> *at_ptr);
1112292SN/A
1129444SAndreas.Sandberg@ARM.com    /** Perform sanity checks after a drain. */
1139444SAndreas.Sandberg@ARM.com    void drainSanityCheck() const;
1142307SN/A
1152348SN/A    /** Takes over another CPU's thread. */
1162307SN/A    void takeOverFrom();
1172307SN/A
1182292SN/A    /** Function to insert an instruction into the ROB. Note that whatever
1192292SN/A     *  calls this function must ensure that there is enough space within the
1202292SN/A     *  ROB for the new instruction.
1211763SN/A     *  @param inst The instruction being inserted into the ROB.
1221060SN/A     */
1231061SN/A    void insertInst(DynInstPtr &inst);
1241060SN/A
1251060SN/A    /** Returns pointer to the head instruction within the ROB.  There is
1261060SN/A     *  no guarantee as to the return value if the ROB is empty.
1271060SN/A     *  @retval Pointer to the DynInst that is at the head of the ROB.
1281060SN/A     */
1292329SN/A//    DynInstPtr readHeadInst();
1301060SN/A
1312292SN/A    /** Returns a pointer to the head instruction of a specific thread within
1322292SN/A     *  the ROB.
1332292SN/A     *  @return Pointer to the DynInst that is at the head of the ROB.
1342292SN/A     */
1356221Snate@binkert.org    DynInstPtr readHeadInst(ThreadID tid);
1361060SN/A
1378822Snilay@cs.wisc.edu    /** Returns a pointer to the instruction with the given sequence if it is
1388822Snilay@cs.wisc.edu     *  in the ROB.
1398822Snilay@cs.wisc.edu     */
1408822Snilay@cs.wisc.edu    DynInstPtr findInst(ThreadID tid, InstSeqNum squash_inst);
1418822Snilay@cs.wisc.edu
1422292SN/A    /** Returns pointer to the tail instruction within the ROB.  There is
1432292SN/A     *  no guarantee as to the return value if the ROB is empty.
1442292SN/A     *  @retval Pointer to the DynInst that is at the tail of the ROB.
1452292SN/A     */
1462329SN/A//    DynInstPtr readTailInst();
1471060SN/A
1482292SN/A    /** Returns a pointer to the tail instruction of a specific thread within
1492292SN/A     *  the ROB.
1502292SN/A     *  @return Pointer to the DynInst that is at the tail of the ROB.
1512292SN/A     */
1526221Snate@binkert.org    DynInstPtr readTailInst(ThreadID tid);
1531060SN/A
1542292SN/A    /** Retires the head instruction, removing it from the ROB. */
1552329SN/A//    void retireHead();
1562107SN/A
1572292SN/A    /** Retires the head instruction of a specific thread, removing it from the
1582292SN/A     *  ROB.
1592292SN/A     */
1606221Snate@binkert.org    void retireHead(ThreadID tid);
1612292SN/A
1622292SN/A    /** Is the oldest instruction across all threads ready. */
1632329SN/A//    bool isHeadReady();
1642107SN/A
1652292SN/A    /** Is the oldest instruction across a particular thread ready. */
1666221Snate@binkert.org    bool isHeadReady(ThreadID tid);
1672292SN/A
1682292SN/A    /** Is there any commitable head instruction across all threads ready. */
1692292SN/A    bool canCommit();
1702292SN/A
1712292SN/A    /** Re-adjust ROB partitioning. */
1722292SN/A    void resetEntries();
1732292SN/A
1742292SN/A    /** Number of entries needed For 'num_threads' amount of threads. */
1756221Snate@binkert.org    int entryAmount(ThreadID num_threads);
1762292SN/A
1772292SN/A    /** Returns the number of total free entries in the ROB. */
1781060SN/A    unsigned numFreeEntries();
1791060SN/A
1802292SN/A    /** Returns the number of free entries in a specific ROB paritition. */
1816221Snate@binkert.org    unsigned numFreeEntries(ThreadID tid);
1822292SN/A
1832292SN/A    /** Returns the maximum number of entries for a specific thread. */
1846221Snate@binkert.org    unsigned getMaxEntries(ThreadID tid)
1852292SN/A    { return maxEntries[tid]; }
1862292SN/A
1872292SN/A    /** Returns the number of entries being used by a specific thread. */
1886221Snate@binkert.org    unsigned getThreadEntries(ThreadID tid)
1892292SN/A    { return threadEntries[tid]; }
1902292SN/A
1912292SN/A    /** Returns if the ROB is full. */
1921060SN/A    bool isFull()
1931060SN/A    { return numInstsInROB == numEntries; }
1941060SN/A
1952292SN/A    /** Returns if a specific thread's partition is full. */
1966221Snate@binkert.org    bool isFull(ThreadID tid)
1972292SN/A    { return threadEntries[tid] == numEntries; }
1982292SN/A
1992292SN/A    /** Returns if the ROB is empty. */
2009444SAndreas.Sandberg@ARM.com    bool isEmpty() const
2011060SN/A    { return numInstsInROB == 0; }
2021060SN/A
2032292SN/A    /** Returns if a specific thread's partition is empty. */
2049444SAndreas.Sandberg@ARM.com    bool isEmpty(ThreadID tid) const
2052292SN/A    { return threadEntries[tid] == 0; }
2061060SN/A
2072292SN/A    /** Executes the squash, marking squashed instructions. */
2086221Snate@binkert.org    void doSquash(ThreadID tid);
2091060SN/A
2102292SN/A    /** Squashes all instructions younger than the given sequence number for
2112292SN/A     *  the specific thread.
2122292SN/A     */
2136221Snate@binkert.org    void squash(InstSeqNum squash_num, ThreadID tid);
2141060SN/A
2152292SN/A    /** Updates the head instruction with the new oldest instruction. */
2162292SN/A    void updateHead();
2171060SN/A
2182292SN/A    /** Updates the tail instruction with the new youngest instruction. */
2192292SN/A    void updateTail();
2201060SN/A
2212292SN/A    /** Reads the PC of the oldest head instruction. */
2222329SN/A//    uint64_t readHeadPC();
2231060SN/A
2242292SN/A    /** Reads the PC of the head instruction of a specific thread. */
2256221Snate@binkert.org//    uint64_t readHeadPC(ThreadID tid);
2262292SN/A
2272292SN/A    /** Reads the next PC of the oldest head instruction. */
2282329SN/A//    uint64_t readHeadNextPC();
2292107SN/A
2302292SN/A    /** Reads the next PC of the head instruction of a specific thread. */
2316221Snate@binkert.org//    uint64_t readHeadNextPC(ThreadID tid);
2322292SN/A
2332292SN/A    /** Reads the sequence number of the oldest head instruction. */
2342329SN/A//    InstSeqNum readHeadSeqNum();
2352107SN/A
2362292SN/A    /** Reads the sequence number of the head instruction of a specific thread.
2372292SN/A     */
2386221Snate@binkert.org//    InstSeqNum readHeadSeqNum(ThreadID tid);
2392292SN/A
2402292SN/A    /** Reads the PC of the youngest tail instruction. */
2412329SN/A//    uint64_t readTailPC();
2422107SN/A
2432292SN/A    /** Reads the PC of the tail instruction of a specific thread. */
2446221Snate@binkert.org//    uint64_t readTailPC(ThreadID tid);
2452292SN/A
2462292SN/A    /** Reads the sequence number of the youngest tail instruction. */
2472329SN/A//    InstSeqNum readTailSeqNum();
2482107SN/A
2492292SN/A    /** Reads the sequence number of tail instruction of a specific thread. */
2506221Snate@binkert.org//    InstSeqNum readTailSeqNum(ThreadID tid);
2511060SN/A
2521060SN/A    /** Checks if the ROB is still in the process of squashing instructions.
2531060SN/A     *  @retval Whether or not the ROB is done squashing.
2541060SN/A     */
2556221Snate@binkert.org    bool isDoneSquashing(ThreadID tid) const
2562292SN/A    { return doneSquashing[tid]; }
2572292SN/A
2582292SN/A    /** Checks if the ROB is still in the process of squashing instructions for
2592292SN/A     *  any thread.
2602292SN/A     */
2612292SN/A    bool isDoneSquashing();
2621060SN/A
2631060SN/A    /** This is more of a debugging function than anything.  Use
2641060SN/A     *  numInstsInROB to get the instructions in the ROB unless you are
2651060SN/A     *  double checking that variable.
2661060SN/A     */
2671060SN/A    int countInsts();
2681060SN/A
2692292SN/A    /** This is more of a debugging function than anything.  Use
2702292SN/A     *  threadEntries to get the instructions in the ROB unless you are
2712292SN/A     *  double checking that variable.
2722292SN/A     */
2736221Snate@binkert.org    int countInsts(ThreadID tid);
2742292SN/A
2757897Shestness@cs.utexas.edu    /** Registers statistics. */
2767897Shestness@cs.utexas.edu    void regStats();
2777897Shestness@cs.utexas.edu
2781060SN/A  private:
2799444SAndreas.Sandberg@ARM.com    /** Reset the ROB state */
2809444SAndreas.Sandberg@ARM.com    void resetState();
2819444SAndreas.Sandberg@ARM.com
2821060SN/A    /** Pointer to the CPU. */
2832733Sktlim@umich.edu    O3CPU *cpu;
2841060SN/A
2852292SN/A    /** Active Threads in CPU */
2866221Snate@binkert.org    std::list<ThreadID> *activeThreads;
2872292SN/A
2881061SN/A    /** Number of instructions in the ROB. */
2891060SN/A    unsigned numEntries;
2901060SN/A
2912292SN/A    /** Entries Per Thread */
2922292SN/A    unsigned threadEntries[Impl::MaxThreads];
2932292SN/A
2942292SN/A    /** Max Insts a Thread Can Have in the ROB */
2952292SN/A    unsigned maxEntries[Impl::MaxThreads];
2962292SN/A
2972292SN/A    /** ROB List of Instructions */
2982292SN/A    std::list<DynInstPtr> instList[Impl::MaxThreads];
2992292SN/A
3001060SN/A    /** Number of instructions that can be squashed in a single cycle. */
3011060SN/A    unsigned squashWidth;
3021060SN/A
3032292SN/A  public:
3041061SN/A    /** Iterator pointing to the instruction which is the last instruction
3051061SN/A     *  in the ROB.  This may at times be invalid (ie when the ROB is empty),
3061061SN/A     *  however it should never be incorrect.
3071061SN/A     */
3082292SN/A    InstIt tail;
3091060SN/A
3102292SN/A    /** Iterator pointing to the instruction which is the first instruction in
3112292SN/A     *  in the ROB*/
3122292SN/A    InstIt head;
3132292SN/A
3142292SN/A  private:
3151061SN/A    /** Iterator used for walking through the list of instructions when
3161061SN/A     *  squashing.  Used so that there is persistent state between cycles;
3171061SN/A     *  when squashing, the instructions are marked as squashed but not
3181061SN/A     *  immediately removed, meaning the tail iterator remains the same before
3191061SN/A     *  and after a squash.
3201061SN/A     *  This will always be set to cpu->instList.end() if it is invalid.
3211061SN/A     */
3222292SN/A    InstIt squashIt[Impl::MaxThreads];
3231060SN/A
3242292SN/A  public:
3251061SN/A    /** Number of instructions in the ROB. */
3261060SN/A    int numInstsInROB;
3271060SN/A
3282348SN/A    /** Dummy instruction returned if there are no insts left. */
3292292SN/A    DynInstPtr dummyInst;
3302292SN/A
3312292SN/A  private:
3321060SN/A    /** The sequence number of the squashed instruction. */
3332877Sksewell@umich.edu    InstSeqNum squashedSeqNum[Impl::MaxThreads];
3341060SN/A
3351060SN/A    /** Is the ROB done squashing. */
3362292SN/A    bool doneSquashing[Impl::MaxThreads];
3372292SN/A
3382292SN/A    /** Number of active threads. */
3396221Snate@binkert.org    ThreadID numThreads;
3407897Shestness@cs.utexas.edu
3417897Shestness@cs.utexas.edu    // The number of rob_reads
3427897Shestness@cs.utexas.edu    Stats::Scalar robReads;
3437897Shestness@cs.utexas.edu    // The number of rob_writes
3447897Shestness@cs.utexas.edu    Stats::Scalar robWrites;
3451060SN/A};
3461060SN/A
3472292SN/A#endif //__CPU_O3_ROB_HH__
348