lsq.hh revision 6974
12292SN/A/* 22329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 32292SN/A * All rights reserved. 42292SN/A * 52292SN/A * Redistribution and use in source and binary forms, with or without 62292SN/A * modification, are permitted provided that the following conditions are 72292SN/A * met: redistributions of source code must retain the above copyright 82292SN/A * notice, this list of conditions and the following disclaimer; 92292SN/A * redistributions in binary form must reproduce the above copyright 102292SN/A * notice, this list of conditions and the following disclaimer in the 112292SN/A * documentation and/or other materials provided with the distribution; 122292SN/A * neither the name of the copyright holders nor the names of its 132292SN/A * contributors may be used to endorse or promote products derived from 142292SN/A * this software without specific prior written permission. 152292SN/A * 162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu * 282689Sktlim@umich.edu * Authors: Korey Sewell 292292SN/A */ 302292SN/A 312292SN/A#ifndef __CPU_O3_LSQ_HH__ 322292SN/A#define __CPU_O3_LSQ_HH__ 332292SN/A 342292SN/A#include <map> 352292SN/A#include <queue> 362292SN/A 372292SN/A#include "config/full_system.hh" 382292SN/A#include "cpu/inst_seq.hh" 392292SN/A#include "cpu/o3/lsq_unit.hh" 402669Sktlim@umich.edu#include "mem/port.hh" 412292SN/A#include "sim/sim_object.hh" 422292SN/A 435529Snate@binkert.orgclass DerivO3CPUParams; 445529Snate@binkert.org 452292SN/Atemplate <class Impl> 462292SN/Aclass LSQ { 472292SN/A public: 482733Sktlim@umich.edu typedef typename Impl::O3CPU O3CPU; 492292SN/A typedef typename Impl::DynInstPtr DynInstPtr; 502292SN/A typedef typename Impl::CPUPol::IEW IEW; 512292SN/A typedef typename Impl::CPUPol::LSQUnit LSQUnit; 522292SN/A 532348SN/A /** SMT policy. */ 542292SN/A enum LSQPolicy { 552292SN/A Dynamic, 562292SN/A Partitioned, 572292SN/A Threshold 582292SN/A }; 592292SN/A 602292SN/A /** Constructs an LSQ with the given parameters. */ 615529Snate@binkert.org LSQ(O3CPU *cpu_ptr, IEW *iew_ptr, DerivO3CPUParams *params); 622292SN/A 632292SN/A /** Returns the name of the LSQ. */ 642292SN/A std::string name() const; 652292SN/A 662727Sktlim@umich.edu /** Registers statistics of each LSQ unit. */ 672727Sktlim@umich.edu void regStats(); 682727Sktlim@umich.edu 692871Sktlim@umich.edu /** Returns dcache port. 702871Sktlim@umich.edu * @todo: Dcache port needs to be moved up to this level for SMT 712871Sktlim@umich.edu * to work. For now it just returns the port from one of the 722871Sktlim@umich.edu * threads. 732871Sktlim@umich.edu */ 742907Sktlim@umich.edu Port *getDcachePort() { return &dcachePort; } 752871Sktlim@umich.edu 762292SN/A /** Sets the pointer to the list of active threads. */ 776221Snate@binkert.org void setActiveThreads(std::list<ThreadID> *at_ptr); 782348SN/A /** Switches out the LSQ. */ 792307SN/A void switchOut(); 802348SN/A /** Takes over execution from another CPU's thread. */ 812307SN/A void takeOverFrom(); 822307SN/A 832292SN/A /** Number of entries needed for the given amount of threads.*/ 846221Snate@binkert.org int entryAmount(ThreadID num_threads); 856221Snate@binkert.org void removeEntries(ThreadID tid); 862292SN/A /** Reset the max entries for each thread. */ 872292SN/A void resetEntries(); 882292SN/A /** Resize the max entries for a thread. */ 896221Snate@binkert.org void resizeEntries(unsigned size, ThreadID tid); 902292SN/A 912292SN/A /** Ticks the LSQ. */ 922292SN/A void tick(); 932292SN/A /** Ticks a specific LSQ Unit. */ 946221Snate@binkert.org void tick(ThreadID tid) 952329SN/A { thread[tid].tick(); } 962292SN/A 972292SN/A /** Inserts a load into the LSQ. */ 982292SN/A void insertLoad(DynInstPtr &load_inst); 992292SN/A /** Inserts a store into the LSQ. */ 1002292SN/A void insertStore(DynInstPtr &store_inst); 1012292SN/A 1022292SN/A /** Executes a load. */ 1032292SN/A Fault executeLoad(DynInstPtr &inst); 1042292SN/A 1052292SN/A /** Executes a store. */ 1062292SN/A Fault executeStore(DynInstPtr &inst); 1072292SN/A 1082292SN/A /** 1092292SN/A * Commits loads up until the given sequence number for a specific thread. 1102292SN/A */ 1116221Snate@binkert.org void commitLoads(InstSeqNum &youngest_inst, ThreadID tid) 1122329SN/A { thread[tid].commitLoads(youngest_inst); } 1132329SN/A 1142292SN/A /** 1152292SN/A * Commits stores up until the given sequence number for a specific thread. 1162292SN/A */ 1176221Snate@binkert.org void commitStores(InstSeqNum &youngest_inst, ThreadID tid) 1182329SN/A { thread[tid].commitStores(youngest_inst); } 1192292SN/A 1202292SN/A /** 1212292SN/A * Attempts to write back stores until all cache ports are used or the 1222292SN/A * interface becomes blocked. 1232292SN/A */ 1242292SN/A void writebackStores(); 1252292SN/A /** Same as above, but only for one thread. */ 1266221Snate@binkert.org void writebackStores(ThreadID tid); 1272292SN/A 1282292SN/A /** 1292292SN/A * Squash instructions from a thread until the specified sequence number. 1302292SN/A */ 1316221Snate@binkert.org void squash(const InstSeqNum &squashed_num, ThreadID tid) 1322329SN/A { thread[tid].squash(squashed_num); } 1332292SN/A 1342292SN/A /** Returns whether or not there was a memory ordering violation. */ 1352292SN/A bool violation(); 1362292SN/A /** 1372292SN/A * Returns whether or not there was a memory ordering violation for a 1382292SN/A * specific thread. 1392292SN/A */ 1406221Snate@binkert.org bool violation(ThreadID tid) 1412329SN/A { return thread[tid].violation(); } 1422292SN/A 1432292SN/A /** Returns if a load is blocked due to the memory system for a specific 1442292SN/A * thread. 1452292SN/A */ 1466221Snate@binkert.org bool loadBlocked(ThreadID tid) 1472329SN/A { return thread[tid].loadBlocked(); } 1482292SN/A 1496221Snate@binkert.org bool isLoadBlockedHandled(ThreadID tid) 1502292SN/A { return thread[tid].isLoadBlockedHandled(); } 1512292SN/A 1526221Snate@binkert.org void setLoadBlockedHandled(ThreadID tid) 1532292SN/A { thread[tid].setLoadBlockedHandled(); } 1542292SN/A 1552292SN/A /** Gets the instruction that caused the memory ordering violation. */ 1566221Snate@binkert.org DynInstPtr getMemDepViolator(ThreadID tid) 1572329SN/A { return thread[tid].getMemDepViolator(); } 1582292SN/A 1592292SN/A /** Returns the head index of the load queue for a specific thread. */ 1606221Snate@binkert.org int getLoadHead(ThreadID tid) 1612329SN/A { return thread[tid].getLoadHead(); } 1622329SN/A 1632292SN/A /** Returns the sequence number of the head of the load queue. */ 1646221Snate@binkert.org InstSeqNum getLoadHeadSeqNum(ThreadID tid) 1652292SN/A { 1662292SN/A return thread[tid].getLoadHeadSeqNum(); 1672292SN/A } 1682292SN/A 1692292SN/A /** Returns the head index of the store queue. */ 1706221Snate@binkert.org int getStoreHead(ThreadID tid) 1712329SN/A { return thread[tid].getStoreHead(); } 1722329SN/A 1732292SN/A /** Returns the sequence number of the head of the store queue. */ 1746221Snate@binkert.org InstSeqNum getStoreHeadSeqNum(ThreadID tid) 1752292SN/A { 1762292SN/A return thread[tid].getStoreHeadSeqNum(); 1772292SN/A } 1782292SN/A 1792292SN/A /** Returns the number of instructions in all of the queues. */ 1802292SN/A int getCount(); 1812292SN/A /** Returns the number of instructions in the queues of one thread. */ 1826221Snate@binkert.org int getCount(ThreadID tid) 1832329SN/A { return thread[tid].getCount(); } 1842292SN/A 1852292SN/A /** Returns the total number of loads in the load queue. */ 1862292SN/A int numLoads(); 1872292SN/A /** Returns the total number of loads for a single thread. */ 1886221Snate@binkert.org int numLoads(ThreadID tid) 1892329SN/A { return thread[tid].numLoads(); } 1902292SN/A 1912292SN/A /** Returns the total number of stores in the store queue. */ 1922292SN/A int numStores(); 1932292SN/A /** Returns the total number of stores for a single thread. */ 1946221Snate@binkert.org int numStores(ThreadID tid) 1952329SN/A { return thread[tid].numStores(); } 1962292SN/A 1972292SN/A /** Returns the total number of loads that are ready. */ 1982292SN/A int numLoadsReady(); 1992292SN/A /** Returns the number of loads that are ready for a single thread. */ 2006221Snate@binkert.org int numLoadsReady(ThreadID tid) 2012329SN/A { return thread[tid].numLoadsReady(); } 2022292SN/A 2032292SN/A /** Returns the number of free entries. */ 2042292SN/A unsigned numFreeEntries(); 2052292SN/A /** Returns the number of free entries for a specific thread. */ 2066221Snate@binkert.org unsigned numFreeEntries(ThreadID tid); 2072292SN/A 2082292SN/A /** Returns if the LSQ is full (either LQ or SQ is full). */ 2092292SN/A bool isFull(); 2102292SN/A /** 2112292SN/A * Returns if the LSQ is full for a specific thread (either LQ or SQ is 2122292SN/A * full). 2132292SN/A */ 2146221Snate@binkert.org bool isFull(ThreadID tid); 2152292SN/A 2162292SN/A /** Returns if any of the LQs are full. */ 2172292SN/A bool lqFull(); 2182292SN/A /** Returns if the LQ of a given thread is full. */ 2196221Snate@binkert.org bool lqFull(ThreadID tid); 2202292SN/A 2212292SN/A /** Returns if any of the SQs are full. */ 2222292SN/A bool sqFull(); 2232292SN/A /** Returns if the SQ of a given thread is full. */ 2246221Snate@binkert.org bool sqFull(ThreadID tid); 2252292SN/A 2262292SN/A /** 2272292SN/A * Returns if the LSQ is stalled due to a memory operation that must be 2282292SN/A * replayed. 2292292SN/A */ 2302292SN/A bool isStalled(); 2312292SN/A /** 2322292SN/A * Returns if the LSQ of a specific thread is stalled due to a memory 2332292SN/A * operation that must be replayed. 2342292SN/A */ 2356221Snate@binkert.org bool isStalled(ThreadID tid); 2362292SN/A 2372292SN/A /** Returns whether or not there are any stores to write back to memory. */ 2382292SN/A bool hasStoresToWB(); 2392329SN/A 2402292SN/A /** Returns whether or not a specific thread has any stores to write back 2412292SN/A * to memory. 2422292SN/A */ 2436221Snate@binkert.org bool hasStoresToWB(ThreadID tid) 2442329SN/A { return thread[tid].hasStoresToWB(); } 2452329SN/A 2462292SN/A /** Returns the number of stores a specific thread has to write back. */ 2476221Snate@binkert.org int numStoresToWB(ThreadID tid) 2482329SN/A { return thread[tid].numStoresToWB(); } 2492292SN/A 2502292SN/A /** Returns if the LSQ will write back to memory this cycle. */ 2512292SN/A bool willWB(); 2522292SN/A /** Returns if the LSQ of a specific thread will write back to memory this 2532292SN/A * cycle. 2542292SN/A */ 2556221Snate@binkert.org bool willWB(ThreadID tid) 2562329SN/A { return thread[tid].willWB(); } 2572292SN/A 2582907Sktlim@umich.edu /** Returns if the cache is currently blocked. */ 2592907Sktlim@umich.edu bool cacheBlocked() 2606221Snate@binkert.org { return retryTid != InvalidThreadID; } 2612907Sktlim@umich.edu 2622907Sktlim@umich.edu /** Sets the retry thread id, indicating that one of the LSQUnits 2632907Sktlim@umich.edu * tried to access the cache but the cache was blocked. */ 2646221Snate@binkert.org void setRetryTid(ThreadID tid) 2652907Sktlim@umich.edu { retryTid = tid; } 2662907Sktlim@umich.edu 2672292SN/A /** Debugging function to print out all instructions. */ 2682292SN/A void dumpInsts(); 2692292SN/A /** Debugging function to print out instructions from a specific thread. */ 2706221Snate@binkert.org void dumpInsts(ThreadID tid) 2712329SN/A { thread[tid].dumpInsts(); } 2722292SN/A 2736974Stjones1@inf.ed.ac.uk /** Executes a read operation, using the load specified at the load 2746974Stjones1@inf.ed.ac.uk * index. 2756974Stjones1@inf.ed.ac.uk */ 2762292SN/A template <class T> 2776974Stjones1@inf.ed.ac.uk Fault read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 2786974Stjones1@inf.ed.ac.uk T &data, int load_idx); 2792292SN/A 2802292SN/A /** Executes a store operation, using the store specified at the store 2816974Stjones1@inf.ed.ac.uk * index. 2822292SN/A */ 2832292SN/A template <class T> 2846974Stjones1@inf.ed.ac.uk Fault write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 2856974Stjones1@inf.ed.ac.uk T &data, int store_idx); 2862292SN/A 2874329Sktlim@umich.edu /** The CPU pointer. */ 2884329Sktlim@umich.edu O3CPU *cpu; 2894329Sktlim@umich.edu 2904329Sktlim@umich.edu /** The IEW stage pointer. */ 2914329Sktlim@umich.edu IEW *iewStage; 2924329Sktlim@umich.edu 2932907Sktlim@umich.edu /** DcachePort class for this LSQ. Handles doing the 2942907Sktlim@umich.edu * communication with the cache/memory. 2952907Sktlim@umich.edu */ 2962907Sktlim@umich.edu class DcachePort : public Port 2972907Sktlim@umich.edu { 2982907Sktlim@umich.edu protected: 2992907Sktlim@umich.edu /** Pointer to LSQ. */ 3002907Sktlim@umich.edu LSQ *lsq; 3012907Sktlim@umich.edu 3022907Sktlim@umich.edu public: 3032907Sktlim@umich.edu /** Default constructor. */ 3045494Sstever@gmail.com DcachePort(LSQ *_lsq) 3055606Snate@binkert.org : Port(_lsq->name() + "-dport", _lsq->cpu), lsq(_lsq) 3062907Sktlim@umich.edu { } 3072907Sktlim@umich.edu 3083647Srdreslin@umich.edu bool snoopRangeSent; 3093647Srdreslin@umich.edu 3104192Sktlim@umich.edu virtual void setPeer(Port *port); 3114192Sktlim@umich.edu 3122907Sktlim@umich.edu protected: 3132907Sktlim@umich.edu /** Atomic version of receive. Panics. */ 3142907Sktlim@umich.edu virtual Tick recvAtomic(PacketPtr pkt); 3152907Sktlim@umich.edu 3162907Sktlim@umich.edu /** Functional version of receive. Panics. */ 3172907Sktlim@umich.edu virtual void recvFunctional(PacketPtr pkt); 3182907Sktlim@umich.edu 3192907Sktlim@umich.edu /** Receives status change. Other than range changing, panics. */ 3202907Sktlim@umich.edu virtual void recvStatusChange(Status status); 3212907Sktlim@umich.edu 3222907Sktlim@umich.edu /** Returns the address ranges of this device. */ 3232907Sktlim@umich.edu virtual void getDeviceAddressRanges(AddrRangeList &resp, 3244475Sstever@eecs.umich.edu bool &snoop) 3254475Sstever@eecs.umich.edu { resp.clear(); snoop = true; } 3262907Sktlim@umich.edu 3272907Sktlim@umich.edu /** Timing version of receive. Handles writing back and 3282907Sktlim@umich.edu * completing the load or store that has returned from 3292907Sktlim@umich.edu * memory. */ 3302907Sktlim@umich.edu virtual bool recvTiming(PacketPtr pkt); 3312907Sktlim@umich.edu 3322907Sktlim@umich.edu /** Handles doing a retry of the previous send. */ 3332907Sktlim@umich.edu virtual void recvRetry(); 3342907Sktlim@umich.edu }; 3352907Sktlim@umich.edu 3362907Sktlim@umich.edu /** D-cache port. */ 3372907Sktlim@umich.edu DcachePort dcachePort; 3382907Sktlim@umich.edu 3394192Sktlim@umich.edu#if FULL_SYSTEM 3404192Sktlim@umich.edu /** Tell the CPU to update the Phys and Virt ports. */ 3414192Sktlim@umich.edu void updateMemPorts() { cpu->updateMemPorts(); } 3424192Sktlim@umich.edu#endif 3434192Sktlim@umich.edu 3442907Sktlim@umich.edu protected: 3452292SN/A /** The LSQ policy for SMT mode. */ 3462292SN/A LSQPolicy lsqPolicy; 3472292SN/A 3482292SN/A /** The LSQ units for individual threads. */ 3492292SN/A LSQUnit thread[Impl::MaxThreads]; 3502292SN/A 3512292SN/A /** List of Active Threads in System. */ 3526221Snate@binkert.org std::list<ThreadID> *activeThreads; 3532292SN/A 3542292SN/A /** Total Size of LQ Entries. */ 3552292SN/A unsigned LQEntries; 3562292SN/A /** Total Size of SQ Entries. */ 3572292SN/A unsigned SQEntries; 3582292SN/A 3592292SN/A /** Max LQ Size - Used to Enforce Sharing Policies. */ 3602292SN/A unsigned maxLQEntries; 3612292SN/A 3622292SN/A /** Max SQ Size - Used to Enforce Sharing Policies. */ 3632292SN/A unsigned maxSQEntries; 3642292SN/A 3652292SN/A /** Number of Threads. */ 3666221Snate@binkert.org ThreadID numThreads; 3672907Sktlim@umich.edu 3682907Sktlim@umich.edu /** The thread id of the LSQ Unit that is currently waiting for a 3692907Sktlim@umich.edu * retry. */ 3706221Snate@binkert.org ThreadID retryTid; 3712292SN/A}; 3722292SN/A 3732292SN/Atemplate <class Impl> 3742292SN/Atemplate <class T> 3752292SN/AFault 3766974Stjones1@inf.ed.ac.ukLSQ<Impl>::read(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 3776974Stjones1@inf.ed.ac.uk T &data, int load_idx) 3782292SN/A{ 3796221Snate@binkert.org ThreadID tid = req->threadId(); 3802292SN/A 3816974Stjones1@inf.ed.ac.uk return thread[tid].read(req, sreqLow, sreqHigh, data, load_idx); 3822292SN/A} 3832292SN/A 3842292SN/Atemplate <class Impl> 3852292SN/Atemplate <class T> 3862292SN/AFault 3876974Stjones1@inf.ed.ac.ukLSQ<Impl>::write(RequestPtr req, RequestPtr sreqLow, RequestPtr sreqHigh, 3886974Stjones1@inf.ed.ac.uk T &data, int store_idx) 3892292SN/A{ 3906221Snate@binkert.org ThreadID tid = req->threadId(); 3912292SN/A 3926974Stjones1@inf.ed.ac.uk return thread[tid].write(req, sreqLow, sreqHigh, data, store_idx); 3932292SN/A} 3942292SN/A 3952292SN/A#endif // __CPU_O3_LSQ_HH__ 396